Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

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

Open
inf3rnus opened this issue May 9, 2020 · 3 comments

Comments

@inf3rnus
Copy link

inf3rnus commented May 9, 2020

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
Copy link

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
Copy link
Member

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

@michaeldgraham
Copy link
Collaborator

#608

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

No branches or pull requests

4 participants