Skip to content

Commit

Permalink
schema-reporting: Fix error message whitespace, add tests for overrid…
Browse files Browse the repository at this point in the history
…eReportedSchema (#4581)

This PR adds testing for `overrideReportedSchema` for unparsable/invalid schemas, and fixes a typo in the error message where a space was missing.
  • Loading branch information
sachindshinde committed Sep 22, 2020
1 parent 1af2792 commit 72cd117
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The version headers in this history reflect the versions of Apollo Server itself

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. With few exceptions, the format of the entry should follow convention (i.e., prefix with package name, use markdown `backtick formatting` for package names and code, suffix with a link to the change-set à la `[PR #YYY](https://link/pull/YYY)`, etc.). When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- `apollo-server-core`: Fix typo in error message for unparsable/invalid schemas provided via `overrideReportedSchema`. [PR #4581](https://github.com/apollographql/apollo-server/pull/4581)

## v2.18.0

- `apollo-server-core`: When Apollo Server is configured with an Apollo API key, the URLs it uses to connect to Apollo's servers have changed. If the environment in which you run your servers requires you to explicitly allow connections by domain, you will need to add the new domain names. Usage reporting previously connected to https://engine-report.apollodata.com/ and now connects to https://usage-reporting.api.apollographql.com/; schema reporting previously connected to https://edge-server-reporting.api.apollographql.com/ and now connects to https://schema-reporting.api.apollographql.com/ . [PR #4453](https://github.com/apollographql/apollo-server/pull/4453)
Expand Down
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."`,
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function ApolloServerPluginSchemaReporting(
}
} catch (err) {
throw new Error(
'The schema provided to overrideReportedSchema failed to parse or' +
'The schema provided to overrideReportedSchema failed to parse or ' +
`validate: ${err.message}`,
);
}
Expand Down

0 comments on commit 72cd117

Please sign in to comment.