Apollo Gateway Directives Plugin
This plugin allows you to handle GraphQL directives within Apollo Gateway.
Installation
pnpm add @labdigital/apollo-gateway-directives
Usage
import { GatewayDirectivesPlugin } from '@labdigital/apollo-gateway-directives';
import type { BaseContext } from "@apollo/server";
import { buildSchema } from "graphql";
type ContextValue extends BaseContext {
foobar: string;
}
const directivesPlugin = new GatewayDirectivesPlugin<ContextValue>({
myDirective: async (
args: Record<string, unknown>,
context: ContextValue,
) => {
}
});
const gateway = new ApolloGateway({
});
gateway.onSchemaLoadOrUpdate((schema) => {
const sdl = buildSchema(schema.coreSupergraphSdl);
directivesPlugin.parseSchema(sdl);
});
const server = new ApolloServer({
gateway,
plugins: [
directivesPlugin,
]
});
await server.start();