Remove Apollo Graphql Schema Directives while migrating from v2 to v3 or v4

JavaScript pattern

The 'schemaDirectives' option in Apollo GraphQL, which was effective in ApolloServer version v2, no longer functions in versions >=3 and above. This change can have significant implications, potentially exposing authenticated endpoints, disabling rate limiting, and more, depending on the directives used. To address this, it is recommended to consult the references on creating custom directives specifically for ApolloServer versions v3 and v4.

references


Apply with the Grit CLI
grit apply remove_apollo_graphql_schema_directives_for_v3_v4

Apollo Graphql Schema Directives while migrating from v2 to v3 or v4

BEFORE
// BAD: Has 'schemaDirectives'
const apollo_server_1 = new ApolloServer({
    typeDefs,
    resolvers,
    schemaDirectives: {
        rateLimit: rateLimitDirective
    },
});

// Good: Does not have 'schemaDirectives'
const apollo_server_3 = new ApolloServer({
    typeDefs,
    resolvers,
});
AFTER
// BAD: Has 'schemaDirectives'
const apollo_server_1 = new ApolloServer({
    typeDefs,
    resolvers,
    
});

// Good: Does not have 'schemaDirectives'
const apollo_server_3 = new ApolloServer({
    typeDefs,
    resolvers,
});