Skip to content

Commit

Permalink
expose all of the execution environment to resolvers
Browse files Browse the repository at this point in the history
presumably we should do this
  • Loading branch information
yaacovCR committed Jan 15, 2023
1 parent e90cdbc commit d998e79
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/execution/__tests__/executor-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ describe('Execute: Handles basic execution tasks', () => {

expect(resolvedInfo).to.have.all.keys(
'fieldName',
'fieldNodes',
'fieldGroup',
'deferDepth',
'returnType',
'parentType',
'path',
Expand All @@ -238,9 +239,10 @@ describe('Execute: Handles basic execution tasks', () => {
operation,
});

const field = operation.selectionSet.selections[0];
const fieldNode = operation.selectionSet.selections[0];
expect(resolvedInfo).to.deep.include({
fieldNodes: [field],
fieldGroup: [{ fieldNode, depth: 0, deferDepth: undefined }],
deferDepth: undefined,
variableValues: { var: 'abc' },
});

Expand Down
5 changes: 4 additions & 1 deletion src/execution/execute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ function executeField(
fieldGroup,
parentType,
path,
asyncPayloadRecord,
);

// Get the resolve function, regardless of if its result is normal or abrupt (error).
Expand Down Expand Up @@ -865,12 +866,14 @@ export function buildResolveInfo(
fieldGroup: FieldGroup,
parentType: GraphQLObjectType,
path: Path,
asyncPayloadRecord?: AsyncPayloadRecord | undefined,
): GraphQLResolveInfo {
// The resolve function's optional fourth argument is a collection of
// information about the current execution state.
return {
fieldName: fieldDef.name,
fieldNodes: toNodes(fieldGroup),
fieldGroup,
deferDepth: asyncPayloadRecord?.deferDepth,
returnType: fieldDef.type,
parentType,
path,
Expand Down
7 changes: 6 additions & 1 deletion src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,12 @@ export type GraphQLFieldResolver<

export interface GraphQLResolveInfo {
readonly fieldName: string;
readonly fieldNodes: ReadonlyArray<FieldNode>;
readonly fieldGroup: ReadonlyArray<{
fieldNode: FieldNode;
depth: number;
deferDepth: number | undefined;
}>;
readonly deferDepth: number | undefined;
readonly returnType: GraphQLOutputType;
readonly parentType: GraphQLObjectType;
readonly path: Path;
Expand Down

0 comments on commit d998e79

Please sign in to comment.