2
votes

I am trying to create a relationship between to nodes in Neo4j using GraphQL. What should the mutation look like?

Schema shows it should look like this.

AddPersonRoll(
from: _PersonInput!
to: _RollInput!
): _AddPersonRollPayload

I tryed

mutation {
  AddPersonRoll(
    from: {
      id: "be91aaca-944d-49f7-b3fd-c89ad454d5ab"
    }
    to: {
        id: "8726255f-b6b6-4299-ba01-95f6d4ef2be7"
    }
  ) { 
    from {
      id
      name
    }

    to {
      id
      name
    }
  }
}

And it worked. But when I tried putting var into the query I got

{
  "error": "Failed to execute 'fetch' on 'Window': Invalid name"
}

the code is

mutation AddPersonRoll($PersonInput: ID!, $RollInput: ID!){
  AddPersonRoll(
    from: {
      id: $PersonInput
    }
    to: {
        id: $RollInput
    }
  ) { 
    from {
      id
      name
    }

    to {
      id
      name
    }
  }
}


{
  "PersonInput": "3cc70aca-9e07-4bbd-acb2-92670b4d1b0d",
  "RollInput": "8726255f-b6b6-4299-ba01-95f6d4ef2be7"
}
1

1 Answers

0
votes

Found this earlier today when I ran into a similar problem. Here is my working mutation:

const ADD_INCIDENT_USER = gql`
  mutation AddIncidentUser($from: ID!, $to: ID!) {
    AddIncidentUser(from: { id: $from }, to: { id: $to }) {
      from {
        id
      }
      to {
        id
      }
    }
  }
`;

so in your example you would want to change

mutation AddPersonRoll($PersonInput: ID!, $RollInput: ID!){

to

mutation AddPersonRoll($from: ID!, $to: ID!){