0

I can see the generated query in my vscode terminal with debugging turned on: DEBUG=@neo4j/graphql:* node index2.js

@neo4j/graphql:execute About to execute Cypher:
Cypher:
MATCH (this:`Business`)
RETURN this { .name } AS this
Params:
{} +45ms
  @neo4j/graphql:execute Execute successful, received 0 records +0ms

As you can see no results are returned. However, if I run the exact same query inside the neo4j browser I receive the expected results

╒═════════════════════════════════╕
│this                             │
╞═════════════════════════════════╡
│{name: "Market on Front"}        │
├─────────────────────────────────┤
│{name: "Hanabi"}                 │
├─────────────────────────────────┤
│{name: "Zootown Brew"}           │
├─────────────────────────────────┤
│{name: "Missoula Public Library"}│
├─────────────────────────────────┤
│{name: "Ninja Mike's"}           │
├─────────────────────────────────┤
│{name: "KettleHouse Brewing Co."}│
├─────────────────────────────────┤
│{name: "Imagine Nation Brewing"} │
├─────────────────────────────────┤
│{name: "Ducky's Car Wash"}       │
├─────────────────────────────────┤
│{name: "Neo4j"}                  │
└─────────────────────────────────┘

The code below is almost exactly copy/pasted from this github repo with the exception of upgrading from apollo-server to @apollo/server

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

const resolvers = {
  Business: {
    waitTime: (obj, args, context, info) => {
      var options = [0, 5, 10, 15, 30, 45];
      return options[Math.floor(Math.random() * options.length)];
    },
  },
};

const typeDefs = /* GraphQL */ `
  type Query {
    fuzzyBusinessByName(searchString: String): [Business!]!
      @cypher(
        statement: """
        CALL db.index.fulltext.queryNodes( 'businessNameIndex', $searchString+'~')
        YIELD node RETURN node
        """
      )
  }

  type Business {
    businessId: ID!
    waitTime: Int! @computed
    averageStars: Float!
      @cypher(
        statement: "MATCH (this)<-[:REVIEWS]-(r:Review) RETURN avg(r.stars)"
      )
    recommended(first: Int = 1): [Business!]!
      @cypher(
        statement: """
        MATCH (this)<-[:REVIEWS]-(:Review)<-[:WROTE]-(:User)-[:WROTE]->(:Review)-[:REVIEWS]->(rec:Business)
        WITH rec, COUNT(*) AS score
        RETURN rec ORDER BY score DESC LIMIT $first
        """
      )
    name: String!
    city: String!
    state: String!
    address: String!
    location: Point!
    reviews: [Review!]! @relationship(type: "REVIEWS", direction: IN)
    categories: [Category!]! @relationship(type: "IN_CATEGORY", direction: OUT)
  }

  type User {
    userID: ID!
    name: String!
    reviews: [Review!]! @relationship(type: "WROTE", direction: OUT)
  }

  type Review {
    reviewId: ID!
    stars: Float!
    date: Date!
    text: String
    user: User! @relationship(type: "WROTE", direction: IN)
    business: Business! @relationship(type: "REVIEWS", direction: OUT)
  }

  type Category {
    name: String!
    businesses: [Business!]! @relationship(type: "IN_CATEGORY", direction: IN)
  }
`;

const driver = neo4j.driver(
  "bolt://localhost:7687",
  neo4j.auth.basic("database", "password") # this is not the default database
);

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

neoSchema.getSchema().then(async (schema) => {
  const server = new ApolloServer({ schema });
  const { url } = await startStandaloneServer(server, {
    listen: { port: 4000 },
  });
});

1 Answers1

0

After too many hours I came up with a list of possible issue(s).

  • Is there an error? No
  • Is my db running? Yes
  • Is my connection correct? Yes as there is an error if I use the wrong password
  • Is my schema correct? Uknown: I used the @neo4j/introspector to attempt to see what my schema looked like and it returns an empty string. Hmm
  • Am I connected to the right DBMS???

I am not using the default neo4j instance that comes by default. I have a separate DBMS that I have installed plugins on and that's what I'm attempting to connect to.

After more searching and dead ends I used the right search terms to get what I was looking for. Here in the official documentation is how to specify which DBMS you want to use. After updating my code like below everything began working as expected.

neoSchema.getSchema().then(async (schema) => {
  const server = new ApolloServer({ schema });
  const { url } = await startStandaloneServer(server, {
    listen: { port: 4000 },
    // HERE
    context: async ({ req }) => ({ req, driverConfig: { database: "NOT_DEFAULT_DBMS" } }),
  });
});