Skip to content

Commit e714acb

Browse files
committed
deprecates (internal) buildResolveInfo in favor of new (internal) ResolveInfo class
(ResolveInfo upgraded in v17 to be lazy and include abortSignal) Change appreciable only to those using deep imports.
1 parent 4c057eb commit e714acb

File tree

3 files changed

+64
-3
lines changed

3 files changed

+64
-3
lines changed

src/execution/ResolveInfo.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import type { ObjMap } from '../jsutils/ObjMap';
2+
import type { Path } from '../jsutils/Path';
3+
4+
import type {
5+
FieldNode,
6+
FragmentDefinitionNode,
7+
OperationDefinitionNode,
8+
} from '../language/ast';
9+
10+
import type {
11+
GraphQLField,
12+
GraphQLObjectType,
13+
GraphQLOutputType,
14+
GraphQLResolveInfo,
15+
} from '../type/definition';
16+
import type { GraphQLSchema } from '../type/schema';
17+
18+
interface ExecutionDetails {
19+
schema: GraphQLSchema;
20+
fragments: ObjMap<FragmentDefinitionNode>;
21+
rootValue: unknown;
22+
operation: OperationDefinitionNode;
23+
variableValues: { [key: string]: unknown };
24+
}
25+
26+
/** @internal */
27+
export class ResolveInfo implements GraphQLResolveInfo {
28+
readonly fieldName: string;
29+
readonly fieldNodes: ReadonlyArray<FieldNode>;
30+
readonly returnType: GraphQLOutputType;
31+
readonly parentType: GraphQLObjectType;
32+
readonly path: Path;
33+
readonly schema: GraphQLSchema;
34+
readonly fragments: ObjMap<FragmentDefinitionNode>;
35+
readonly rootValue: unknown;
36+
readonly operation: OperationDefinitionNode;
37+
readonly variableValues: { [variable: string]: unknown };
38+
39+
constructor(
40+
executionDetails: ExecutionDetails,
41+
fieldDef: GraphQLField<unknown, unknown>,
42+
fieldNodes: ReadonlyArray<FieldNode>,
43+
parentType: GraphQLObjectType,
44+
path: Path,
45+
) {
46+
this.fieldName = fieldNodes[0].name.value;
47+
this.fieldNodes = fieldNodes;
48+
this.returnType = fieldDef.type;
49+
this.parentType = parentType;
50+
this.path = path;
51+
const { schema, fragments, rootValue, operation, variableValues } =
52+
executionDetails;
53+
this.schema = schema;
54+
this.fragments = fragments;
55+
this.rootValue = rootValue;
56+
this.operation = operation;
57+
this.variableValues = variableValues;
58+
}
59+
}

src/execution/execute.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
collectFields,
5757
collectSubfields as _collectSubfields,
5858
} from './collectFields';
59+
import { ResolveInfo } from './ResolveInfo';
5960
import { getArgumentValues, getVariableValues } from './values';
6061

6162
/**
@@ -551,7 +552,7 @@ function executeField(
551552
const returnType = fieldDef.type;
552553
const resolveFn = fieldDef.resolve ?? exeContext.fieldResolver;
553554

554-
const info = buildResolveInfo(
555+
const info = new ResolveInfo(
555556
exeContext,
556557
fieldDef,
557558
fieldNodes,
@@ -609,6 +610,7 @@ function executeField(
609610
}
610611

611612
/**
613+
* @deprecated will be removed in v17, use ResolveInfo class instead
612614
* @internal
613615
*/
614616
export function buildResolveInfo(

src/execution/subscribe.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import {
2222
// eslint-disable-next-line import/no-deprecated
2323
assertValidExecutionArguments,
2424
buildExecutionContext,
25-
buildResolveInfo,
2625
execute,
2726
getFieldDef,
2827
} from './execute';
2928
import { mapAsyncIterator } from './mapAsyncIterator';
29+
import { ResolveInfo } from './ResolveInfo';
3030
import { getArgumentValues } from './values';
3131

3232
/**
@@ -228,7 +228,7 @@ async function executeSubscription(
228228
}
229229

230230
const path = addPath(undefined, responseName, rootType.name);
231-
const info = buildResolveInfo(
231+
const info = new ResolveInfo(
232232
exeContext,
233233
fieldDef,
234234
fieldNodes,

0 commit comments

Comments
 (0)