-
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
Support gateways without executors #5539
Conversation
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.
dd72998
to
443c2ff
Compare
Hi @glasser - do you happen to have a complete example you can share? I've spent quite some time this morning and haven't had any success. I've followed the above fragment you shared, but any queries are still returning |
@setchy I'll admit I threw the above together pretty quickly... I'm pretty sure I tested it though! Can you show me a codesandbox or repo demonstrating that it doesn't work with AS 3.1? (FYI I'm on and off vacation the next few weeks.) |
No problems at all @glasser - decent chance its my user error 😅 Here is a stripped down minimal recreation - https://github.com/setchy/apollo-server-3-mocked-federation Enjoy your vacation! 😎 |
Ah @setchy, here's what's going on. After some recent refactors (which introduced onSchemaLoadOrUpdate), the So it looks like this works: const gateway: GatewayInterface = {
async load(options) {
await realGateway.load(options);
return {
schema: null,
executor: null,
};
},
stop() {
return realGateway.stop();
},
onSchemaLoadOrUpdate(callback) {
return realGateway.onSchemaLoadOrUpdate((schemaContext) => {
callback({
...schemaContext,
apiSchema: addMocksToSchema({ schema: schemaContext.apiSchema, mocks }),
});
});
},
}; (If returning I've updated the PR description to show the new code. |
Awesome, this is working like a treat! Thank you @glasser 👏 I've updated my sample repo with the above, too |
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:
to define a server that follows a managed federation graph but executes
queries using mocking.