如何使用GRANDstack在GraphQL中编写关系突变?

时间:2019-06-16 04:38:11

标签: neo4j graphql grandstack

我正在尝试使用GraphQL在Neo4j中创建与节点之间的关系。突变应该是什么样?

模式显示它应该看起来像这样。

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

我尝试了

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

    to {
      id
      name
    }
  }
}

它奏效了。但是当我尝试将var放入查询中时,我得到了

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

代码是

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 个答案:

答案 0 :(得分:0)

今天早些时候我遇到类似问题时发现了这个问题。这是我的工作变异:

//create slice
const requestState= createFeatureSelector<IRequestState>(feature);

//get exactly what you need from the state, not extra stuff
export const selectReference= createSelector(requestState, (state) => state?.reference);

export const selectWork= createSelector(requestState, (state) => state.Work);

因此在您的示例中,您需要更改

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

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