Skip to content

Commit ae5b163

Browse files
committed
Execute: use consistent name for execution context (#1318)
commit b58697d8e91de91265cbebe48906e0c29b48b28b Author: Lee Byron <[email protected]> Date: Mon Apr 23 16:50:02 2018 -0400 Also unify contextValue commit 30d062cedd687c1f662d9e87e08d35d61c2a50ce Merge: 1d07ebf 4db01f3 Author: Lee Byron <[email protected]> Date: Mon Apr 23 16:47:31 2018 -0400 Merge branch 'exeContextName' of https://github.com/APIs-guru/graphql-js into APIs-guru-exeContextName commit 4db01f3 Author: Lee Byron <[email protected]> Date: Mon Apr 23 13:43:20 2018 -0700 Addendum commit 571f2bc Author: Lee Byron <[email protected]> Date: Mon Apr 23 13:42:41 2018 -0700 Address review commit 0195b30 Author: Ivan Goncharov <[email protected]> Date: Sat Apr 21 17:30:35 2018 +0300 Execute: use consistent name for execution context
1 parent 1d07ebf commit ae5b163

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/execution/execute.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ function executeImpl(
193193
// If arguments are missing or incorrect, throw an error.
194194
assertValidExecutionArguments(schema, document, variableValues);
195195

196-
// If a valid context cannot be created due to incorrect arguments,
196+
// If a valid execution context cannot be created due to incorrect arguments,
197197
// a "Response" with only errors is returned.
198-
const context = buildExecutionContext(
198+
const exeContext = buildExecutionContext(
199199
schema,
200200
document,
201201
rootValue,
@@ -206,8 +206,8 @@ function executeImpl(
206206
);
207207

208208
// Return early errors if execution context failed.
209-
if (Array.isArray(context)) {
210-
return { errors: context };
209+
if (Array.isArray(exeContext)) {
210+
return { errors: exeContext };
211211
}
212212

213213
// Return a Promise that will eventually resolve to the data described by
@@ -217,24 +217,24 @@ function executeImpl(
217217
// field and its descendants will be omitted, and sibling fields will still
218218
// be executed. An execution which encounters errors will still result in a
219219
// resolved Promise.
220-
const data = executeOperation(context, context.operation, rootValue);
221-
return buildResponse(context, data);
220+
const data = executeOperation(exeContext, exeContext.operation, rootValue);
221+
return buildResponse(exeContext, data);
222222
}
223223

224224
/**
225225
* Given a completed execution context and data, build the { errors, data }
226226
* response defined by the "Response" section of the GraphQL specification.
227227
*/
228228
function buildResponse(
229-
context: ExecutionContext,
229+
exeContext: ExecutionContext,
230230
data: MaybePromise<ObjMap<mixed> | null>,
231231
) {
232232
if (isPromise(data)) {
233-
return data.then(resolved => buildResponse(context, resolved));
233+
return data.then(resolved => buildResponse(exeContext, resolved));
234234
}
235-
return context.errors.length === 0
235+
return exeContext.errors.length === 0
236236
? { data }
237-
: { errors: context.errors, data };
237+
: { errors: exeContext.errors, data };
238238
}
239239

240240
/**
@@ -767,9 +767,9 @@ export function resolveFieldValueOrError<TSource>(
767767
// The resolve function's optional third argument is a context value that
768768
// is provided to every resolve function within an execution. It is commonly
769769
// used to represent an authenticated user, or request-specific caches.
770-
const context = exeContext.contextValue;
770+
const contextValue = exeContext.contextValue;
771771

772-
const result = resolveFn(source, args, context, info);
772+
const result = resolveFn(source, args, contextValue, info);
773773
return isPromise(result) ? result.then(undefined, asErrorInstance) : result;
774774
} catch (error) {
775775
return asErrorInstance(error);
@@ -1174,7 +1174,7 @@ function collectAndExecuteSubfields(
11741174
}
11751175

11761176
/**
1177-
* A memoized collection of relevant subfields in the context of the return
1177+
* A memoized collection of relevant subfields with regard to the return
11781178
* type. Memoizing ensures the subfields are not repeatedly calculated, which
11791179
* saves overhead when resolving lists of values.
11801180
*/
@@ -1213,7 +1213,7 @@ function _collectSubfields(
12131213
*/
12141214
function defaultResolveTypeFn(
12151215
value: mixed,
1216-
context: mixed,
1216+
contextValue: mixed,
12171217
info: GraphQLResolveInfo,
12181218
abstractType: GraphQLAbstractType,
12191219
): MaybePromise<?GraphQLObjectType | string> {
@@ -1234,7 +1234,7 @@ function defaultResolveTypeFn(
12341234
const type = possibleTypes[i];
12351235

12361236
if (type.isTypeOf) {
1237-
const isTypeOfResult = type.isTypeOf(value, context, info);
1237+
const isTypeOfResult = type.isTypeOf(value, contextValue, info);
12381238

12391239
if (isPromise(isTypeOfResult)) {
12401240
promisedIsTypeOfResults[i] = isTypeOfResult;
@@ -1259,19 +1259,19 @@ function defaultResolveTypeFn(
12591259
* If a resolve function is not given, then a default resolve behavior is used
12601260
* which takes the property of the source object of the same name as the field
12611261
* and returns it as the result, or if it's a function, returns the result
1262-
* of calling that function while passing along args and context.
1262+
* of calling that function while passing along args and context value.
12631263
*/
12641264
export const defaultFieldResolver: GraphQLFieldResolver<any, *> = function(
12651265
source,
12661266
args,
1267-
context,
1267+
contextValue,
12681268
info,
12691269
) {
12701270
// ensure source is a value for which property access is acceptable.
12711271
if (typeof source === 'object' || typeof source === 'function') {
12721272
const property = source[info.fieldName];
12731273
if (typeof property === 'function') {
1274-
return source[info.fieldName](args, context, info);
1274+
return source[info.fieldName](args, contextValue, info);
12751275
}
12761276
return property;
12771277
}

0 commit comments

Comments
 (0)