-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schema-reporting: Fix error message whitespace, add tests for overrid…
…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
1 parent
1af2792
commit 72cd117
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
packages/apollo-server-core/src/plugin/schemaReporting/__tests__/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."`, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters