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

**URL:** <https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636>\
**Category:** Neo4j Graph Platform\
**Tags:** graphql\
**Created:** [July 8, 2019, 11:13pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636 "2019-07-08T23:13:27Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mail2michaelenn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mail2michaelenn/32/2762_2.png) [@mail2michaelenn](https://community.neo4j.com/u/mail2michaelenn)\
**Post date:** [July 8, 2019, 11:13pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/1 "2019-07-08T23:13:27Z")

</div>

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 approach...is 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.

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [July 9, 2019, 1:20pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/2 "2019-07-09T13:20:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mail2michaelenn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mail2michaelenn/32/2762_2.png) [@mail2michaelenn](https://community.neo4j.com/u/mail2michaelenn)\
**Post date:** [July 9, 2019, 2:06pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/3 "2019-07-09T14:06:30Z")

</div>

The Nestjs graphql docs([Documentation | NestJS - A progressive Node.js framework](https://docs.nestjs.com/graphql/quick-start)) 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 ([cypher - How to integrate Neo4j database, NestJS framework and GraphQL? - Stack Overflow](https://stackoverflow.com/questions/53544876/how-to-integrate-neo4j-database-nestjs-framework-and-graphql)) 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.

---

<div class="post-metadata">

**Author:** ![david\_allen](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/david_allen/32/13090_2.png) [@david\_allen](https://community.neo4j.com/u/david_allen)\
**Post date:** [July 11, 2019, 7:49pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/4 "2019-07-11T19:49:19Z")

</div>

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: [Inferring GraphQL Type Definitions From An Existing Neo4j Database | by William Lyon | GRANDstack - GraphQL, React, Apollo, Neo4j Database](https://blog.grandstack.io/inferring-graphql-type-definitions-from-an-existing-neo4j-database-dadca2138b25) but "generating the schema from the resolvers" doesn't fully parse for me and I can't advise.

---

<div class="post-metadata">

**Author:** ![lyonwj](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/lyonwj/32/27358_2.png) [@lyonwj](https://community.neo4j.com/u/lyonwj)\
**Post date:** [July 11, 2019, 8:01pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/5 "2019-07-11T20:01:39Z")

</div>

Hey @mail2michaelenn -

You can do "code first GraphQL" with neo4j-graphql.js by passing a GraphQL schema object to [`makeAugmentedSchema` or `augmentSchema`](https://grandstack.io/docs/neo4j-graphql-js-api.html). 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:

```auto
const schema = makeAugmentedSchema({schema: mySchema})

```

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

---

<div class="post-metadata">

**Author:** ![mail2michaelenn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mail2michaelenn/32/2762_2.png) [@mail2michaelenn](https://community.neo4j.com/u/mail2michaelenn)\
**Post date:** [July 11, 2019, 9:09pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/6 "2019-07-11T21:09:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mail2michaelenn](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/mail2michaelenn/32/2762_2.png) [@mail2michaelenn](https://community.neo4j.com/u/mail2michaelenn)\
**Post date:** [July 11, 2019, 9:11pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/7 "2019-07-11T21:11:14Z")

</div>

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

-Michael

---

<div class="post-metadata">

**Author:** ![arnleiftordal](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/arnleiftordal/32/4694_2.png) [@arnleiftordal](https://community.neo4j.com/u/arnleiftordal)\
**Post date:** [October 17, 2021, 3:12pm UTC](https://community.neo4j.com/t/how-to-integrate-neo4j-graphql-js-into-nestjs-w-graphql/8636/8 "2021-10-17T15:12:00Z")

</div>

@mail2michaelenn what solution did you land on?
