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, 2022 in Node-js by Vaani
• 7,070 points
857 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')

To know more about Node JS, It's recommended to join Node JS Certification today.

answered Jun 17, 2022 by Neha
• 9,020 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, 2022 in Node-js by Vaani
• 7,070 points
1,233 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,840 points
1,554 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,840 points
1,882 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,840 points
6,106 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
1,927 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,455 views
0 votes
1 answer

What is the role of Nodejs and Express in a MERN stack web application when GraphQL is also used?

Node.js is a JavaScript runtime environment, which ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
2,642 views
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, 2022 in Node-js by Neha
• 9,020 points
5,229 views
0 votes
1 answer

How to schedule a google meet and get the meet link in NodeJs?

To create a Google Meet, you'll need ...READ MORE

answered May 27, 2022 in Node-js by Neha
• 9,020 points
3,878 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP