neo4j-graphql / neo4j-graphql-js

NOTE: This project is no longer actively maintained. Please consider using the official Neo4j GraphQL Library (linked in README).
Other
608 stars 148 forks source link

Use variable number of parameters inside of @cypher directive statement with mutation #434

Open inf3rnus opened 4 years ago

inf3rnus commented 4 years ago

Hi again, is it possible to use only a subset of all of the arguments you pass into a @cypher directive mutation?

I can't seem to get this to work without putting in all of the arguments in to match the parameters in the cypher statement.

Is there a way to default values to null or something of that effect?

e.g.

type Mutation { mergeThing( id: ID title: String, description: String ): Thing @cypher( statement: """ MERGE (thing: Thing {title: $title, description: $description}) ON CREATE SET thing.id = apoc.create.uuid() RETURN thing """ )

imkleats commented 4 years ago

Have you tried doing something like this?

input ThingInput {
  id: ID
  title: String
  description: String
}

type Mutation {
  mergeThing(payload: ThingInput!): Thing @cypher(
    statement: """
      MERGE (thing:Thing $payload)
      ON CREATE SET thing.id = apoc.create,uuid()
      RETURN thing
    """
  )
}

Haven't had a chance to verify how the composite GraphQL argument is stored/provided as a parameter to the cypher query, but it looks like you should be able to use the parameter in place of the literal map for node merging (https://neo4j.com/docs/cypher-manual/current/syntax/parameters/). This seems like it would include only the attributes that are supplied in your payload.

johnymontana commented 4 years ago

Yes, ^^^ this should work. I'll make an issue to include an example of input type argument in the cos.

michaeldgraham commented 3 years ago

https://github.com/neo4j-graphql/neo4j-graphql-js/issues/608