Extend SchemaDirectiveVisitor To Use Apollo Server Schema Directives in NodeJS

0 votes

In Apollo Server 2, I'm attempting to extend SchemaDirectiveVisitor in order to create a custom directive. I'm specifically using the 2.2.6 hapi node module.

My server.js code is as follows:

const { ApolloServer } = require('apollo-server-hapi');
const { SchemaDirectiveVisitor } = ApolloServer;

class ViewTemplateGroup extends SchemaDirectiveVisitor {
  visitFieldDefinition(field) {
    console.log('Im calling this directive!');
    return;
  }
}

When I start up my server I immediately get the following error:

TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (/Users/garrett.kim/Desktop/Projects/Test Web/poc-graphQL-forms-gyk/server.js:36:33)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)
    at Function.Module._load (module.js:505:3)
    at Function.Module.runMain (module.js:701:10)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:617:3

To my knowledge, I'm following the Apollo Server 2 example very closely.

Any assistance in getting commands to work would be greatly appreciated.

Jun 16 in Node-js by Vaani
• 6,820 points
7 views

1 answer to this question.

0 votes

Because the ApolloServer class lacks a SchemaDirectiveVisitor property, calling ApolloServer fails. As the problem implies, SchemaDirectiveVisitor returns undefined, therefore a class cannot extend undefined. Simply use the apollo-server-hapi module to import SchemaDirectiveVisitor:

const { ApolloServer, SchemaDirectiveVisitor } = require('apollo-server-hapi')
answered Jun 17 by Neha
• 8,560 points

Related Questions In Node-js

0 votes
1 answer

Making POST request to discord server in nodejs

You'll need to solve the captchas; I ...READ MORE

answered May 30 in Node-js by Vaani
• 6,820 points
15 views
0 votes
1 answer

How to use executables from a package installed locally in node_modules?

Hello @kartik, Use the npm bin command to get the ...READ MORE

answered Jul 13, 2020 in Node-js by Niroj
• 82,720 points
522 views
0 votes
1 answer

How to create an HTTPS server in Node.js?

Hello @kartik, The minimal setup for an HTTPS ...READ MORE

answered Jul 13, 2020 in Node-js by Niroj
• 82,720 points
723 views
0 votes
1 answer

How to get access to webpack-dev-server from devices in local network?

Hello @kartik, You can set your ip address ...READ MORE

answered Jul 17, 2020 in Node-js by Niroj
• 82,720 points
3,606 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
962 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

How to use pino-transport in nodejs for logs?

Ensure that you have a recent version ...READ MORE

answered Jun 9 in Node-js by Neha
• 8,560 points
37 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP