From 149afddba856211e64c9263b9c6770f7838691f8 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Tue, 19 Oct 2021 10:56:59 -0400 Subject: [PATCH] fix: getting ready for GraphQL v16 (#3716) * Test GraphQL v16 * Fix TS * Oops dont push package.json * Fix older versions * More * Move on * Move on again * Fix TS for v14' * Try * Next attempt * What? * Ah * Clear locations completely * ... * Remove nodes as well * Come on * Ok? * Now? * Anothjer * Remove nodes * Another try * Add changeset * oops * This is minor actually --- .changeset/funny-clocks-report.md | 14 +++ .github/workflows/tests.yml | 6 +- .../tests/basic.example.test.ts | 6 +- .../tests/withTransforms.test.ts | 4 +- packages/batch-execute/src/mergeRequests.ts | 4 +- .../batch-execute/tests/batchExecute.test.ts | 35 +++--- packages/delegate/src/createRequest.ts | 9 +- .../delegate/src/finalizeGatewayRequest.ts | 34 +++--- .../delegate/src/prepareGatewayDocument.ts | 10 +- packages/delegate/tests/createRequest.test.ts | 8 +- .../delegate/tests/delegateToSchema.test.ts | 8 +- packages/delegate/tests/errors.test.ts | 4 +- .../tests/finalizeGatewayRequest.test.ts | 10 +- packages/load/src/filter-document-kind.ts | 5 +- packages/merge/src/typedefs-mergers/enum.ts | 4 +- .../merge/src/typedefs-mergers/input-type.ts | 4 +- .../merge/src/typedefs-mergers/interface.ts | 4 +- .../src/typedefs-mergers/merge-typedefs.ts | 4 +- packages/merge/src/typedefs-mergers/scalar.ts | 4 +- packages/merge/src/typedefs-mergers/type.ts | 4 +- packages/merge/src/typedefs-mergers/union.ts | 8 +- .../extract-extensions-from-schema.spec.ts | 2 +- packages/merge/tests/merge-typedefs.spec.ts | 12 +- packages/schema/tests/schemaGenerator.test.ts | 2 +- .../stitch/src/createMergedTypeResolver.ts | 6 +- packages/stitch/src/typeFromAST.ts | 15 ++- .../tests/alternateStitchSchemas.test.ts | 103 ++++------------ packages/stitch/tests/dataloader.test.ts | 4 +- packages/stitch/tests/example.test.ts | 10 +- packages/stitch/tests/selectionSets.test.ts | 6 +- packages/stitch/tests/stitchSchemas.test.ts | 115 ++++++------------ packages/stitch/tests/typeMerging.test.ts | 4 +- .../src/stitchingDirectives.ts | 8 +- .../src/stitchingDirectivesTransformer.ts | 2 +- .../utils/src/build-operation-for-field.ts | 2 +- .../utils/src/print-schema-with-directives.ts | 2 +- packages/utils/src/rootTypes.ts | 6 +- packages/utils/src/types.ts | 5 +- .../build-operation-node-for-field.spec.ts | 32 ++--- packages/utils/tests/mapSchema.test.ts | 2 +- .../print-schema-with-directives.spec.ts | 8 +- packages/utils/tests/visitResult.test.ts | 22 ++-- packages/wrap/src/introspect.ts | 3 +- packages/wrap/src/transforms/HoistField.ts | 3 +- packages/wrap/src/transforms/WrapFields.ts | 3 +- packages/wrap/tests/requests.test.ts | 4 +- .../wrap/tests/transformWrapQuery.test.ts | 6 +- packages/wrap/tests/transforms.test.ts | 25 ++-- 48 files changed, 265 insertions(+), 336 deletions(-) create mode 100644 .changeset/funny-clocks-report.md diff --git a/.changeset/funny-clocks-report.md b/.changeset/funny-clocks-report.md new file mode 100644 index 00000000000..db9afdf4f63 --- /dev/null +++ b/.changeset/funny-clocks-report.md @@ -0,0 +1,14 @@ +--- +'@graphql-tools/batch-delegate': minor +'@graphql-tools/batch-execute': minor +'@graphql-tools/delegate': minor +'@graphql-tools/load': minor +'@graphql-tools/merge': minor +'@graphql-tools/schema': minor +'@graphql-tools/stitch': minor +'@graphql-tools/stitching-directives': minor +'@graphql-tools/utils': minor +'@graphql-tools/wrap': minor +--- + +fix: getting ready for GraphQL v16 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8133dcd8f54..ccf20b8c9b6 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -38,7 +38,7 @@ jobs: graphql_version: - 14 - 15 - # - 16.0.0-rc.1 + - 16.0.0-rc.5 steps: - name: Checkout Master uses: actions/checkout@v2 @@ -57,7 +57,7 @@ jobs: run: node ./scripts/match-graphql.js ${{matrix.graphql_version}} - name: Install Dependencies using Yarn run: yarn install --ignore-engines && git checkout yarn.lock - - name: Build + - name: Type Check run: yarn ts:check test: name: Unit Test on Node ${{matrix.node_version}} (${{matrix.os}}) and GraphQL v${{matrix.graphql_version}} @@ -69,7 +69,7 @@ jobs: graphql_version: - 14 - 15 - # - 16.0.0-rc.1 + - 16.0.0-rc.5 include: - node_version: 14 os: windows-latest diff --git a/packages/batch-delegate/tests/basic.example.test.ts b/packages/batch-delegate/tests/basic.example.test.ts index e64acd2c66b..1d88bc95181 100644 --- a/packages/batch-delegate/tests/basic.example.test.ts +++ b/packages/batch-delegate/tests/basic.example.test.ts @@ -1,4 +1,4 @@ -import { execute, parse } from 'graphql'; +import { execute, OperationTypeNode, parse } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { batchDelegateToSchema } from '@graphql-tools/batch-delegate'; @@ -62,7 +62,7 @@ describe('batch delegation within basic stitching example', () => { resolve(chirp, _args, context, info) { return batchDelegateToSchema({ schema: authorSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'usersByIds', key: chirp.chirpedAtUserId, argsFromKeys: (ids) => ({ ids }), @@ -155,7 +155,7 @@ describe('batch delegation within basic stitching example', () => { resolve(user, _args, context, info) { return batchDelegateToSchema({ schema: postsSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'posts', key: user.postIds, context, diff --git a/packages/batch-delegate/tests/withTransforms.test.ts b/packages/batch-delegate/tests/withTransforms.test.ts index dfea2463c06..f5a7f7f01e5 100644 --- a/packages/batch-delegate/tests/withTransforms.test.ts +++ b/packages/batch-delegate/tests/withTransforms.test.ts @@ -1,4 +1,4 @@ -import { execute, GraphQLList, GraphQLObjectType, Kind, parse } from 'graphql'; +import { execute, GraphQLList, GraphQLObjectType, Kind, OperationTypeNode, parse } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { batchDelegateToSchema } from '@graphql-tools/batch-delegate'; @@ -93,7 +93,7 @@ describe('works with complex transforms', () => { selectionSet: `{ id }`, resolve: (user, _args, context, info) => batchDelegateToSchema({ schema: bookSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'booksByUserIds', key: user.id, argsFromKeys: (userIds) => ({ userIds }), diff --git a/packages/batch-execute/src/mergeRequests.ts b/packages/batch-execute/src/mergeRequests.ts index 1b4823dd799..a2c7da5ffe2 100644 --- a/packages/batch-execute/src/mergeRequests.ts +++ b/packages/batch-execute/src/mergeRequests.ts @@ -12,8 +12,6 @@ import { SelectionNode, FragmentSpreadNode, VariableNode, - VisitorKeyMap, - ASTKindToNode, InlineFragmentNode, FieldNode, } from 'graphql'; @@ -176,7 +174,7 @@ function aliasTopLevelFields(prefix: string, document: DocumentNode): DocumentNo }; return visit(document, transformer, { [Kind.DOCUMENT]: [`definitions`], - } as unknown as VisitorKeyMap); + } as any); } /** diff --git a/packages/batch-execute/tests/batchExecute.test.ts b/packages/batch-execute/tests/batchExecute.test.ts index e0b434024cd..c7f73340396 100644 --- a/packages/batch-execute/tests/batchExecute.test.ts +++ b/packages/batch-execute/tests/batchExecute.test.ts @@ -3,7 +3,8 @@ import { parse, print, OperationDefinitionNode, - ExecutionResult + ExecutionResult, + OperationTypeNode } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { createBatchingExecutor } from '@graphql-tools/batch-execute'; @@ -68,8 +69,8 @@ describe('batch execution', () => { it('batchs multiple executions', async () => { const [first, second] = await Promise.all([ - batchExec({ document: parse('{ field1 field2 }'), operationType: 'query' }), - batchExec({ document: parse('{ field2 field3(input: "3") }'), operationType: 'query' }), + batchExec({ document: parse('{ field1 field2 }'), operationType: 'query' as OperationTypeNode, }), + batchExec({ document: parse('{ field2 field3(input: "3") }'), operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; expect(first?.data).toEqual({ field1: '1', field2: '2' }); @@ -80,8 +81,8 @@ describe('batch execution', () => { it('preserves root field aliases in the final result', async () => { const [first, second] = await Promise.all([ - batchExec({ document: parse('{ a: field1 b: field2 }'), operationType: 'query' }), - batchExec({ document: parse('{ c: field2 d: field3(input: "3") }'), operationType: 'query' }), + batchExec({ document: parse('{ a: field1 b: field2 }'), operationType: 'query' as OperationTypeNode, }), + batchExec({ document: parse('{ c: field2 d: field3(input: "3") }'), operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; expect(first?.data).toEqual({ a: '1', b: '2' }); @@ -95,12 +96,12 @@ describe('batch execution', () => { batchExec({ document: parse('query($a: String){ field3(input: $a) }'), variables: { a: '1' }, - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), batchExec({ document: parse('query($a: String){ field3(input: $a) }'), variables: { a: '2' }, - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; @@ -112,8 +113,8 @@ describe('batch execution', () => { it('renames fields within inline spreads', async () => { const [first, second] = await Promise.all([ - batchExec({ document: parse('{ ...on Query { field1 } }'), operationType: 'query' }), - batchExec({ document: parse('{ ...on Query { field2 } }'), operationType: 'query' }), + batchExec({ document: parse('{ ...on Query { field1 } }'), operationType: 'query' as OperationTypeNode, }), + batchExec({ document: parse('{ ...on Query { field2 } }'), operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; const squishedDoc = executorDocument?.replace(/\s+/g, ' '); @@ -128,11 +129,11 @@ describe('batch execution', () => { const [first, second] = await Promise.all([ batchExec({ document: parse('fragment A on Widget { name } query{ widget { ...A } }'), - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), batchExec({ document: parse('fragment A on Widget { name } query{ widget { ...A } }'), - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; @@ -150,11 +151,11 @@ describe('batch execution', () => { const [first, second] = await Promise.all([ batchExec({ document: parse('fragment A on Query { field1 } query{ ...A }'), - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), batchExec({ document: parse('fragment A on Query { field2 } query{ ...A }'), - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; @@ -167,11 +168,11 @@ describe('batch execution', () => { const [first, second] = await Promise.all([ batchExec({ document: parse('{ first: boom(message: "first error") }'), - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), batchExec({ document: parse('{ second: boom(message: "second error") }'), - operationType: 'query', + operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; @@ -184,8 +185,8 @@ describe('batch execution', () => { it('returns request-level errors to all results', async () => { const [first, second] = await Promise.all([ - batchExec({ document: parse('{ field1 field2 }'), operationType: 'query' }), - batchExec({ document: parse('{ notgonnawork }'), operationType: 'query' }), + batchExec({ document: parse('{ field1 field2 }'), operationType: 'query' as OperationTypeNode, }), + batchExec({ document: parse('{ notgonnawork }'), operationType: 'query' as OperationTypeNode, }), ]) as ExecutionResult[]; expect(first?.errors?.length).toEqual(1); diff --git a/packages/delegate/src/createRequest.ts b/packages/delegate/src/createRequest.ts index 6c28857d5df..154eeeb4eb7 100644 --- a/packages/delegate/src/createRequest.ts +++ b/packages/delegate/src/createRequest.ts @@ -14,6 +14,7 @@ import { SelectionSetNode, DefinitionNode, DocumentNode, + NameNode, } from 'graphql'; import { @@ -26,12 +27,12 @@ import { ICreateRequestFromInfo, ICreateRequest } from './types'; export function getDelegatingOperation(parentType: GraphQLObjectType, schema: GraphQLSchema): OperationTypeNode { if (parentType === schema.getMutationType()) { - return 'mutation'; + return 'mutation' as OperationTypeNode; } else if (parentType === schema.getSubscriptionType()) { - return 'subscription'; + return 'subscription' as OperationTypeNode; } - return 'query'; + return 'query' as OperationTypeNode; } export function createRequestFromInfo({ @@ -149,7 +150,7 @@ export function createRequest({ selectionSet: newSelectionSet, }; - const operationName = targetOperationName + const operationName: NameNode | undefined = targetOperationName ? { kind: Kind.NAME, value: targetOperationName, diff --git a/packages/delegate/src/finalizeGatewayRequest.ts b/packages/delegate/src/finalizeGatewayRequest.ts index 7a5f8f8b57c..b9032af3f7b 100644 --- a/packages/delegate/src/finalizeGatewayRequest.ts +++ b/packages/delegate/src/finalizeGatewayRequest.ts @@ -1,6 +1,6 @@ import { ArgumentNode, - ASTKindToNode, + DocumentNode, FragmentDefinitionNode, getNamedType, GraphQLField, @@ -19,7 +19,6 @@ import { VariableDefinitionNode, versionInfo as graphqlVersionInfo, visit, - VisitorKeyMap, visitWithTypeInfo, } from 'graphql'; @@ -31,6 +30,7 @@ import { createVariableNameGenerator, implementsAbstractType, inspect, + ASTVisitorKeyMap, } from '@graphql-tools/utils'; import { DelegationContext } from './types'; @@ -94,12 +94,14 @@ function finalizeGatewayDocument( }); } + const newDocument: DocumentNode = { + kind: Kind.DOCUMENT, + definitions: [...newOperations, ...newFragments], + }; + return { usedVariables, - newDocument: { - kind: Kind.DOCUMENT, - definitions: [...newOperations, ...newFragments], - }, + newDocument, }; } @@ -158,7 +160,7 @@ function addVariablesToRootFields( const type = getDefinedRootType(targetSchema, operation.operation); - const newSelectionSet: Array = []; + const newSelections: Array = []; for (const selection of operation.selectionSet.selections) { if (selection.kind === Kind.FIELD) { @@ -178,22 +180,24 @@ function addVariablesToRootFields( updateArguments(targetField, argumentNodeMap, variableDefinitionMap, newVariables, args); } - newSelectionSet.push({ + newSelections.push({ ...selection, arguments: Object.values(argumentNodeMap), }); } else { - newSelectionSet.push(selection); + newSelections.push(selection); } } + const newSelectionSet: SelectionSetNode = { + kind: Kind.SELECTION_SET, + selections: newSelections, + }; + return { ...operation, variableDefinitions: Object.values(variableDefinitionMap), - selectionSet: { - kind: Kind.SELECTION_SET, - selections: newSelectionSet, - }, + selectionSet: newSelectionSet, }; }); @@ -284,14 +288,14 @@ function collectFragmentVariables( }; } -const filteredSelectionSetVisitorKeys: Partial> = { +const filteredSelectionSetVisitorKeys: ASTVisitorKeyMap = { SelectionSet: ['selections'], Field: ['selectionSet'], InlineFragment: ['selectionSet'], FragmentDefinition: ['selectionSet'], }; -const variablesVisitorKeys: Partial> = { +const variablesVisitorKeys: ASTVisitorKeyMap = { SelectionSet: ['selections'], Field: ['arguments', 'directives', 'selectionSet'], Argument: ['value'], diff --git a/packages/delegate/src/prepareGatewayDocument.ts b/packages/delegate/src/prepareGatewayDocument.ts index 3601e3d55e5..34c5f03672b 100644 --- a/packages/delegate/src/prepareGatewayDocument.ts +++ b/packages/delegate/src/prepareGatewayDocument.ts @@ -16,11 +16,9 @@ import { GraphQLOutputType, isObjectType, FieldNode, - VisitorKeyMap, - ASTKindToNode, } from 'graphql'; -import { implementsAbstractType, getRootTypeNames, memoize2 } from '@graphql-tools/utils'; +import { implementsAbstractType, getRootTypeNames, memoize2, ASTVisitorKeyMap } from '@graphql-tools/utils'; import { getDocumentMetadata } from './getDocumentMetadata'; import { StitchingInfo } from './types'; @@ -52,12 +50,12 @@ export function prepareGatewayDocument( const typeInfo = new TypeInfo(transformedSchema); - const expandedDocument = { + const expandedDocument: DocumentNode = { kind: Kind.DOCUMENT, definitions: [...operations, ...fragments, ...expandedFragments], }; - const visitorKeyMap: Partial> = { + const visitorKeyMap: ASTVisitorKeyMap = { Document: ['definitions'], OperationDefinition: ['selectionSet'], SelectionSet: ['selections'], @@ -392,7 +390,7 @@ function wrapConcreteTypes( const typeInfo = new TypeInfo(targetSchema); - const visitorKeys: Partial> = { + const visitorKeys: ASTVisitorKeyMap = { Document: ['definitions'], OperationDefinition: ['selectionSet'], SelectionSet: ['selections'], diff --git a/packages/delegate/tests/createRequest.test.ts b/packages/delegate/tests/createRequest.test.ts index 573f3c1cc2e..5d9180b0893 100644 --- a/packages/delegate/tests/createRequest.test.ts +++ b/packages/delegate/tests/createRequest.test.ts @@ -1,4 +1,4 @@ -import { graphql, Kind, GraphQLError } from 'graphql'; +import { graphql, Kind, GraphQLError, OperationTypeNode } from 'graphql'; import { createRequest } from '../src/createRequest'; import { makeExecutableSchema } from '@graphql-tools/schema'; @@ -66,7 +66,7 @@ describe('bare requests', () => { } }] }], - targetOperation: 'query', + targetOperation: 'query' as OperationTypeNode, targetFieldName: 'test', }); return delegateRequest({ @@ -149,7 +149,7 @@ describe('bare requests', () => { }], }, }], - targetOperation: 'query', + targetOperation: 'query' as OperationTypeNode, targetFieldName: 'test', }); return delegateRequest({ @@ -214,7 +214,7 @@ describe('bare requests', () => { value: 'delegate', }, }], - targetOperation: 'query', + targetOperation: 'query' as OperationTypeNode, targetFieldName: 'test', }); return delegateRequest({ diff --git a/packages/delegate/tests/delegateToSchema.test.ts b/packages/delegate/tests/delegateToSchema.test.ts index 13ce52cdefb..02a1684c16e 100644 --- a/packages/delegate/tests/delegateToSchema.test.ts +++ b/packages/delegate/tests/delegateToSchema.test.ts @@ -1,4 +1,4 @@ -import { graphql } from 'graphql'; +import { graphql, OperationTypeNode } from 'graphql'; import { delegateToSchema } from '../src/delegateToSchema'; import { makeExecutableSchema } from '@graphql-tools/schema'; @@ -36,7 +36,7 @@ describe('delegateToSchema', () => { Query: { delegateToSchema: (_root, args, context, info) => delegateToSchema({ schema: innerSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'test', args, context, @@ -83,7 +83,7 @@ describe('delegateToSchema', () => { Query: { delegateToSchema: (_root, args, context, info) => delegateToSchema({ schema: innerSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'test', args, context, @@ -130,7 +130,7 @@ describe('delegateToSchema', () => { Query: { delegateToSchema: (_root, args, context, info) => delegateToSchema({ schema: innerSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'test', args, context, diff --git a/packages/delegate/tests/errors.test.ts b/packages/delegate/tests/errors.test.ts index 1fd6edfa88a..cbc77ff6ddd 100644 --- a/packages/delegate/tests/errors.test.ts +++ b/packages/delegate/tests/errors.test.ts @@ -1,4 +1,4 @@ -import { GraphQLError, GraphQLResolveInfo, locatedError, graphql } from 'graphql'; +import { GraphQLError, GraphQLResolveInfo, locatedError, graphql, OperationTypeNode } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { ExecutionResult } from '@graphql-tools/utils'; @@ -140,7 +140,7 @@ describe('Errors', () => { Query: { object: (_parent, _args, context, info) => delegateToSchema({ schema: remoteSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, context, info, }), diff --git a/packages/delegate/tests/finalizeGatewayRequest.test.ts b/packages/delegate/tests/finalizeGatewayRequest.test.ts index e312bc6699a..59678569247 100644 --- a/packages/delegate/tests/finalizeGatewayRequest.test.ts +++ b/packages/delegate/tests/finalizeGatewayRequest.test.ts @@ -1,4 +1,4 @@ -import { print, parse } from 'graphql'; +import { print, parse, OperationTypeNode } from 'graphql'; import { DelegationContext } from '@graphql-tools/delegate'; import { bookingSchema, propertySchema } from '../../testing/fixtures/schemas'; import { finalizeGatewayRequest } from '../src/finalizeGatewayRequest'; @@ -21,7 +21,7 @@ describe('finalizeGatewayRequest', () => { variables: { id: 'c1', }, - operationType: 'query' as const + operationType: 'query' as OperationTypeNode }, { targetSchema: bookingSchema } as DelegationContext); @@ -55,7 +55,7 @@ describe('finalizeGatewayRequest', () => { id: 'c1', limit: 10, }, - operationType: 'query' as const, + operationType: 'query' as OperationTypeNode, }, { targetSchema: bookingSchema } as DelegationContext); @@ -82,7 +82,7 @@ describe('finalizeGatewayRequest', () => { variables: { test: 'test', }, - operationType: 'query' as const, + operationType: 'query' as OperationTypeNode, }, { targetSchema: propertySchema } as DelegationContext); @@ -113,7 +113,7 @@ describe('finalizeGatewayRequest', () => { variables: { id: 'b1', }, - operationType: 'query' as const, + operationType: 'query' as OperationTypeNode, }, { targetSchema: bookingSchema } as DelegationContext); diff --git a/packages/load/src/filter-document-kind.ts b/packages/load/src/filter-document-kind.ts index 044a55404f4..e0e6a491ca6 100644 --- a/packages/load/src/filter-document-kind.ts +++ b/packages/load/src/filter-document-kind.ts @@ -4,7 +4,10 @@ import { env } from 'process'; /** * @internal */ -export const filterKind = (content: DocumentNode | undefined, filterKinds: null | string[]) => { +export const filterKind = ( + content: DocumentNode | undefined, + filterKinds: null | string[] +): DocumentNode | undefined => { if (content && content.definitions && content.definitions.length && filterKinds && filterKinds.length > 0) { const invalidDefinitions: DefinitionNode[] = []; const validDefinitions: DefinitionNode[] = []; diff --git a/packages/merge/src/typedefs-mergers/enum.ts b/packages/merge/src/typedefs-mergers/enum.ts index 566fe802e43..160ab36d1c6 100644 --- a/packages/merge/src/typedefs-mergers/enum.ts +++ b/packages/merge/src/typedefs-mergers/enum.ts @@ -1,4 +1,4 @@ -import { EnumTypeDefinitionNode, EnumTypeExtensionNode } from 'graphql'; +import { EnumTypeDefinitionNode, EnumTypeExtensionNode, Kind } from 'graphql'; import { mergeDirectives } from './directives'; import { mergeEnumValues } from './enum-values'; import { Config } from './merge-typedefs'; @@ -25,7 +25,7 @@ export function mergeEnum( return config?.convertExtensions ? { ...e1, - kind: 'EnumTypeDefinition', + kind: Kind.ENUM_TYPE_DEFINITION, } : e1; } diff --git a/packages/merge/src/typedefs-mergers/input-type.ts b/packages/merge/src/typedefs-mergers/input-type.ts index 0fa30232c5a..f2d4ad517c3 100644 --- a/packages/merge/src/typedefs-mergers/input-type.ts +++ b/packages/merge/src/typedefs-mergers/input-type.ts @@ -1,5 +1,5 @@ import { Config } from './merge-typedefs'; -import { InputObjectTypeDefinitionNode, InputValueDefinitionNode, InputObjectTypeExtensionNode } from 'graphql'; +import { InputObjectTypeDefinitionNode, InputValueDefinitionNode, InputObjectTypeExtensionNode, Kind } from 'graphql'; import { mergeFields } from './fields'; import { mergeDirectives } from './directives'; @@ -31,7 +31,7 @@ export function mergeInputType( return config?.convertExtensions ? { ...node, - kind: 'InputObjectTypeDefinition', + kind: Kind.INPUT_OBJECT_TYPE_DEFINITION, } : node; } diff --git a/packages/merge/src/typedefs-mergers/interface.ts b/packages/merge/src/typedefs-mergers/interface.ts index 8c5eebcd82d..1c9e0a23bd2 100644 --- a/packages/merge/src/typedefs-mergers/interface.ts +++ b/packages/merge/src/typedefs-mergers/interface.ts @@ -1,5 +1,5 @@ import { Config } from './merge-typedefs'; -import { InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode } from 'graphql'; +import { InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, Kind } from 'graphql'; import { mergeFields } from './fields'; import { mergeDirectives } from './directives'; @@ -31,7 +31,7 @@ export function mergeInterface( return config?.convertExtensions ? { ...node, - kind: 'InterfaceTypeDefinition', + kind: Kind.INTERFACE_TYPE_DEFINITION, } : node; } diff --git a/packages/merge/src/typedefs-mergers/merge-typedefs.ts b/packages/merge/src/typedefs-mergers/merge-typedefs.ts index aefa2283fba..3916d729006 100644 --- a/packages/merge/src/typedefs-mergers/merge-typedefs.ts +++ b/packages/merge/src/typedefs-mergers/merge-typedefs.ts @@ -90,7 +90,7 @@ export function mergeTypeDefs( export function mergeTypeDefs(typeSource: TypeSource, config?: Partial): DocumentNode | string { resetComments(); - const doc = { + const doc: DocumentNode = { kind: Kind.DOCUMENT, definitions: mergeGraphQLTypes(typeSource, { useSchemaDefinition: true, @@ -188,7 +188,7 @@ export function mergeGraphQLTypes(typeSource: TypeSource, config: Config): Defin operationTypes: [ { kind: Kind.OPERATION_TYPE_DEFINITION, - operation: 'query', + operation: 'query' as OperationTypeNode, type: { kind: Kind.NAMED_TYPE, name: { diff --git a/packages/merge/src/typedefs-mergers/scalar.ts b/packages/merge/src/typedefs-mergers/scalar.ts index 58c65d5b0ed..5869cf2852d 100644 --- a/packages/merge/src/typedefs-mergers/scalar.ts +++ b/packages/merge/src/typedefs-mergers/scalar.ts @@ -1,4 +1,4 @@ -import { ScalarTypeDefinitionNode, ScalarTypeExtensionNode } from 'graphql'; +import { Kind, ScalarTypeDefinitionNode, ScalarTypeExtensionNode } from 'graphql'; import { mergeDirectives } from './directives'; import { Config } from './merge-typedefs'; @@ -25,7 +25,7 @@ export function mergeScalar( return config?.convertExtensions ? { ...node, - kind: 'ScalarTypeDefinition', + kind: Kind.SCALAR_TYPE_DEFINITION, } : node; } diff --git a/packages/merge/src/typedefs-mergers/type.ts b/packages/merge/src/typedefs-mergers/type.ts index 00e974a9d35..bdc546c8b3f 100644 --- a/packages/merge/src/typedefs-mergers/type.ts +++ b/packages/merge/src/typedefs-mergers/type.ts @@ -1,5 +1,5 @@ import { Config } from './merge-typedefs'; -import { ObjectTypeDefinitionNode, ObjectTypeExtensionNode } from 'graphql'; +import { Kind, ObjectTypeDefinitionNode, ObjectTypeExtensionNode } from 'graphql'; import { mergeFields } from './fields'; import { mergeDirectives } from './directives'; import { mergeNamedTypeArray } from './merge-named-type-array'; @@ -33,7 +33,7 @@ export function mergeType( return config?.convertExtensions ? { ...node, - kind: 'ObjectTypeDefinition', + kind: Kind.OBJECT_TYPE_DEFINITION, } : node; } diff --git a/packages/merge/src/typedefs-mergers/union.ts b/packages/merge/src/typedefs-mergers/union.ts index 7d173f03aba..86aff8ac19d 100644 --- a/packages/merge/src/typedefs-mergers/union.ts +++ b/packages/merge/src/typedefs-mergers/union.ts @@ -1,4 +1,4 @@ -import { UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql'; +import { Kind, UnionTypeDefinitionNode, UnionTypeExtensionNode } from 'graphql'; import { mergeDirectives } from './directives'; import { mergeNamedTypeArray } from './merge-named-type-array'; import { Config } from './merge-typedefs'; @@ -16,8 +16,8 @@ export function mergeUnion( directives: mergeDirectives(first.directives, second.directives, config) as any, kind: config?.convertExtensions || first.kind === 'UnionTypeDefinition' || second.kind === 'UnionTypeDefinition' - ? 'UnionTypeDefinition' - : 'UnionTypeExtension', + ? Kind.UNION_TYPE_DEFINITION + : Kind.UNION_TYPE_EXTENSION, loc: first.loc, types: mergeNamedTypeArray(first.types, second.types, config), }; @@ -26,7 +26,7 @@ export function mergeUnion( return config?.convertExtensions ? { ...first, - kind: 'UnionTypeDefinition', + kind: Kind.UNION_TYPE_DEFINITION, } : first; } diff --git a/packages/merge/tests/extract-extensions-from-schema.spec.ts b/packages/merge/tests/extract-extensions-from-schema.spec.ts index 4e360fa3f12..805dcf77e0c 100644 --- a/packages/merge/tests/extract-extensions-from-schema.spec.ts +++ b/packages/merge/tests/extract-extensions-from-schema.spec.ts @@ -184,7 +184,7 @@ describe('extensions', () => { MyInput = cleanSchema.getType('MyInput') assertGraphQLInputObjectType(MyInput) // To make sure it's stripped - expect(MyInput.extensions).toBeUndefined(); + expect(Object.keys(MyInput.extensions || {})).toHaveLength(0); const modifiedSchema = applyExtensions(cleanSchema, result); diff --git a/packages/merge/tests/merge-typedefs.spec.ts b/packages/merge/tests/merge-typedefs.spec.ts index 373c27d476b..dd20d74508f 100644 --- a/packages/merge/tests/merge-typedefs.spec.ts +++ b/packages/merge/tests/merge-typedefs.spec.ts @@ -3,7 +3,7 @@ import '../../testing/to-be-similar-string'; import { mergeDirectives, mergeTypeDefs, mergeGraphQLTypes } from '../src'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { stitchSchemas } from '@graphql-tools/stitch' -import { buildSchema, buildClientSchema, print, parse, Kind } from 'graphql'; +import { buildSchema, buildClientSchema, print, parse, Kind, DirectiveNode } from 'graphql'; import { stripWhitespaces } from './utils'; import gql from 'graphql-tag'; import { readFileSync } from 'fs'; @@ -1297,7 +1297,7 @@ describe('Merge TypeDefs', () => { }); it(`should merge with first schema directives set in ${direction} order`, () => { - const directives = [{ + const directives: DirectiveNode[] = [{ kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, @@ -1308,7 +1308,7 @@ describe('Merge TypeDefs', () => { }); it(`should merge with second schema directives set in ${direction} order`, () => { - const directives = [{ + const directives: DirectiveNode[] = [{ kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, @@ -1319,7 +1319,7 @@ describe('Merge TypeDefs', () => { }); it(`should merge with both schema directives set in ${direction} order`, () => { - const directives = [{ + const directives: DirectiveNode[] = [{ kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, @@ -1330,14 +1330,14 @@ describe('Merge TypeDefs', () => { }); it(`should merge with both schema directives set, one of which has arguments in ${direction} order`, () => { - const directivesOne = [{ + const directivesOne: DirectiveNode[] = [{ kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, value: 'firstDirective' } }]; - const directivesTwo = [{ + const directivesTwo: DirectiveNode[] = [{ kind: Kind.DIRECTIVE, name: { kind: Kind.NAME, diff --git a/packages/schema/tests/schemaGenerator.test.ts b/packages/schema/tests/schemaGenerator.test.ts index ef02cde8ee3..6ac04229c14 100644 --- a/packages/schema/tests/schemaGenerator.test.ts +++ b/packages/schema/tests/schemaGenerator.test.ts @@ -2042,7 +2042,7 @@ describe('can specify lexical parser options', () => { const parsedQuery = parse(query, { experimentalFragmentVariables: true, allowLegacyFragmentVariables: true } as any); - const hoist = (document: DocumentNode) => { + const hoist = (document: DocumentNode): DocumentNode => { const variableDefs: Array = []; for (const def of document.definitions) { diff --git a/packages/stitch/src/createMergedTypeResolver.ts b/packages/stitch/src/createMergedTypeResolver.ts index 76735bf923b..3835c76bfb5 100644 --- a/packages/stitch/src/createMergedTypeResolver.ts +++ b/packages/stitch/src/createMergedTypeResolver.ts @@ -1,4 +1,4 @@ -import { getNamedType, GraphQLOutputType, GraphQLList } from 'graphql'; +import { getNamedType, GraphQLOutputType, GraphQLList, OperationTypeNode } from 'graphql'; import { delegateToSchema, MergedTypeResolver, MergedTypeResolverOptions } from '@graphql-tools/delegate'; import { batchDelegateToSchema } from '@graphql-tools/batch-delegate'; @@ -11,7 +11,7 @@ export function createMergedTypeResolver( return function mergedBatchedTypeResolver(originalResult, context, info, subschema, selectionSet, key) { return batchDelegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName, returnType: new GraphQLList( getNamedType(info.schema.getType(originalResult.__typename) ?? info.returnType) as GraphQLOutputType @@ -31,7 +31,7 @@ export function createMergedTypeResolver( return function mergedTypeResolver(originalResult, context, info, subschema, selectionSet) { return delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName, returnType: getNamedType( info.schema.getType(originalResult.__typename) ?? info.returnType diff --git a/packages/stitch/src/typeFromAST.ts b/packages/stitch/src/typeFromAST.ts index ee9146ce104..356d91a776d 100644 --- a/packages/stitch/src/typeFromAST.ts +++ b/packages/stitch/src/typeFromAST.ts @@ -17,7 +17,6 @@ import { UnionTypeDefinitionNode, GraphQLDirective, DirectiveDefinitionNode, - DirectiveLocationEnum, DirectiveLocation, GraphQLFieldConfig, GraphQLEnumValueConfigMap, @@ -27,6 +26,7 @@ import { getDirectiveValues, GraphQLDeprecatedDirective, TypeDefinitionNode, + DirectiveLocationEnum, } from 'graphql'; import { createStub, createNamedStub, Maybe, getDescription } from '@graphql-tools/utils'; @@ -86,7 +86,7 @@ function makeInterfaceType(node: InterfaceTypeDefinitionNode): GraphQLInterfaceT fields: () => (node.fields != null ? makeFields(node.fields) : {}), astNode: node, }; - return new GraphQLInterfaceType(config); + return new GraphQLInterfaceType(config as any); } function makeEnumType(node: EnumTypeDefinitionNode): GraphQLEnumType { @@ -171,17 +171,22 @@ function makeValues(nodes: ReadonlyArray): GraphQLFiel ); } +function isLocationValue(value: any): value is DirectiveLocationEnum { + return value in DirectiveLocation; +} + function makeDirective(node: DirectiveDefinitionNode): GraphQLDirective { const locations: Array = []; for (const location of node.locations) { - if (location.value in DirectiveLocation) { - locations.push(location.value as DirectiveLocationEnum); + const locationValue = location.value; + if (isLocationValue(locationValue)) { + locations.push(locationValue); } } return new GraphQLDirective({ name: node.name.value, description: node.description != null ? node.description.value : null, - locations, + locations: locations as any[], isRepeatable: node.repeatable, args: makeValues(node.arguments ?? []), astNode: node, diff --git a/packages/stitch/tests/alternateStitchSchemas.test.ts b/packages/stitch/tests/alternateStitchSchemas.test.ts index 7cbd2e4ee5f..872377e0ee8 100644 --- a/packages/stitch/tests/alternateStitchSchemas.test.ts +++ b/packages/stitch/tests/alternateStitchSchemas.test.ts @@ -13,6 +13,8 @@ import { GraphQLNamedType, Kind, execute, + OperationTypeNode, + GraphQLError, } from 'graphql'; import { @@ -161,7 +163,7 @@ describe('merge schemas through transforms', () => { if (args.id.startsWith('p')) { return delegateToSchema({ schema: propertySubschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args, context, @@ -171,7 +173,7 @@ describe('merge schemas through transforms', () => { } else if (args.id.startsWith('b')) { return delegateToSchema({ schema: bookingSubschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookingById', args, context, @@ -181,7 +183,7 @@ describe('merge schemas through transforms', () => { } else if (args.id.startsWith('c')) { return delegateToSchema({ schema: bookingSubschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'customerById', args, context, @@ -198,7 +200,7 @@ describe('merge schemas through transforms', () => { resolve: (parent, args, context, info) => delegateToSchema({ schema: bookingSubschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookingsByPropertyId', args: { propertyId: parent.id, @@ -224,7 +226,7 @@ describe('merge schemas through transforms', () => { resolve: (parent, _args, context, info) => delegateToSchema({ schema: propertySubschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args: { id: parent.propertyId, @@ -745,17 +747,9 @@ describe('transform object fields', () => { `, }); - const expectedResult: any = { + const expectedResult: ExecutionResult = { errors: [ - { - locations: [ - { - column: 17, - line: 6, - }, - ], - message: 'Cannot query field "id" on type "Item".', - }, + new GraphQLError('Cannot query field "id" on type "Item".', undefined, undefined, [17,6]), ], }; @@ -836,7 +830,7 @@ type Query { }, }); - const expectedResult: any = { + const expectedResult: ExecutionResult = { data: { propertyById: { // eslint-disable-next-line camelcase @@ -852,21 +846,10 @@ type Query { }, }, errors: [ - { - locations: [ - { - column: 13, - line: 9, - }, - ], - message: 'Property.error error', - path: ['propertyById', 'new_error'], - }, + new GraphQLError('Property.error error', undefined, undefined, [13, 9], ['propertyById, new_error'], undefined, { code: 'SOME_CUSTOM_CODE' }) ], }; - expectedResult.errors[0].extensions = { code: 'SOME_CUSTOM_CODE' }; - expect(result).toEqual(expectedResult); }); }); @@ -1010,7 +993,7 @@ describe('WrapType', () => { }, }); - const expectedResult: any = { + const expectedResult: ExecutionResult = { data: { namespace: { bookingById: { @@ -1022,16 +1005,7 @@ describe('WrapType', () => { }, }, errors: [ - { - locations: [ - { - column: 15, - line: 8, - }, - ], - message: 'Booking.error error', - path: ['namespace', 'bookingById', 'error'], - }, + new GraphQLError('Booking.error error', undefined, undefined, [15, 8], ['namespace', 'bookingById, error']) ], }; @@ -1070,7 +1044,7 @@ describe('WrapType', () => { }, }); - const expectedResult: any = { + const expectedResult: ExecutionResult = { data: { namespace: { addBooking: { @@ -1083,16 +1057,7 @@ describe('WrapType', () => { }, }, errors: [ - { - locations: [ - { - column: 15, - line: 9, - }, - ], - message: 'Booking.error error', - path: ['namespace', 'addBooking', 'error'], - }, + new GraphQLError('Booking.error error', undefined, undefined, [15, 9], ['namespace', 'addBooking', 'error']), ], }; @@ -1350,7 +1315,7 @@ describe('schema transformation with wrapping of object fields', () => { }, }); - const expectedResult: any = { + const expectedResult: ExecutionResult = { data: { propertyById: { test1: { @@ -1363,21 +1328,10 @@ describe('schema transformation with wrapping of object fields', () => { }, }, errors: [ - { - locations: [ - { - column: 13, - line: 14, - }, - ], - message: 'Property.error error', - path: ['propertyById', 'test1', 'two'], - }, + new GraphQLError('Property.error error', undefined, undefined, [13, 14], ['propertyById', 'test1', 'two'], undefined, { code: 'SOME_CUSTOM_CODE' }), ], }; - expectedResult.errors[0].extensions = { code: 'SOME_CUSTOM_CODE' }; - expect(result).toEqual(expectedResult); }); @@ -1424,7 +1378,7 @@ describe('schema transformation with wrapping of object fields', () => { }, }); - const expectedResult: any = { + const expectedResult: ExecutionResult = { data: { propertyById: { test1: { @@ -1441,21 +1395,10 @@ describe('schema transformation with wrapping of object fields', () => { }, }, errors: [ - { - locations: [ - { - column: 13, - line: 18, - }, - ], - message: 'Property.error error', - path: ['propertyById', 'test1', 'innerWrap', 'two'], - }, + new GraphQLError('Property.error error', undefined, undefined, [13, 18], ['propertyById', 'test1', 'innerWrap', 'two'], undefined, { code: 'SOME_CUSTOM_CODE' }), ], }; - expectedResult.errors[0].extensions = { code: 'SOME_CUSTOM_CODE' }; - expect(result).toEqual(expectedResult); }); @@ -1775,7 +1718,7 @@ type Query { get2: (_root, _args, context, info) => delegateToSchema({ schema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'get1', context, info, @@ -2008,7 +1951,7 @@ describe('basic type merging', () => { resolve: (originalResult, context, info, subschema, selectionSet) => delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'getTest', args: { id: originalResult.id }, selectionSet, @@ -2028,7 +1971,7 @@ describe('basic type merging', () => { resolve: (originalResult, context, info, subschema, selectionSet) => delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'getTest', args: { id: originalResult.id }, selectionSet, @@ -2152,7 +2095,7 @@ describe('unidirectional type merging', () => { resolve: (originalResult, context, info, subschema, selectionSet) => delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'getTest', args: { id: originalResult.id }, selectionSet, diff --git a/packages/stitch/tests/dataloader.test.ts b/packages/stitch/tests/dataloader.test.ts index 2dbe1e40f36..d05734ac4b3 100644 --- a/packages/stitch/tests/dataloader.test.ts +++ b/packages/stitch/tests/dataloader.test.ts @@ -1,5 +1,5 @@ import DataLoader from 'dataloader'; -import { graphql, GraphQLList, GraphQLResolveInfo } from 'graphql'; +import { graphql, GraphQLList, GraphQLResolveInfo, OperationTypeNode } from 'graphql'; import { delegateToSchema } from '@graphql-tools/delegate'; import { makeExecutableSchema } from '@graphql-tools/schema'; @@ -71,7 +71,7 @@ describe('dataloader', () => { async (keys: ReadonlyArray<{ id: any; info: GraphQLResolveInfo }>) => { const users = await delegateToSchema({ schema: userSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'usersByIds', args: { ids: keys.map((k: { id: any }) => k.id), diff --git a/packages/stitch/tests/example.test.ts b/packages/stitch/tests/example.test.ts index 2c0d6fc159e..9d929dc8e58 100644 --- a/packages/stitch/tests/example.test.ts +++ b/packages/stitch/tests/example.test.ts @@ -1,4 +1,4 @@ -import { graphql, GraphQLSchema } from 'graphql'; +import { graphql, GraphQLSchema, OperationTypeNode } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { delegateToSchema } from '@graphql-tools/delegate'; @@ -63,7 +63,7 @@ describe('basic stitching example', () => { selectionSet: `{ id }`, resolve: (user, _args, context, info) => delegateToSchema({ schema: chirpSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'chirpsByAuthorId', args: { authorId: user.id, @@ -78,7 +78,7 @@ describe('basic stitching example', () => { selectionSet: `{ authorId }`, resolve: (chirp, _args, context, info) => delegateToSchema({ schema: authorSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'userById', args: { id: chirp.authorId, @@ -181,7 +181,7 @@ describe('stitching to interfaces', () => { selectionSet: `{ id }`, resolve: (user, _args, context, info) => delegateToSchema({ schema: chirpSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'chirpsByAuthorId', args: { authorId: user.id, @@ -196,7 +196,7 @@ describe('stitching to interfaces', () => { selectionSet: `{ authorId }`, resolve: (chirp, _args, context, info) => delegateToSchema({ schema: authorSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'node', args: { id: chirp.authorId, diff --git a/packages/stitch/tests/selectionSets.test.ts b/packages/stitch/tests/selectionSets.test.ts index e5829a53c12..6016162ab2e 100644 --- a/packages/stitch/tests/selectionSets.test.ts +++ b/packages/stitch/tests/selectionSets.test.ts @@ -1,4 +1,4 @@ -import { graphql } from 'graphql'; +import { graphql, OperationTypeNode } from 'graphql'; import { delegateToSchema } from '@graphql-tools/delegate'; import { batchDelegateToSchema } from '@graphql-tools/batch-delegate'; @@ -47,7 +47,7 @@ describe('delegateToSchema ', () => { resolve(booking, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args: { id: booking.propertyId }, context, @@ -178,7 +178,7 @@ describe('delegateToSchema ', () => { context, fieldName: 'networks', info, - operation: 'query', + operation: 'query' as OperationTypeNode, schema: networkSchema, }) }, diff --git a/packages/stitch/tests/stitchSchemas.test.ts b/packages/stitch/tests/stitchSchemas.test.ts index f34e1025a42..99f8a620416 100644 --- a/packages/stitch/tests/stitchSchemas.test.ts +++ b/packages/stitch/tests/stitchSchemas.test.ts @@ -7,6 +7,8 @@ import { parse, printSchema, GraphQLResolveInfo, + OperationTypeNode, + GraphQLError, } from 'graphql'; import { delegateToSchema, SubschemaConfig } from '@graphql-tools/delegate'; @@ -34,7 +36,7 @@ import { } from '../../testing/fixtures/schemas'; // eslint-disable-next-line @typescript-eslint/no-unused-vars -const removeLocations = ({ locations, ...rest }: any): any => ({ ...rest }); +const removeLocations = ({ locations, positions, source, originalError, nodes, ...rest }: any): any => ({ ...rest }); const testCombinations = [ { @@ -359,7 +361,7 @@ for (const combination of testCombinations) { resolve(parent, args, context, info) { return delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookingsByPropertyId', args: { propertyId: parent.id, @@ -382,7 +384,7 @@ for (const combination of testCombinations) { resolve(parent, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args: { id: parent.propertyId, @@ -409,7 +411,7 @@ for (const combination of testCombinations) { resolve(_parent, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args: { id: 'p1', @@ -429,7 +431,7 @@ for (const combination of testCombinations) { delegateInterfaceTest(_parent, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'interfaceTest', args: { kind: 'ONE', @@ -441,7 +443,7 @@ for (const combination of testCombinations) { delegateArgumentTest(_parent, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args: { id: 'p1', @@ -461,7 +463,7 @@ for (const combination of testCombinations) { if (args.id.startsWith('p')) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args, context, @@ -470,7 +472,7 @@ for (const combination of testCombinations) { } else if (args.id.startsWith('b')) { return delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookingById', args, context, @@ -479,7 +481,7 @@ for (const combination of testCombinations) { } else if (args.id.startsWith('c')) { return delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'customerById', args, context, @@ -493,14 +495,14 @@ for (const combination of testCombinations) { async nodes(_parent, _args, context, info) { const bookings = await delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookings', context, info, }); const properties = await delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'properties', context, info, @@ -860,16 +862,7 @@ bookingById(id: "b1") { }, } as any, errors: [ - { - message: 'subscription field error', - path: ['notifications', 'throwError'], - locations: [ - { - line: 4, - column: 15, - }, - ], - }, + new GraphQLError('subscription field error', undefined, undefined, [4, 15], ['notifications', 'throwError']) ], }; @@ -1372,7 +1365,7 @@ bookingById(id: "b1") { resolve(parent, args, context, info) { return delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookingsByPropertyId', args: { propertyId: parent.id, @@ -1392,7 +1385,7 @@ bookingById(id: "b1") { resolve(parent, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args: { id: parent.propertyId, @@ -1419,7 +1412,7 @@ bookingById(id: "b1") { delegateInterfaceTest(_parent, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'interfaceTest', args: { kind: 'ONE', @@ -1431,7 +1424,7 @@ bookingById(id: "b1") { delegateArgumentTest(_parent, _args, context, info) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args: { id: 'p1', @@ -1451,7 +1444,7 @@ bookingById(id: "b1") { if (args.id.startsWith('p')) { return delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'propertyById', args, context, @@ -1460,7 +1453,7 @@ bookingById(id: "b1") { } else if (args.id.startsWith('b')) { return delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookingById', args, context, @@ -1469,7 +1462,7 @@ bookingById(id: "b1") { } else if (args.id.startsWith('c')) { return delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'customerById', args, context, @@ -1488,14 +1481,14 @@ bookingById(id: "b1") { async nodes(_parent, _args, context, info) { const bookings = await delegateToSchema({ schema: bookingSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'bookings', context, info, }); const properties = await delegateToSchema({ schema: propertySchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'properties', context, info, @@ -2200,7 +2193,7 @@ fragment BookingFragment on Booking { const result = await delegateToSchema( { schema: remoteSchema, - operation: "query", + operation: "query" as OperationTypeNode, fieldName: "persona", context, info, @@ -2516,11 +2509,8 @@ fragment BookingFragment on Booking { expect(stitchedResult2.data).toBe(null); assertSome(stitchedResult2.errors) expect(stitchedResult2.errors.map(removeLocations)).toEqual([ - { - message: 'Sample error non-null!', - path: ['errorTestNonNull'], - }, - ]); + new GraphQLError('Sample error non-null!', undefined, undefined, undefined, ['errorTestNonNull']) + ].map(removeLocations)); }); test('nested errors', async () => { @@ -2568,45 +2558,18 @@ fragment BookingFragment on Booking { assertSome(result.errors) const errorsWithoutLocations = result.errors.map(removeLocations); - const expectedErrors: Array = [ - { - message: 'Property.error error', - path: ['propertyById', 'error'], - }, - { - message: 'Property.error error', - path: ['propertyById', 'errorAlias'], - }, - { - message: 'Booking.error error', - path: ['propertyById', 'bookings', 0, 'error'], - }, - { - message: 'Booking.error error', - path: ['propertyById', 'bookings', 0, 'bookingErrorAlias'], - }, - { - message: 'Booking.error error', - path: ['propertyById', 'bookings', 1, 'error'], - }, - { - message: 'Booking.error error', - path: ['propertyById', 'bookings', 1, 'bookingErrorAlias'], - }, - { - message: 'Booking.error error', - path: ['propertyById', 'bookings', 2, 'error'], - }, - { - message: 'Booking.error error', - path: ['propertyById', 'bookings', 2, 'bookingErrorAlias'], - }, - ]; - - expectedErrors[0].extensions = { code: 'SOME_CUSTOM_CODE' }; - expectedErrors[1].extensions = { code: 'SOME_CUSTOM_CODE' }; + const expectedErrors = [ + new GraphQLError('Property.error error', undefined, undefined, undefined, ['propertyById', 'error'], undefined, { code: 'SOME_CUSTOM_CODE' }), + new GraphQLError('Property.error error', undefined, undefined, undefined, ['propertyById', 'errorAlias'], undefined, { code: 'SOME_CUSTOM_CODE' }), + new GraphQLError('Booking.error error', undefined, undefined, undefined, ['propertyById', 'bookings', 0, 'error']), + new GraphQLError('Booking.error error', undefined, undefined, undefined, ['propertyById', 'bookings', 0, 'bookingErrorAlias']), + new GraphQLError('Booking.error error', undefined, undefined, undefined, ['propertyById', 'bookings', 1, 'error']), + new GraphQLError('Booking.error error', undefined, undefined, undefined, ['propertyById', 'bookings', 1, 'bookingErrorAlias']), + new GraphQLError('Booking.error error', undefined, undefined, undefined, ['propertyById', 'bookings', 2, 'error']), + new GraphQLError('Booking.error error', undefined, undefined, undefined, ['propertyById', 'bookings', 2, 'bookingErrorAlias']), + ].map(removeLocations); - expect(errorsWithoutLocations).toEqual(expectedErrors); + expect(errorsWithoutLocations).toEqual(expectedErrors.map(removeLocations)); }); test( @@ -3174,7 +3137,7 @@ fragment BookingFragment on Booking { typeDefs: [], }); - const result = await graphql({schema, source: '{ book { cat: category } }'}); + const result = await graphql({ schema, source: '{ book { cat: category } }' }); assertSome(result.data) const bookData: any = result.data['book']; expect(bookData.cat).toBe('Test'); @@ -3317,7 +3280,7 @@ fragment BookingFragment on Booking { selectionSet: `{ id } `, resolve: (obj, _args, _context, info) => delegateToSchema({ schema: stockSchema, - operation: "query", + operation: "query" as OperationTypeNode, fieldName: "stockRecord", args: { id: obj.id }, info, diff --git a/packages/stitch/tests/typeMerging.test.ts b/packages/stitch/tests/typeMerging.test.ts index 918e1cfa93f..52a2f04ccd0 100644 --- a/packages/stitch/tests/typeMerging.test.ts +++ b/packages/stitch/tests/typeMerging.test.ts @@ -1,7 +1,7 @@ // The below is meant to be an alternative canonical schema stitching example // which relies on type merging. -import { graphql } from 'graphql'; +import { graphql, OperationTypeNode } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; @@ -286,7 +286,7 @@ describe('merging using type merging', () => { resolve(container, _args, context, info) { return delegateToSchema({ schema: resultSchema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'resultById', args: { id: container.resultId, diff --git a/packages/stitching-directives/src/stitchingDirectives.ts b/packages/stitching-directives/src/stitchingDirectives.ts index cbb993d9f50..0ce1a117367 100644 --- a/packages/stitching-directives/src/stitchingDirectives.ts +++ b/packages/stitching-directives/src/stitchingDirectives.ts @@ -39,7 +39,7 @@ export function stitchingDirectives(options: StitchingDirectivesOptions = {}): S const keyDirective = new GraphQLDirective({ name: keyDirectiveName, - locations: ['OBJECT'], + locations: ['OBJECT'] as any[], args: { selectionSet: { type: new GraphQLNonNull(GraphQLString) }, }, @@ -47,7 +47,7 @@ export function stitchingDirectives(options: StitchingDirectivesOptions = {}): S const computedDirective = new GraphQLDirective({ name: computedDirectiveName, - locations: ['FIELD_DEFINITION'], + locations: ['FIELD_DEFINITION'] as any[], args: { selectionSet: { type: new GraphQLNonNull(GraphQLString) }, }, @@ -55,7 +55,7 @@ export function stitchingDirectives(options: StitchingDirectivesOptions = {}): S const mergeDirective = new GraphQLDirective({ name: mergeDirectiveName, - locations: ['FIELD_DEFINITION'], + locations: ['FIELD_DEFINITION'] as any[], args: { argsExpr: { type: GraphQLString }, keyArg: { type: GraphQLString }, @@ -76,7 +76,7 @@ export function stitchingDirectives(options: StitchingDirectivesOptions = {}): S 'SCALAR', 'FIELD_DEFINITION', 'INPUT_FIELD_DEFINITION', - ], + ] as any[], }); const allStitchingDirectivesTypeDefs = [ diff --git a/packages/stitching-directives/src/stitchingDirectivesTransformer.ts b/packages/stitching-directives/src/stitchingDirectivesTransformer.ts index 570aed10ac2..205e4d48de5 100644 --- a/packages/stitching-directives/src/stitchingDirectivesTransformer.ts +++ b/packages/stitching-directives/src/stitchingDirectivesTransformer.ts @@ -550,7 +550,7 @@ function mergeSelectionSets(...selectionSets: Array): Selectio } } - const newSelectionSet = { + const newSelectionSet: SelectionSetNode = { kind: Kind.SELECTION_SET, selections: Object.values(normalizedSelections), }; diff --git a/packages/utils/src/build-operation-for-field.ts b/packages/utils/src/build-operation-for-field.ts index 9077739cf0f..23b6fad89ae 100644 --- a/packages/utils/src/build-operation-for-field.ts +++ b/packages/utils/src/build-operation-for-field.ts @@ -143,7 +143,7 @@ function buildOperationAndCollectVariables({ kind: Kind.OPERATION_DEFINITION, operation: kind, name: { - kind: 'Name', + kind: Kind.NAME, value: operationName, }, variableDefinitions: [], diff --git a/packages/utils/src/print-schema-with-directives.ts b/packages/utils/src/print-schema-with-directives.ts index e35a120b182..b48154f9055 100644 --- a/packages/utils/src/print-schema-with-directives.ts +++ b/packages/utils/src/print-schema-with-directives.ts @@ -126,7 +126,7 @@ export function astFromSchema( ['query', undefined], ['mutation', undefined], ['subscription', undefined], - ]); + ] as [OperationTypeNode, OperationTypeDefinitionNode | undefined][]); const nodes: Array = []; if (schema.astNode != null) { diff --git a/packages/utils/src/rootTypes.ts b/packages/utils/src/rootTypes.ts index 21daf3f01ef..128de4cb4c9 100644 --- a/packages/utils/src/rootTypes.ts +++ b/packages/utils/src/rootTypes.ts @@ -28,17 +28,17 @@ export const getRootTypeMap = memoize1(function getRootTypeMap( const queryType = schema.getQueryType(); if (queryType) { - rootTypeMap.set('query', queryType); + rootTypeMap.set('query' as OperationTypeNode, queryType); } const mutationType = schema.getMutationType(); if (mutationType) { - rootTypeMap.set('mutation', mutationType); + rootTypeMap.set('mutation' as OperationTypeNode, mutationType); } const subscriptionType = schema.getSubscriptionType(); if (subscriptionType) { - rootTypeMap.set('subscription', subscriptionType); + rootTypeMap.set('subscription' as OperationTypeNode, subscriptionType); } return rootTypeMap; diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index f34e05dfb4b..74d94b87cad 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -1,4 +1,4 @@ -import { GraphQLEnumType, GraphQLInputObjectType, GraphQLNamedType, GraphQLScalarType } from 'graphql'; +import { GraphQLEnumType, GraphQLInputObjectType, GraphQLNamedType, GraphQLScalarType, visit } from 'graphql'; export interface SchemaPrintOptions { /** @@ -59,3 +59,6 @@ export type InputObjectValueTransformer = ( type: GraphQLInputObjectType, originalValue: Record ) => Record; + +// GraphQL v14 doesn't have it. Remove this once we drop support for v14 +export type ASTVisitorKeyMap = Partial[2]>; diff --git a/packages/utils/tests/build-operation-node-for-field.spec.ts b/packages/utils/tests/build-operation-node-for-field.spec.ts index 2349867392b..0467feb6bd6 100644 --- a/packages/utils/tests/build-operation-node-for-field.spec.ts +++ b/packages/utils/tests/build-operation-node-for-field.spec.ts @@ -1,4 +1,4 @@ -import { print, parse, buildSchema, ASTNode } from 'graphql'; +import { print, parse, buildSchema, ASTNode, OperationTypeNode } from 'graphql'; import { buildOperationNodeForField } from '../src/build-operation-for-field'; @@ -76,7 +76,7 @@ const models = ['User', 'Book']; test('should work with Query', async () => { const document = buildOperationNodeForField({ schema, - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'me', models, ignore: [], @@ -123,7 +123,7 @@ test('should work with Query', async () => { test('should work with Query and variables', async () => { const document = buildOperationNodeForField({ schema, - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'user', models, ignore: [], @@ -170,7 +170,7 @@ test('should work with Query and variables', async () => { test('should work with Query and complicated variable', async () => { const document = buildOperationNodeForField({ schema, - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'menuByIngredients', models, ignore: [], @@ -203,7 +203,7 @@ test('should work with Query and complicated variable', async () => { test('should work with Union', async () => { const document = buildOperationNodeForField({ schema, - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'menu', models, ignore: [], @@ -236,7 +236,7 @@ test('should work with Union', async () => { test('should work with mutation', async () => { const document = buildOperationNodeForField({ schema, - kind: 'mutation', + kind: 'mutation' as OperationTypeNode, field: 'addSalad', models, ignore: [], @@ -278,7 +278,7 @@ test('should work with mutation + return a field of type Query', async () => { `) const document = buildOperationNodeForField({ schema, - kind: 'mutation', + kind: 'mutation' as OperationTypeNode, field: 'addPizza', models, ignore: [], @@ -318,7 +318,7 @@ test('should work with mutation + Union + return a field of type Query', async ( `) const document = buildOperationNodeForField({ schema, - kind: 'mutation', + kind: 'mutation' as OperationTypeNode, field: 'addRandomFood', models, ignore: [], @@ -344,7 +344,7 @@ test('should work with mutation + Union + return a field of type Query', async ( test('should work with mutation and unions', async () => { const document = buildOperationNodeForField({ schema, - kind: 'mutation', + kind: 'mutation' as OperationTypeNode, field: 'addRandomFood', models, ignore: [], @@ -377,7 +377,7 @@ test('should work with mutation and unions', async () => { test('should work with Query and nested variables', async () => { const document = buildOperationNodeForField({ schema, - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'feed', models, ignore: [], @@ -397,7 +397,7 @@ test('should work with Query and nested variables', async () => { test('should be able to ignore using models when requested', async () => { const document = buildOperationNodeForField({ schema, - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'user', models, ignore: ['User.favoriteBook', 'User.shelf'], @@ -446,7 +446,7 @@ test('should be able to ignore using models when requested', async () => { test('should work with Subscription', async () => { const document = buildOperationNodeForField({ schema, - kind: 'subscription', + kind: 'subscription' as OperationTypeNode, field: 'onFood', models, ignore: [], @@ -496,7 +496,7 @@ test('should work with circular ref (default depth limit === 1)', async () => { a: A } `), - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'a', models, ignore: [], @@ -537,7 +537,7 @@ test('should work with circular ref (custom depth limit)', async () => { a: A } `), - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'a', models, ignore: [], @@ -583,7 +583,7 @@ test('arguments', async () => { users(pageInfo: PageInfoInput!): [User] } `), - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'users', models, ignore: [], @@ -605,7 +605,7 @@ test('selectedFields', async () => { const document = buildOperationNodeForField({ schema, - kind: 'query', + kind: 'query' as OperationTypeNode, field: 'user', selectedFields: { favoriteFood: { diff --git a/packages/utils/tests/mapSchema.test.ts b/packages/utils/tests/mapSchema.test.ts index abd6d241d0e..a15b1cfe99f 100644 --- a/packages/utils/tests/mapSchema.test.ts +++ b/packages/utils/tests/mapSchema.test.ts @@ -1196,7 +1196,7 @@ describe('mapSchema', () => { `, }); - const expectedResult: any = { + const expectedResult = { me: { friends: { items: [ diff --git a/packages/utils/tests/print-schema-with-directives.spec.ts b/packages/utils/tests/print-schema-with-directives.spec.ts index f8439208ac1..7d375b5f55c 100644 --- a/packages/utils/tests/print-schema-with-directives.spec.ts +++ b/packages/utils/tests/print-schema-with-directives.spec.ts @@ -119,15 +119,15 @@ describe('printSchemaWithDirectives', () => { directives: specifiedDirectives.concat([ new GraphQLDirective({ name: 'entity', - locations: ['OBJECT'], + locations: ['OBJECT'] as any[], }), new GraphQLDirective({ name: 'id', - locations: ['FIELD_DEFINITION'], + locations: ['FIELD_DEFINITION'] as any[], }), new GraphQLDirective({ name: 'link', - locations: ['FIELD_DEFINITION'], + locations: ['FIELD_DEFINITION'] as any[], }), ]), }) @@ -226,7 +226,7 @@ describe('printSchemaWithDirectives', () => { const schema = new GraphQLSchema({ directives: [new GraphQLDirective({ name: 'dummy', - locations: ['QUERY'], + locations: ['QUERY'] as any[], })] } as any); diff --git a/packages/utils/tests/visitResult.test.ts b/packages/utils/tests/visitResult.test.ts index b8c8cc533fb..8f4d51fc4c5 100644 --- a/packages/utils/tests/visitResult.test.ts +++ b/packages/utils/tests/visitResult.test.ts @@ -1,6 +1,6 @@ -import { buildSchema, parse, GraphQLError } from 'graphql'; +import { buildSchema, parse, GraphQLError, OperationTypeNode } from 'graphql'; -import { ExecutionResult } from '@graphql-tools/utils'; +import { ExecutionRequest, ExecutionResult } from '@graphql-tools/utils'; import { relocatedError } from '../src/errors'; @@ -19,10 +19,10 @@ describe('visiting results', () => { } `); - const request = { + const request: ExecutionRequest = { document: parse('{ test { field } }'), variables: {}, - operationType: 'query' as const + operationType: 'query' as OperationTypeNode }; it('should visit without throwing', async () => { @@ -47,7 +47,7 @@ describe('visiting results', () => { const introspectionRequest = { document: parse('{ test { field __typename } }'), variables: {}, - operationType: 'query' as const + operationType: 'query' as OperationTypeNode }; const result = { data: { @@ -218,7 +218,7 @@ describe('visiting nested results', () => { } `); - const request = { + const request: ExecutionRequest = { document: parse(/* GraphQL */`{ userGroups { name @@ -228,7 +228,7 @@ describe('visiting nested results', () => { } }`), variables: {}, - operationType: 'query' as const, + operationType: 'query' as OperationTypeNode, }; it('should work', async () => { @@ -286,7 +286,7 @@ describe('visiting nested results', () => { } `); - const request = { + const request: ExecutionRequest = { document: parse(/* GraphQL */`{ userGroups { name @@ -296,7 +296,7 @@ describe('visiting nested results', () => { } }`), variables: {}, - operationType: 'query' as const, + operationType: 'query' as OperationTypeNode, }; it('should work', async () => { @@ -353,10 +353,10 @@ describe('visiting errors', () => { } `); - const request = { + const request: ExecutionRequest = { document: parse('{ test { field } }'), variables: {}, - operationType: 'query' as const, + operationType: 'query' as OperationTypeNode, }; it('should allow visiting without an errorVisitor', async () => { diff --git a/packages/wrap/src/introspect.ts b/packages/wrap/src/introspect.ts index b0130db1501..d3e0f01305f 100644 --- a/packages/wrap/src/introspect.ts +++ b/packages/wrap/src/introspect.ts @@ -6,6 +6,7 @@ import { IntrospectionOptions, IntrospectionQuery, ParseOptions, + OperationTypeNode, } from 'graphql'; import { ValueOrPromise } from 'value-or-promise'; @@ -56,7 +57,7 @@ export function introspectSchema( return new ValueOrPromise(() => executor({ document: parsedIntrospectionQuery, - operationType: 'query', + operationType: 'query' as OperationTypeNode, context, }) ) diff --git a/packages/wrap/src/transforms/HoistField.ts b/packages/wrap/src/transforms/HoistField.ts index c94590c753a..3f58b8db1b4 100644 --- a/packages/wrap/src/transforms/HoistField.ts +++ b/packages/wrap/src/transforms/HoistField.ts @@ -7,6 +7,7 @@ import { GraphQLError, GraphQLArgument, GraphQLFieldResolver, + OperationTypeNode, } from 'graphql'; import { @@ -112,7 +113,7 @@ export default class HoistField implements Transform { resolve = createProxyingResolver({ subschemaConfig, transformedSchema, - operation, + operation: operation as OperationTypeNode, fieldName: this.newFieldName, }); } else { diff --git a/packages/wrap/src/transforms/WrapFields.ts b/packages/wrap/src/transforms/WrapFields.ts index a6766ff128e..7f2aa0dcd02 100644 --- a/packages/wrap/src/transforms/WrapFields.ts +++ b/packages/wrap/src/transforms/WrapFields.ts @@ -9,6 +9,7 @@ import { GraphQLFieldConfigMap, GraphQLFieldConfig, GraphQLFieldResolver, + OperationTypeNode, } from 'graphql'; import { @@ -134,7 +135,7 @@ export default class WrapFields implements Transform { test('should create requests', () => { const request = removeLocations( createRequest({ - targetOperation: 'query', + targetOperation: 'query' as OperationTypeNode, targetFieldName: 'version', selectionSet: parseSelectionSet(`{ major diff --git a/packages/wrap/tests/transformWrapQuery.test.ts b/packages/wrap/tests/transformWrapQuery.test.ts index 67a6db1b980..0cb596ea03a 100644 --- a/packages/wrap/tests/transformWrapQuery.test.ts +++ b/packages/wrap/tests/transformWrapQuery.test.ts @@ -1,4 +1,4 @@ -import { execute, GraphQLSchema, Kind, parse, SelectionSetNode } from 'graphql'; +import { execute, GraphQLSchema, Kind, OperationTypeNode, parse, SelectionSetNode } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; import { WrapQuery } from '@graphql-tools/wrap'; import { delegateToSchema } from '@graphql-tools/delegate'; @@ -56,7 +56,7 @@ describe('WrapQuery', () => { addressByUser(_parent, { id }, context, info) { return delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'userById', args: { id }, context, @@ -67,7 +67,7 @@ describe('WrapQuery', () => { // path at which to apply wrapping and extracting ['userById'], (subtree: SelectionSetNode) => { - const newSelectionSet = { + const newSelectionSet: SelectionSetNode = { kind: Kind.SELECTION_SET, selections: subtree.selections.map((selection) => { // just append fragments, not interesting for this diff --git a/packages/wrap/tests/transforms.test.ts b/packages/wrap/tests/transforms.test.ts index b49e89e9010..416e553fd7a 100644 --- a/packages/wrap/tests/transforms.test.ts +++ b/packages/wrap/tests/transforms.test.ts @@ -4,6 +4,8 @@ import { Kind, SelectionSetNode, graphql, + OperationTypeNode, + GraphQLError, } from 'graphql'; import { makeExecutableSchema } from '@graphql-tools/schema'; @@ -260,7 +262,7 @@ describe('transforms', () => { addressByUser(_parent, { id }, context, info) { return delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'userById', args: { id }, context, @@ -292,7 +294,7 @@ describe('transforms', () => { async setUserAndAddress(_parent, { input }, context, info) { const addressResult = await delegateToSchema({ schema: subschema, - operation: 'mutation', + operation: 'mutation' as OperationTypeNode, fieldName: 'setAddress', args: { input: { @@ -314,7 +316,7 @@ describe('transforms', () => { }); const userResult = await delegateToSchema({ schema: subschema, - operation: 'mutation', + operation: 'mutation' as OperationTypeNode, fieldName: 'setUser', args: { input: { @@ -508,7 +510,7 @@ describe('transforms', () => { addressByUser(_parent, { id }, context, info) { return delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'userById', args: { id }, context, @@ -544,7 +546,7 @@ describe('transforms', () => { addressesByUsers(_parent, { ids }, context, info) { return delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'usersByIds', args: { ids }, context, @@ -578,7 +580,7 @@ describe('transforms', () => { errorTest(_parent, { id }, context, info) { return delegateToSchema({ schema: subschema, - operation: 'query', + operation: 'query' as OperationTypeNode, fieldName: 'userById', args: { id }, context, @@ -653,16 +655,7 @@ describe('transforms', () => { }, }, errors: [ - { - locations: [ - { - column: 15, - line: 4, - }, - ], - message: 'Test Error!', - path: ['addressByUser', 'errorTest'], - }, + new GraphQLError('Test Error!', undefined, undefined, [15, 4], ['addressByUser', 'errorTest']), ], }); });