Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary print and subsequent parse #678

Merged
merged 3 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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