Skip to content

Commit 2a52b3f

Browse files
yaacovCRlogaretm
authored andcommitted
move function helpers to follow their use
1 parent 24220f3 commit 2a52b3f

1 file changed

Lines changed: 44 additions & 44 deletions

File tree

src/execution/execute.ts

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ import { getArgumentValues, getVariableValues } from './values.js';
5757
const UNEXPECTED_EXPERIMENTAL_DIRECTIVES =
5858
'The provided schema unexpectedly contains experimental directives (@defer or @stream). These directives may only be utilized if experimental execution features are explicitly enabled.';
5959

60+
/**
61+
* Implements the "Executing requests" section of the GraphQL specification.
62+
*
63+
* Returns either a synchronous ExecutionResult (if all encountered resolvers
64+
* are synchronous), or a Promise of an ExecutionResult that will eventually be
65+
* resolved and never rejected.
66+
*
67+
* If the arguments to this function do not result in a legal execution context,
68+
* a GraphQLError will be thrown immediately explaining the invalid input.
69+
*
70+
* This function does not support incremental delivery (`@defer` and `@stream`).
71+
* If an operation which would defer or stream data is executed with this
72+
* function, it will throw or return a rejected promise.
73+
* Use `experimentalExecuteIncrementally` if you want to support incremental
74+
* delivery.
75+
*/
76+
export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
77+
if (!executeChannel?.hasSubscribers) {
78+
return executeImpl(args);
79+
}
80+
return traceMixed(executeChannel, buildExecuteCtxFromArgs(args), () =>
81+
executeImpl(args),
82+
);
83+
}
84+
6085
/**
6186
* Build a graphql:execute channel context from raw ExecutionArgs. Defers
6287
* resolution of the operation AST to a lazy getter so the cost of walking
@@ -83,50 +108,6 @@ function buildExecuteCtxFromArgs(args: ExecutionArgs): object {
83108
};
84109
}
85110

86-
/**
87-
* Build a graphql:execute channel context from ValidatedExecutionArgs.
88-
* Used by executeSubscriptionEvent, where the operation has already been
89-
* resolved during argument validation. The original document is not
90-
* available at this point, only the resolved operation; subscribers that
91-
* need the document should read it from the graphql:subscribe context.
92-
*/
93-
function buildExecuteCtxFromValidatedArgs(
94-
args: ValidatedExecutionArgs,
95-
): object {
96-
return {
97-
operation: args.operation,
98-
schema: args.schema,
99-
variableValues: args.variableValues,
100-
operationName: args.operation.name?.value,
101-
operationType: args.operation.operation,
102-
};
103-
}
104-
105-
/**
106-
* Implements the "Executing requests" section of the GraphQL specification.
107-
*
108-
* Returns either a synchronous ExecutionResult (if all encountered resolvers
109-
* are synchronous), or a Promise of an ExecutionResult that will eventually be
110-
* resolved and never rejected.
111-
*
112-
* If the arguments to this function do not result in a legal execution context,
113-
* a GraphQLError will be thrown immediately explaining the invalid input.
114-
*
115-
* This function does not support incremental delivery (`@defer` and `@stream`).
116-
* If an operation which would defer or stream data is executed with this
117-
* function, it will throw or return a rejected promise.
118-
* Use `experimentalExecuteIncrementally` if you want to support incremental
119-
* delivery.
120-
*/
121-
export function execute(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
122-
if (!executeChannel?.hasSubscribers) {
123-
return executeImpl(args);
124-
}
125-
return traceMixed(executeChannel, buildExecuteCtxFromArgs(args), () =>
126-
executeImpl(args),
127-
);
128-
}
129-
130111
function executeImpl(args: ExecutionArgs): PromiseOrValue<ExecutionResult> {
131112
if (args.schema.getDirective('defer') || args.schema.getDirective('stream')) {
132113
throw new Error(UNEXPECTED_EXPERIMENTAL_DIRECTIVES);
@@ -778,6 +759,25 @@ function assertEventStream(result: unknown): AsyncIterable<unknown> {
778759
return result;
779760
}
780761

762+
/**
763+
* Build a graphql:execute channel context from ValidatedExecutionArgs.
764+
* Used by executeSubscriptionEvent, where the operation has already been
765+
* resolved during argument validation. The original document is not
766+
* available at this point, only the resolved operation; subscribers that
767+
* need the document should read it from the graphql:subscribe context.
768+
*/
769+
function buildExecuteCtxFromValidatedArgs(
770+
args: ValidatedExecutionArgs,
771+
): object {
772+
return {
773+
operation: args.operation,
774+
schema: args.schema,
775+
variableValues: args.variableValues,
776+
operationName: args.operation.name?.value,
777+
operationType: args.operation.operation,
778+
};
779+
}
780+
781781
/**
782782
* TODO: consider no longer exporting this function
783783
* @internal

0 commit comments

Comments
 (0)