MCPcopy Create free account
hub / github.com/apache/cassandra-nodejs-driver / getDefaultGraphOptions

Function getDefaultGraphOptions

lib/datastax/graph/options.js:86–143  ·  view source on GitHub ↗

* Gets the default options with the custom payload for a given profile. * @param {ProfileManager} profileManager * @param baseOptions * @param {RetryPolicy|null} defaultRetryPolicy * @param {ExecutionProfile} profile * @returns {DseClientOptions} * @private

(profileManager, baseOptions, defaultRetryPolicy, profile)

Source from the content-addressed store, hash-verified

84 * @private
85 */
86function getDefaultGraphOptions(profileManager, baseOptions, defaultRetryPolicy, profile) {
87 return profileManager.getOrCreateGraphOptions(profile, function createDefaultOptions() {
88 const profileOptions = profile.graphOptions || utils.emptyObject;
89 const defaultProfile = profileManager.getDefault();
90 const options = {
91 customPayload: {
92 [payloadKeys.language]: utils.allocBufferFromString(profileOptions.language || baseOptions.language),
93 [payloadKeys.source]: utils.allocBufferFromString(profileOptions.source || baseOptions.source)
94 },
95 graphLanguage: profileOptions.language || baseOptions.language,
96 graphResults: profileOptions.results || baseOptions.results,
97 graphSource: profileOptions.source || baseOptions.source,
98 graphName: utils.ifUndefined(profileOptions.name, baseOptions.name)
99 };
100
101 if (profile !== defaultProfile) {
102 options.retry = profile.retry || baseOptions.retry;
103 } else {
104 // Based on an implementation detail of the execution profiles, the retry policy for the default profile is
105 // always loaded (required), but that doesn't mean that it was specified by the user.
106 // If it wasn't specified by the user, use the default retry policy for graph statements.
107 options.retry = defaultRetryPolicy || baseOptions.retry;
108 }
109
110 if (baseOptions.executeAs) {
111 options.customPayload[proxyExecuteKey] = utils.allocBufferFromString(baseOptions.executeAs);
112 }
113
114 if (options.graphName) {
115 options.customPayload[payloadKeys.name] = utils.allocBufferFromString(options.graphName);
116 }
117
118 const graphResults = utils.ifUndefined(profileOptions.results, baseOptions.graphResults);
119 if (graphResults !== undefined) {
120 options.customPayload[payloadKeys.results] = utils.allocBufferFromString(graphResults);
121 }
122
123 const readConsistency = utils.ifUndefined(profileOptions.readConsistency, baseOptions.readConsistency);
124 if (readConsistency !== undefined) {
125 options.customPayload[payloadKeys.readConsistency] =
126 utils.allocBufferFromString(getConsistencyName(readConsistency));
127 }
128
129 const writeConsistency = utils.ifUndefined(profileOptions.writeConsistency, baseOptions.writeConsistency);
130 if (writeConsistency !== undefined) {
131 options.customPayload[payloadKeys.writeConsistency] =
132 utils.allocBufferFromString(getConsistencyName(writeConsistency));
133 }
134
135 options.readTimeout = utils.ifUndefined3(profile.readTimeout, defaultProfile.readTimeout, baseOptions.readTimeout);
136 if (options.readTimeout > 0) {
137 // Write the graph read timeout payload
138 options.customPayload[payloadKeys.timeout] = longBuffer(options.readTimeout);
139 }
140
141 return options;
142 });
143}

Callers 1

constructorMethod · 0.85

Calls 4

getConsistencyNameFunction · 0.85
getDefaultMethod · 0.80
longBufferFunction · 0.70

Tested by

no test coverage detected