Skip to content

Commit

Permalink
Add tests for overrideReportedSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
sachindshinde committed Sep 22, 2020
1 parent 97f3667 commit 93c929a
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import {
ApolloServerPluginSchemaReporting,
ApolloServerPluginSchemaReportingOptions,
} from '..';
import pluginTestHarness from 'apollo-server-core/dist/utils/pluginTestHarness';
import { makeExecutableSchema } from 'graphql-tools';
import { graphql } from 'graphql';

describe('end-to-end', () => {
async function runTest({
pluginOptions = {},
}: {
pluginOptions?: ApolloServerPluginSchemaReportingOptions;
}) {
return await pluginTestHarness({
pluginInstance: ApolloServerPluginSchemaReporting(pluginOptions),
graphqlRequest: {
query: 'query { __typename }',
},
executor: async ({ request: { query }, context }) => {
return await graphql({
schema: makeExecutableSchema({ typeDefs: 'type Query { foo: Int }' }),
source: query,
// context is needed for schema instrumentation to find plugins.
contextValue: context,
});
},
});
}

it('fails for unparsable overrideReportedSchema', async () => {
await expect(
runTest({
pluginOptions: {
overrideReportedSchema: 'type Query {',
},
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"The schema provided to overrideReportedSchema failed to parse or validate: Syntax Error: Expected Name, found <EOF>"`,
);
});

it('fails for invalid overrideReportedSchema', async () => {
await expect(
runTest({
pluginOptions: {
overrideReportedSchema: 'type Query',
},
}),
).rejects.toThrowErrorMatchingInlineSnapshot(
`"The schema provided to overrideReportedSchema failed to parse or validate: Type Query must define one or more fields."`,
);
});
});

0 comments on commit 93c929a

Please sign in to comment.