Hi, I m testing our Apollo graphql to use the managed federation, but I cant seem to find a way to pass in buildService(definition: ServiceEndpointDefinition)
into the gateway’s option as the doc mentioned that we just have to initialize the gateway const gateway = new ApolloGateway()
without any options and it will detect that we are using managed federation.
Old Code:
class AuthenticatedDataSource extends RemoteGraphQLDataSource {
willSendRequest({ request, context }: any) {
const { authentication, authorization, environment, instance, operationName } = context;
request.http!.headers.set('authentication', authentication);
request.http!.headers.set('authorization', authorization);
request.http!.headers.set('environment', environment);
request.http!.headers.set('instance', instance);
request.http!.headers.set('operationName', operationName);
request.http!.headers.set('traceId', uid());
request.http!.headers.set(
'x-correlation-id',
context['x-correlation-id'] === undefined ? 'polling' : context['x-correlation-id'],
);
}
}
const gateway = new ApolloGateway({
buildService(definition: ServiceEndpointDefinition) {
const { url } = definition;
return new AuthenticatedDataSource({ url });
},
experimental_updateSupergraphSdl: async () => {
const supergraphSdl = readFileSync('./supergraph.graphql').toString();
return {
id: new Date().toISOString(),
supergraphSdl,
};
},
});