Skip to content

Commit 3761e2c

Browse files
committed
add support for graphql v14 and v15
1 parent 6a3b9f9 commit 3761e2c

File tree

10 files changed

+26
-28
lines changed

10 files changed

+26
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"typecheck": "tsc --noEmit --project tsconfig.build.json"
6060
},
6161
"peerDependencies": {
62-
"graphql": "^16.0.0"
62+
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
6363
},
6464
"dependencies": {
6565
"constant-case": "^3.0.4",

src/subgraph/state.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
Kind,
99
ObjectTypeDefinitionNode,
1010
ObjectTypeExtensionNode,
11-
OperationTypeNode,
11+
type OperationTypeNode,
1212
SchemaDefinitionNode,
1313
specifiedDirectives as specifiedDirectiveTypes,
1414
specifiedScalarTypes,
@@ -398,17 +398,17 @@ export function createSubgraphStateBuilder(
398398

399399
const expectedQueryTypeName = decideOnRootTypeName(
400400
schemaDef,
401-
OperationTypeNode.QUERY,
401+
'query' as OperationTypeNode,
402402
"Query",
403403
);
404404
const expectedMutationTypeName = decideOnRootTypeName(
405405
schemaDef,
406-
OperationTypeNode.MUTATION,
406+
'mutation' as OperationTypeNode,
407407
"Mutation",
408408
);
409409
const expectedSubscriptionTypeName = decideOnRootTypeName(
410410
schemaDef,
411-
OperationTypeNode.SUBSCRIPTION,
411+
'subscription' as OperationTypeNode,
412412
"Subscription",
413413
);
414414

src/subgraph/validation/rules/known-directives-rule.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
DocumentNode,
66
GraphQLError,
77
Kind,
8-
OperationTypeNode,
8+
type OperationTypeNode,
99
specifiedDirectives,
1010
} from "graphql";
1111

@@ -135,11 +135,11 @@ function getDirectiveLocationForOperation(
135135
operation: OperationTypeNode,
136136
): DirectiveLocation {
137137
switch (operation) {
138-
case OperationTypeNode.QUERY:
138+
case 'query' as OperationTypeNode.QUERY:
139139
return DirectiveLocation.QUERY;
140-
case OperationTypeNode.MUTATION:
140+
case 'mutation' as OperationTypeNode.MUTATION:
141141
return DirectiveLocation.MUTATION;
142-
case OperationTypeNode.SUBSCRIPTION:
142+
case 'subscription' as OperationTypeNode.SUBSCRIPTION:
143143
return DirectiveLocation.SUBSCRIPTION;
144144
}
145145
}

src/subgraph/validation/rules/query-root-type-inaccessible-rule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ASTVisitor, GraphQLError, OperationTypeNode } from "graphql";
1+
import { ASTVisitor, GraphQLError, type OperationTypeNode } from "graphql";
22
import type { SubgraphValidationContext } from "../validation-context.js";
33

