Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

How to integrate neo4j-graphql-js into nestjs w/Graphql

Graph Buddy

I am experimenting with Nestjs, graphql, and neo4j-graphql with augmented schema. I am interested if anyone doing any work in this area. The main challenge I am having relates to neo4j-graphql-js and the code-first concept. So from my understanding neo4j-graphql-js in based on the Schema-first this correct? and if this is so what kind of workaround can be done to fit in the code-first approach. If this is not so...are there any available example of how this works.



I'm not sure what you mean by code first approach, can you clarify?

yes with neo4j-graphql-js, generally you start by coming up with a GraphQL schema / set of typedefs and resolvers. The resolvers can of course be JS code, but the typedefs aren't.

There are a number of folks doing work in this area but it'd help if you could narrow down what you're trying to do, what you've tried, and what you want to do.

Graph Buddy

The Nestjs graphql docs( speaks to Schema First and Code First. The code first (resolver first) approach uses the type-graphql library to generate the schema from the resolvers....apparently this approach was introduced to solve scalability and single-source of truth for the schema. I am looking at Christian Lutz response to a similar question ( where he suggested using Nest Interceptor with the schema first approach. What I am trying to do is implement the code first approach using type-graphql and neo4j-graphql. In essence I want to go from my standard Nest/REST approach of xyz-controller --> xyz-service-->neo4j-service to a Nest/graphql/neo4j structure using the code first approach.

I am still not 100% sure I'm following, and I may just not be the right person to answer this.

On the note of generating the schema, this can be done from an existing Neo4j Database: but "generating the schema from the resolvers" doesn't fully parse for me and I can't advise.

Thanks David...I agree it's not quite clear what's going I am going to do some trial and error.


Graph Fellow

Hey @mail2michaelennis -

You can do "code first GraphQL" with neo4j-graphql.js by passing a GraphQL schema object to makeAugmentedSchema or augmentSchema. I'm not too familiar with Nest, but if you are using it to create a GraphQL schema object, you can pass that to makeAugmentedSchema from neo4j-graphql.js to add the auto-generated resolvers, instead of SDL type definitions:

const schema = makeAugmentedSchema({schema: mySchema})

In that stackoverflow answer it looks like they are passing augmentSchema to a transformSchema step.

Yes....I can see that if we have a schema created we can pass it through the augmentSchema function. The problem is in the Nest version it's not clear how the schema (schema.gql) is created. Apparently the type-graphql library builds it on startup of the app but this is not clear. I will test this view to see it it works....Thanks for the input.

Node Link

@mail2michaelennis what solution did you land on?