cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

GraphQL API ReferenceError: resolvers is not defined

I am following along with the Full Stack GraphQL Book Club. In Chapter 4: The Neo4j GraphQL Library, we are setting up GraphQL API to work with Neo4j. The code given is the class works.  However, when I try changing to match my data schema I just get errors.

 

 

 

const { ApolloServer } = require("apollo-server");
const neo4j = require("neo4j-driver");
const { Neo4jGraphQL } = require("@neo4j/graphql");

const typeDefs = /* GraphQL */ `
const Language {
  languageId:ID!
  name:String!
  wordWall: [WordWall] @relationship(type: "IN_LANGUAGE", direction: IN)
}
type WordWall {
    wordWallID: ID!
    name: String!
    language: Language! @relationship(type: "IN_LANGUAGE", direction: OUT)
  }
`;

const driver = neo4j.driver(
  "neo4j+s://########.databases.neo4j.io",
  neo4j.auth.basic("neo4j", "****************")
);

const neoSchema = new Neo4jGraphQL({ typeDefs, resolvers, driver });

neoSchema.getSchema().then((schema) => {
  const server = new ApolloServer({
    schema,
  });
  server.listen().then(({ url }) => {
    console.log(`GraphQL server ready at ${url}`);
  });
});

 

 

error:

/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/index.js:23
const neoSchema = new Neo4jGraphQL({ typeDefs, resolvers, driver });
^

ReferenceError: resolvers is not defined
at Object.<anonymous> (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/index.js:23:48)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
[nodemon] app crashed - waiting for file changes before starting...

 

From what I understand from the class and the book this should be all that is need. Am I misunderstanding? what am I missing?

@William_Lyon  #GrandStack #GraphQL #ApolloServer #Neo4jGraphQL

 

 

2 ACCEPTED SOLUTIONS

William_Lyon
Graph Fellow

Hi @Seraphits - the error looks to be caused by line 23 in the snippet you posted:

const neoSchema = new Neo4jGraphQL({ typeDefs, resolvers, driver });

The resolvers variable is not defined in your snippet. This variable was used in the book code as an example of passing a resolver map (an object that contained manually implemented resolver functions), however, it looks like you don't need that here. Could you try removing the reference to resolvers and see if that works (passing just the driver and typeDefs):

const neoschema = new Neo4jGraphQL({typeDefs, driver})

 

View solution in original post

The error is in your GraphQL type definitions. There's a const at the beginning that doesn't belong:

const Language {
  languageId:ID!
  name:String!
  wordWall: [WordWall] @relationship(type: "IN_LANGUAGE", direction: IN)
}
type WordWall {
    wordWallID: ID!
    name: String!
    language: Language! @relationship(type: "IN_LANGUAGE", direction: OUT)
  }

 

View solution in original post

3 REPLIES 3

William_Lyon
Graph Fellow

Hi @Seraphits - the error looks to be caused by line 23 in the snippet you posted:

const neoSchema = new Neo4jGraphQL({ typeDefs, resolvers, driver });

The resolvers variable is not defined in your snippet. This variable was used in the book code as an example of passing a resolver map (an object that contained manually implemented resolver functions), however, it looks like you don't need that here. Could you try removing the reference to resolvers and see if that works (passing just the driver and typeDefs):

const neoschema = new Neo4jGraphQL({typeDefs, driver})

 

@William_Lyon

Thanks That worked for that error.    

Now I am getting a new error. 

/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/graphql/error/syntaxError.js:15
return new _GraphQLError.GraphQLError(`Syntax Error: ${description}`, {

 

What ${description}`  is the error talking about? 

And What do I do?

 


^

GraphQLError: Syntax Error: Unexpected Name "const".
at syntaxError (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/graphql/error/syntaxError.js:15:10)
at Parser.unexpected (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/graphql/language/parser.js:1458:41)
at Parser.parseDefinition (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/graphql/language/parser.js:212:16)
at Parser.many (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/graphql/language/parser.js:1511:26)
at Parser.parseDocument (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/graphql/language/parser.js:122:25)
at parse (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/graphql/language/parser.js:32:17)
at visitTypeSources (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/@neo4j/graphql/node_modules/@graphql-tools/merge/cjs/typedefs-mergers/merge-typedefs.js:48:54)
at mergeGraphQLTypes (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/@neo4j/graphql/node_modules/@graphql-tools/merge/cjs/typedefs-mergers/merge-typedefs.js:66:22)
at mergeTypeDefs (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/@neo4j/graphql/node_modules/@graphql-tools/merge/cjs/typedefs-mergers/merge-typedefs.js:13:22)
at getDocument (/Users/seraphitssingh/Documents/GitHub/Neo4jAPI/node_modules/@neo4j/graphql/dist/schema/get-document.js:24:38) {
path: undefined,
locations: [ { line: 2, column: 1 } ],
extensions: [Object: null prototype] {}

The error is in your GraphQL type definitions. There's a const at the beginning that doesn't belong:

const Language {
  languageId:ID!
  name:String!
  wordWall: [WordWall] @relationship(type: "IN_LANGUAGE", direction: IN)
}
type WordWall {
    wordWallID: ID!
    name: String!
    language: Language! @relationship(type: "IN_LANGUAGE", direction: OUT)
  }