2
const { SchemaDirectiveVisitor } = require('apollo-server-express');

class ReplaceDirective extends SchemaDirectiveVisitor {
visitFieldDefinition(field) {
    const { replacement } = this.args;
    field.resolve = () => {
        return replacement
    }
}
}

module.exports = Object.freeze({ ReplaceDirective })

The Error I am getting is following TypeError: Class extends value undefined is not a constructor or null

Vipul
  • 75
  • 4

2 Answers2

2

Looking at the apollo-server/packages/apollo-server-express/src/index.ts, that function is not exposed.

SchemaDirectiveVisitor is a legacy function from graphql-tools.

apollo-server-express@2.X.X (last v2.25.2) used graphql-tools 4.0.8 which still had that function.

You'll need to pin to a v2 version of apollo-server-express to make use of that function.

Manny
  • 369
  • 2
  • 7
  • 2
    Thanks Manny, but I'd like to stick with the latest version. How can I make custom directives in the latest version. – Vipul Jul 26 '21 at 16:39
1

They got rid of the SchemaDirectiveVisitor and added two new functions to simplify: mapSchema and getDirectives.

Source: https://www.the-guild.dev/blog/graphql-tools-v6 Then scroll to the following title. Modify Schemas with Directives

Mahdi Zarei
  • 5,644
  • 7
  • 24
  • 54
Antonio
  • 63
  • 5