Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using NestJS validations with Neo4jGraphQL library #117

Open
gethassaan opened this issue Feb 28, 2024 · 2 comments
Open

Using NestJS validations with Neo4jGraphQL library #117

gethassaan opened this issue Feb 28, 2024 · 2 comments

Comments

@gethassaan
Copy link

gethassaan commented Feb 28, 2024

Is your feature request related to a problem? Please describe.
While working on a project in nestjs using Graphql and Neo4j I have come across a problem when I need to validate the inputs for the Qureries and Mutations. However if you're following the approach described in Nestjs' documents adding these validations (using class-validator) is quite straight forward.

import { MinLength, MaxLength } from 'class-validator';

export class CreatePostInput {
  @MinLength(3)
  @MaxLength(50)
  title: string;
}

Whereas it can't be done with the suggested Schema Types approach from Neo4j (as class-validator requires class schema).

interface Production {
    title: String!
    actors: [Actor!]! @declareRelationship
}

type Movie implements Production {
    title: String!
    actors: [Actor!]! @relationship(type: "ACTED_IN", direction: IN, properties: "ActedIn")
    runtime: Int!
}

Describe the solution you'd like
I am looking for way where it's possible to add Schemas using classes so that we can take full advantage of existing futures of Nestjs and develop the applications without these constraints

@mjfwebb
Copy link
Contributor

mjfwebb commented Feb 28, 2024

Hi @gethassaan, I believe you can use the NestJS example at https://github.com/nestjs/nest/tree/master/sample/23-graphql-code-first as a basis to work from.

You can see that they have a way of interacting with a pre-generated schema here.

Though the schema is sourced from a static file (their schema.gql) I think you'd have no problem replacing it with a generated schema from the Neo4j GraphQL library.

As described in the getting started guide, you can use the Neo4j GraphQL library to generate the schema based on the provided type definitions like so (imports and type definitions removed for brevity):

const typeDefs = // Your type definitions here

const driver = neo4j.driver(
    "bolt://localhost:7687",
    neo4j.auth.basic("username", "password")
);

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

@mjfwebb mjfwebb closed this as completed Feb 28, 2024
@mjfwebb mjfwebb transferred this issue from neo4j/graphql Feb 29, 2024
@mjfwebb mjfwebb changed the title Class definations for GraphQL Schema Using NestJS validations with Neo4jGraphQL library Feb 29, 2024
@mjfwebb mjfwebb reopened this Feb 29, 2024
@mjfwebb
Copy link
Contributor

mjfwebb commented Feb 29, 2024

I've re-opened this issue and moved it to our docs repository with the idea that we'll write a tutorial in the future that covers this 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants