-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly name the root field execution functions #3294
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,7 +166,7 @@ export interface ExecutionArgs { | |
* a GraphQLError will be thrown immediately explaining the invalid input. | ||
*/ | ||
export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> { | ||
const { schema, document, variableValues, rootValue } = args; | ||
const { schema, document, variableValues } = args; | ||
|
||
// If arguments are missing or incorrect, throw an error. | ||
assertValidExecutionArguments(schema, document, variableValues); | ||
|
@@ -180,14 +180,16 @@ export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> { | |
return { errors: exeContext }; | ||
} | ||
|
||
// Return a Promise that will eventually resolve to the data described by | ||
// The "Response" section of the GraphQL specification. | ||
// | ||
// Return data or a Promise that will eventually resolve to the data described | ||
// by the "Response" section of the GraphQL specification. | ||
|
||
// If errors are encountered while executing a GraphQL field, only that | ||
// field and its descendants will be omitted, and sibling fields will still | ||
// be executed. An execution which encounters errors will still result in a | ||
// resolved Promise. | ||
const data = executeOperation(exeContext, exeContext.operation, rootValue); | ||
const data = executeQueryOrMutationRootFields(exeContext); | ||
|
||
// Return the response. | ||
return buildResponse(exeContext, data); | ||
} | ||
|
||
|
@@ -329,14 +331,13 @@ export function buildExecutionContext( | |
} | ||
|
||
/** | ||
* Implements the "Executing operations" section of the spec. | ||
* Executes the root fields specified by query or mutation operation. | ||
*/ | ||
function executeOperation( | ||
function executeQueryOrMutationRootFields( | ||
exeContext: ExecutionContext, | ||
operation: OperationDefinitionNode, | ||
rootValue: unknown, | ||
): PromiseOrValue<ObjMap<unknown> | null> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Context is a necessary evil, for stuff used deeply in the call chain. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Especially, since a plan is to separate operation execution context later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Debatable, but Ok |
||
const type = getOperationRootType(exeContext.schema, operation); | ||
const { schema, operation, rootValue } = exeContext; | ||
const type = getOperationRootType(schema, operation); | ||
const fields = collectFields( | ||
exeContext.schema, | ||
exeContext.fragments, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,7 +169,7 @@ export async function createSourceEventStream( | |
} | ||
|
||
try { | ||
const eventStream = await executeSubscription(exeContext); | ||
const eventStream = await executeSubscriptionRootField(exeContext); | ||
|
||
// Assert field returned an event stream, otherwise yield an error. | ||
if (!isAsyncIterable(eventStream)) { | ||
|
@@ -190,7 +190,7 @@ export async function createSourceEventStream( | |
} | ||
} | ||
|
||
async function executeSubscription( | ||
async function executeSubscriptionRootField( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep, naming for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment above, disagree strongly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is nothing premature about correcting an error, just because you will further improve later, this is internal code refactoring, non breaking changes, you can rererename as often as you want |
||
exeContext: ExecutionContext, | ||
): Promise<unknown> { | ||
const { schema, fragments, operation, variableValues, rootValue } = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed previously want to put
subscription
here.So let's keep the name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name as now is incorrect, for internal refactoring, better to just improve instead of adding todo to get optimal solution. There is a saying, “perfect is the enemy of good.”