-
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.
Add tests for overrideReportedSchema
- Loading branch information
1 parent
c29fbce
commit f645699
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
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."`, | ||
); | ||
}); | ||
}); |