Skip to content

Commit

Permalink
Remove unnecessary print and subsequent parse (#678)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Fix authored and freiksenet committed Mar 16, 2018
1 parent 42c7296 commit c91e577
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
8 changes: 5 additions & 3 deletions src/stitching/introspectSchema.ts
Original file line number Diff line number Diff line change
@@ -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 },
Expand All @@ -14,7 +16,7 @@ export default async function introspectSchema(
}

const introspectionResult = await (fetcher as Fetcher)({
query: introspectionQuery,
query: parsedIntrospectionQuery,
context: linkContext,
});

Expand Down
8 changes: 1 addition & 7 deletions src/stitching/linkToFetcher.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { parse } from 'graphql';
import { Fetcher, FetcherOperation } from './makeRemoteExecutableSchema';

import {
Expand All @@ -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));
};
}
6 changes: 3 additions & 3 deletions src/stitching/makeRemoteExecutableSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -41,7 +41,7 @@ export type ResolverFn = (
export type Fetcher = (operation: FetcherOperation) => Promise<ExecutionResult>;

export type FetcherOperation = {
query: string;
query: DocumentNode;
operationName?: string;
variables?: { [key: string]: any };
context?: { [key: string]: any };
Expand Down Expand Up @@ -161,7 +161,7 @@ function createResolver(fetcher: Fetcher): GraphQLFieldResolver<any, any> {
definitions: [info.operation, ...fragments],
};
const result = await fetcher({
query: print(document),
query: document,
variables: info.variableValues,
context: { graphqlContext: context },
});
Expand Down
2 changes: 1 addition & 1 deletion src/test/testingSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit c91e577

Please sign in to comment.