44
export function QueryRootTypeInaccessibleRule(
@@ -10,7 +10,7 @@ export function QueryRootTypeInaccessibleRule(
1010
SchemaDefinition(node) {
1111
const nonQueryType = node.operationTypes?.find(
1212
(operationType) =>
13-
operationType.operation === OperationTypeNode.QUERY &&
13+
operationType.operation === 'query' &&
1414
operationType.type.name.value !== "Query",
1515
);
1616

@@ -21,7 +21,7 @@ export function QueryRootTypeInaccessibleRule(
2121
SchemaExtension(node) {
2222
const nonQueryType = node.operationTypes?.find(
2323
(operationType) =>
24-
operationType.operation === OperationTypeNode.QUERY &&
24+
operationType.operation === 'query' &&
2525
operationType.type.name.value !== "Query",
2626
);
2727

src/subgraph/validation/rules/root-type-used-rule.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
DefinitionNode,
44
GraphQLError,
55
isTypeDefinitionNode,
6-
OperationTypeNode,
6+
type OperationTypeNode,
77
SchemaDefinitionNode,
88
SchemaExtensionNode,
99
} from "graphql";
@@ -26,13 +26,13 @@ function findDefaultRootTypes(definitions: readonly DefinitionNode[]) {
2626
if (isTypeDefinitionNode(definition)) {
2727
if (definition.name.value === "Query") {
2828
foundRootTypes.query = "Query";
29-
found.add(OperationTypeNode.QUERY);
29+
found.add('query' as OperationTypeNode);
3030
} else if (definition.name.value === "Mutation") {
3131
foundRootTypes.mutation = "Mutation";
32-
found.add(OperationTypeNode.MUTATION);
32+
found.add('mutation' as OperationTypeNode);
3333
} else if (definition.name.value === "Subscription") {
3434
foundRootTypes.subscription = "Subscription";
35-
found.add(OperationTypeNode.SUBSCRIPTION);
35+
found.add('subscription' as OperationTypeNode);
3636
}
3737
}
3838
}

src/subgraph/validation/validate-subgraph.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
Kind,
99
ObjectTypeDefinitionNode,
1010
ObjectTypeExtensionNode,
11-
OperationTypeNode,
1211
parse,
1312
SchemaDefinitionNode,
1413
SchemaExtensionNode,
@@ -541,13 +540,13 @@ function cleanSubgraphTypeDefsFromSubgraphSpec(typeDefs: DocumentNode) {
541540
(node.kind === Kind.SCHEMA_DEFINITION ||
542541
node.kind === Kind.SCHEMA_EXTENSION) &&
543542
node.operationTypes?.some(
544-
(op) => op.operation === OperationTypeNode.QUERY,
543+
(op) => op.operation === 'query',
545544
),
546545
) as SchemaDefinitionNode | SchemaExtensionNode | undefined;
547546

548547
const queryTypeName =
549548
schemaDef?.operationTypes?.find(
550-
(op) => op.operation === OperationTypeNode.QUERY,
549+
(op) => op.operation === 'query',
551550
)?.type.name.value ?? "Query";
552551

553552
(typeDefs.definitions as unknown as DefinitionNode[]) =

src/supergraph/composition/ast.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
NamedTypeNode,
2222
ObjectTypeDefinitionNode,
2323
OperationTypeDefinitionNode,
24-
OperationTypeNode,
24+
type OperationTypeNode,
2525
parseConstValue,
2626
parseType,
2727
ScalarTypeDefinitionNode,
@@ -77,21 +77,21 @@ export function createSchemaNode(schema: {
7777
schema.query
7878
? {
7979
kind: Kind.OPERATION_TYPE_DEFINITION,
80-
operation: OperationTypeNode.QUERY,
80+
operation: 'query' as OperationTypeNode,
8181
type: createNamedTypeNode(schema.query),
8282
}
8383
: [],
8484
schema.mutation
8585
? {
8686
kind: Kind.OPERATION_TYPE_DEFINITION,
87-
operation: OperationTypeNode.MUTATION,
87+
operation: 'mutation' as OperationTypeNode,
8888
type: createNamedTypeNode(schema.mutation),
8989
}
9090
: [],
9191
schema.subscription
9292
? {
9393
kind: Kind.OPERATION_TYPE_DEFINITION,
94-
operation: OperationTypeNode.SUBSCRIPTION,
94+
operation: 'subscription' as OperationTypeNode,
9595
type: createNamedTypeNode(schema.subscription),
9696
}
9797
: [],

src/supergraph/validation/rules/satisfiablity-rule.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
GraphQLError,
33
Kind,
44
ListValueNode,
5-
OperationTypeNode,
65
print,
76
specifiedScalarTypes,
87
ValueNode,

src/supergraph/validation/rules/satisfiablity/supergraph.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OperationTypeNode } from "graphql";
1+
import type { OperationTypeNode } from "graphql";
22
import { Logger, LoggerContext } from "../../../../utils/logger.js";
33
import type { SupergraphState } from "../../../state.js";
44
import { MERGEDGRAPH_ID, SUPERGRAPH_ID } from "./constants.js";

src/supergraph/validation/rules/satisfiablity/walker.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { OperationTypeNode } from "graphql";
1+
import type { OperationTypeNode } from "graphql";
22
import type { Logger } from "../../../../utils/logger.js";
33
import { isAbstractEdge, isFieldEdge, type Edge } from "./edge.js";
44
import { LazyErrors, SatisfiabilityError } from "./errors.js";
@@ -119,9 +119,9 @@ export class Walker {
119119
}
120120

121121
const rootNode = this.supergraph.nodeOf(
122-
operationType === OperationTypeNode.QUERY
122+
operationType === 'query'
123123
? "Query"
124-
: operationType === OperationTypeNode.MUTATION
124+
: operationType === 'mutation'
125125
? "Mutation"
126126
: "Subscription",
127127
false,

0 commit comments

Comments
 (0)