cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site maintenance this Wednesday, February 1. Disruptions expected as we migrate the forums.

Integrating Neo4j with Nestjs and Graphql

mail2michaelenn
Graph Buddy

neo4j-graphql-js @relation directive produce a @relation undefined error in nestjs graphql generate-typings:
Using the following:
type Author {
id: ID!
name: String!
posts: [Post] @relation(name: "REGISTERED", direction: "OUT")
}
with
const definitionsFactory = new GraphQLDefinitionsFactory();
definitionsFactory.generate({
typePaths: ['./src/**/*.graphql'],
path: join(process.cwd(), 'src/schema.graphql.ts'),
outputAs: 'class',
watch: true,
});

to produce an auto-generated schema result in this error:
(node:181608) UnhandledPromiseRejectionWarning: Error: Unknown directive "relation".
at assertValidSDL (C:\Genysis-Microservices\registry.genysis.com\node_modules\graphql\validation\validate.js:108:11)
at Object.buildASTSchema (C:\Genysis-Microservices\registry.genysis.com\node_modules\graphql\utilities\buildASTSchema.js:71:34)
at Object.buildSchemaFromTypeDefinitions (C:\Genysis-Microservices\registry.genysis.com\node_modules\graphql-tools\src\generate\buildSchemaFromTypeDefinitions.ts:43:32)

It would appear that we have to define the directives before we can use them in GraphQLDefinitionsFactory()....if this is the case how would we handle the directives of neo4j-graphql-js augmented schema?

7 REPLIES 7

MuddyBootsCode
Graph Steward

What exactly are you trying to accomplish with GraphQLDefinitionsFactory? I suspect that they're going to be incompatible because under the hood they're trying to build resolvers, etc. in different ways. What may be more reasonable is to create two schemas one with neo4j-graphql-js and another with GraphQLFactory and then merge them together with Apollo's merge schema directive. I don't have any experience with GraphQLDefinitionsFactory so that may be off base.

mail2michaelenn
Graph Buddy

Thanks for responding...This was my thought...the two schema options seems to be an answer but that would immediately be anti-pattern. What I was hoping is that the schema .ts file generated by definitions could be accessed be neo4j-graphql.js and produce a final single augmented schema....it may be a bridge to far. The GraphQLDefinitionsFactory currently gather all the .graphql SDL files and create a single .ts file...The SDL files apparently cannot use @relation so I guess if I would have to drop neo4j-grapql-js and augmented schema.

MuddyBootsCode
Graph Steward

In the end when you merge your schemas you do get a single augmented schema but if you're hoping to make use of cypher directives, etc and not use neo4j-graphql-js then you're going to have to use the Neo4j JavaScript driver and write those things out manually for your application which may be overkill depending upon your use case. Unless you have a serious need to go with the Definitions Factory I think you'll find that the auto generated mutations and then the ability to write custom cypher queries and mutations available with neo4j-graphql-js will save you quite a bit of work.

mail2michaelenn
Graph Buddy

Thanks...will continue to investigate. I do like the module-lization approach of Nestjs and the shortcuts of neo4j-graphql but I guess its not a match made in heaven.

MuddyBootsCode
Graph Steward

If you don't mind telling me. What exactly are you trying to accomplish? I'm sure there's more than one way to skin the cat, etc. Plus, it's an interesting problem.

mail2michaelenn
Graph Buddy

I am trying to auto-generate central schema from multiple SDLs...type files (Nest construct) that will accept the neo4j-graphql directives....I am build a large multi-microservices application that will require new SDLs from time to time so I need a schema construct that's scalable and gives developers the freedom to create their own schemas and add them to the central registry in a CI/CD pipleline. Apollo federation makes some promises...but the problem is the same..... I need to integrate it with neo4j-graphql.
I am also suspecting that the Nestjs+schema+graphql nexus is not stable....so how we treat the schema my affect the behavior of your queries.
I have many ways to auto-generate the SDLs into a central schema....including this very good strategy
https://medium.com/@choudlet/how-to-combine-graphql-type-definitions-quickly-and-easily-with-apollo-........from Chris Houdlette
Even so we can't use Nest GraphQLDefinitionsFactory to generate an augmented Schema from the output....so it would seem that we are skipping a very important part of Nest which may have an impact later............of course I could always drop Nest ....which would be a shame.....

Hi I am facing a similar issue as you did. In my case I just want to generate the types from a given neo4j schema to use them in graphql, here is my question https://community.neo4j.com/t5/drivers-stacks/neo4j-nestjs-graphql-directives-relashionship-unknown-...

So did you manage it to combine the neo specific schema with nestjs?

Thanks in advance...