useFederation plugin with Apollo managed federation #1040
BorisPetelj
started this conversation in
General
Replies: 1 comment 1 reply
-
You don't call and wait for And you don't follow our example for Apollo Server; import { envelop, } from '@envelop/core';
import { ApolloGateway } from '@apollo/gateway';
import { useApolloFederation } from '@envelop/apollo-federation';
import { ApolloServer } from 'apollo-server';
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
async function main() {
// Initialize the gateway
const gateway = new ApolloGateway({
serviceList: [
{ name: 'accounts', url: 'http://localhost:4001' },
{ name: 'products', url: 'http://localhost:4002' },
// ...additional subgraphs...
],
});
// Make sure all services are loaded
await gateway.load();
// Then pass it to the plugin configuration
const getEnveloped = envelop({
plugins: [
// ... other plugins ...
useApolloFederation({ gateway }),
],
});
const server = new ApolloServer({
schema,
executor: async requestContext => {
const { schema, execute, contextFactory } = getEnveloped({ req: requestContext.request.http });
return execute({
schema: schema,
document: requestContext.document,
contextValue: await contextFactory(),
variableValues: requestContext.request.variables,
operationName: requestContext.operationName,
});
},
plugins: [ApolloServerPluginLandingPageGraphQLPlayground({ endpoint: '/graphql' })],
});
server.listen(3000);
}
main().catch(e => {
console.error(e);
process.exit(1);
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, useFederation plugin requires the ApolloGateway instance with an already loaded schemas. This can be explicitly done by calling
gateway.load()
In case of managed federation, schema loading is done implicit in ApolloServer which requires gateway instance in constructor.
There is no way to pass the initialized gateway (with fetched schemas to ApolloServer) to envelop.
I ended up with this:
In this case, there is getEnveloped creation on every request. Do you have any suggestions or plan to support the usage of Envelop with ApolloGateway in managed federation mode?
Beta Was this translation helpful? Give feedback.
All reactions