1
votes

I am attempting to create a relationship in my Neo4j database with a GraphQL mutation. I have a number of other mutations already working except this one causing problems. It looks like this:

mutation(
    $id: String!,
    $recipe: String!,
    $date: String!
) {
    CreateUserRecipeRelation(id:$id, recipe:$recipe, date:$date) {
            id
        recipe {
        name
      }
  }    
}

I am passing in the following set of parameters:

{"id": "google-oauth2|yyyyremovedauthstuffyyyy", "recipe": "baked spaghetti", "date": "10/10/2018"}

But the GraphQL playground throws the following error:

"Variable \"$id\" of required type \"String!\" was not provided."

In my schema.graphql file I have the following defined:

  CreateUserRecipeRelation (
    id: String
    recipe: String
    date: String
  ): User @cypher(statement:
    "MATCH (r:Recipe{name:$recipe}), (u:User{id:$id}) CREATE (r)-[c:Created_By{date:$date}]->(u) RETURN r,c,u")

And if I run that cypher query directly in Neo4j it works just fine. In this same project I have 5 or 6 other relationship-creating mutations currently working but this one is giving me pause.

UPDATE:

This is a mutation I currently have that is working, so you can see the similarity in structure:

  CreateIngredientRelation (
    name: String
    recipe: String
    quantity: String
  ): Ingredient @cypher(statement:
    "MATCH (r:Recipe{name:$recipe}), (i:Ingredient{name:$name}) CREATE (r)-[c:Contains{quantity:$quantity}]->(i) RETURN r,c,i")

This one works great and creates tons of relationships with the quantity attached to them. This is why I am puzzled. If they both didn't work it would be easier to try and come up with a solution I think.

1
No follow up on how you resolved this question, if you did?Preston
You know, I don't remember if I solved it. I imagine I did. Let me check my repo this evening and see what fixes I put in place and I will let you know.BehemothDan

1 Answers

1
votes

@BehemothDan, how are you calling this mutation? Are you using react-apollo? If yes, Let me provide you an example of how you should be handling this. For example, if you have a form to create this UserRecipeRelation. You have your Mutation component from react-apollo. On this Mutation you have on renderProps CreateUserRecipeRelation, that you could pass to a function on onSubmit. In this function you pass your variables:

UserRecipeRelation({ variables: { id: 'your id', recipe: 'bla bla', date: '12/12/18' } });

Hope it helps! :)