-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Make it easier to mock execution of a managed federation schema #5518
Labels
size/small
Estimated to take LESS THAN A DAY
Comments
glasser
changed the title
Investigate reported regression in mocking federated schema in AS3
Make it easier to mock execution of a managed federation schema
Jul 23, 2021
glasser
added a commit
that referenced
this issue
Jul 23, 2021
Previously gateways could express their executor in two ways: as the executor method (required to exist!) and as part of the return value from load (which was ignored!). Now we just return it from load, and allow it to be null. This supports a mocking use case. Fixes #5518. It lets you do something like: import { addMocksToSchema } from '@graphql-tools/mock'; const realGateway = new ApolloGateway(); const gateway: GatewayInterface = { async load(options) { const { schema } = await realGateway.load(options); return { schema: addMocksToSchema({ schema }), executor: null, }; } stop() { return realGateway.stop(); } onSchemaLoadOrUpdate(callback) { return realGateway.onSchemaLoadOrUpdate(callback); } }; const server = new ApolloServer({ gateway }); to define a server that follows a managed federation graph but executes queries using mocking.
glasser
added a commit
that referenced
this issue
Jul 23, 2021
Previously gateways could express their executor in two ways: as the executor method (required to exist!) and as part of the return value from load (which was ignored!). Now we just return it from load, and allow it to be null. This supports a mocking use case. Fixes #5518. It lets you do something like: import { addMocksToSchema } from '@graphql-tools/mock'; const realGateway = new ApolloGateway(); const gateway: GatewayInterface = { async load(options) { const { schema } = await realGateway.load(options); return { schema: addMocksToSchema({ schema }), executor: null, }; } stop() { return realGateway.stop(); } onSchemaLoadOrUpdate(callback) { return realGateway.onSchemaLoadOrUpdate(callback); } }; const server = new ApolloServer({ gateway }); to define a server that follows a managed federation graph but executes queries using mocking.
glasser
added a commit
that referenced
this issue
Jul 23, 2021
Previously gateways could express their executor in two ways: as the executor method (required to exist!) and as part of the return value from load (which was ignored!). Now we just return it from load, and allow it to be null. This supports a mocking use case. Fixes #5518. It lets you do something like: import { addMocksToSchema } from '@graphql-tools/mock'; const realGateway = new ApolloGateway(); const gateway: GatewayInterface = { async load(options) { const { schema } = await realGateway.load(options); return { schema: addMocksToSchema({ schema }), executor: null, }; } stop() { return realGateway.stop(); } onSchemaLoadOrUpdate(callback) { return realGateway.onSchemaLoadOrUpdate(callback); } }; const server = new ApolloServer({ gateway }); to define a server that follows a managed federation graph but executes queries using mocking.
glasser
added a commit
that referenced
this issue
Jul 23, 2021
Previously gateways could express their executor in two ways: as the executor method (required to exist!) and as part of the return value from load (which was ignored!). Now we just return it from load, and allow it to be null. This supports a mocking use case. Fixes #5518. It lets you do something like: import { addMocksToSchema } from '@graphql-tools/mock'; const realGateway = new ApolloGateway(); const gateway: GatewayInterface = { async load(options) { const { schema } = await realGateway.load(options); return { schema: addMocksToSchema({ schema }), executor: null, }; } stop() { return realGateway.stop(); } onSchemaLoadOrUpdate(callback) { return realGateway.onSchemaLoadOrUpdate(callback); } }; const server = new ApolloServer({ gateway }); to define a server that follows a managed federation graph but executes queries using mocking.
Fixed on release-3.1.0. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The GatewayInterface does two things: it watches a possibly changing schema, and it replaces the executor. There's a use case for running an ApolloServer with a managed federation schema where we want a GatewayInterface implementation that wraps the real ApolloGateway to load and watch the schema, but still uses normal GraphQL execution (using mocks). Let's support that explicitly.
See #5507. cc @setchy
The text was updated successfully, but these errors were encountered: