diff --git a/src/stitching/introspectSchema.ts b/src/stitching/introspectSchema.ts index d32b7628318..63c77e443ee 100644 --- a/src/stitching/introspectSchema.ts +++ b/src/stitching/introspectSchema.ts @@ -1,9 +1,11 @@ -import { GraphQLSchema } from 'graphql'; -import { introspectionQuery, buildClientSchema } from 'graphql'; +import { GraphQLSchema, DocumentNode } from 'graphql'; +import { introspectionQuery, buildClientSchema, parse } from 'graphql'; import { ApolloLink } from 'apollo-link'; import { Fetcher } from './makeRemoteExecutableSchema'; import linkToFetcher from './linkToFetcher'; +const parsedIntrospectionQuery: DocumentNode = parse(introspectionQuery); + export default async function introspectSchema( fetcher: ApolloLink | Fetcher, linkContext?: { [key: string]: any }, @@ -14,7 +16,7 @@ export default async function introspectSchema( } const introspectionResult = await (fetcher as Fetcher)({ - query: introspectionQuery, + query: parsedIntrospectionQuery, context: linkContext, }); diff --git a/src/stitching/linkToFetcher.ts b/src/stitching/linkToFetcher.ts index f309697e51c..cf9e7b5437b 100644 --- a/src/stitching/linkToFetcher.ts +++ b/src/stitching/linkToFetcher.ts @@ -1,4 +1,3 @@ -import { parse } from 'graphql'; import { Fetcher, FetcherOperation } from './makeRemoteExecutableSchema'; import { @@ -11,11 +10,6 @@ export { execute } from 'apollo-link'; export default function linkToFetcher(link: ApolloLink): Fetcher { return (fetcherOperation: FetcherOperation) => { - const linkOperation = { - ...fetcherOperation, - query: parse(fetcherOperation.query), - }; - - return makePromise(execute(link, linkOperation)); + return makePromise(execute(link, fetcherOperation)); }; } diff --git a/src/stitching/makeRemoteExecutableSchema.ts b/src/stitching/makeRemoteExecutableSchema.ts index 29ec6b8889c..3679b7afd41 100644 --- a/src/stitching/makeRemoteExecutableSchema.ts +++ b/src/stitching/makeRemoteExecutableSchema.ts @@ -15,12 +15,12 @@ import { GraphQLInt, GraphQLScalarType, ExecutionResult, - print, buildSchema, printSchema, Kind, ValueNode, GraphQLResolveInfo, + DocumentNode } from 'graphql'; import linkToFetcher, { execute } from './linkToFetcher'; import isEmptyObject from '../isEmptyObject'; @@ -41,7 +41,7 @@ export type ResolverFn = ( export type Fetcher = (operation: FetcherOperation) => Promise; export type FetcherOperation = { - query: string; + query: DocumentNode; operationName?: string; variables?: { [key: string]: any }; context?: { [key: string]: any }; @@ -161,7 +161,7 @@ function createResolver(fetcher: Fetcher): GraphQLFieldResolver { definitions: [info.operation, ...fragments], }; const result = await fetcher({ - query: print(document), + query: document, variables: info.variableValues, context: { graphqlContext: context }, }); diff --git a/src/test/testingSchemas.ts b/src/test/testingSchemas.ts index fceedbcc79f..0d8e3f366ed 100644 --- a/src/test/testingSchemas.ts +++ b/src/test/testingSchemas.ts @@ -730,7 +730,7 @@ export async function makeSchemaRemoteFromLink(schema: GraphQLSchema) { // ensure fetcher support exists from the 2.0 api async function makeExecutableSchemaFromFetcher(schema: GraphQLSchema) { const fetcher: Fetcher = ({ query, operationName, variables, context }) => { - return graphql(schema, query, null, context, variables, operationName); + return graphql(schema, print(query), null, context, variables, operationName); }; const clientSchema = await introspectSchema(fetcher);