1

I'm learning GraphQL and am working with Apollo (client and server) I still have some confusion with the structure of GraphQL queries.

Questions:

  1. Is it possible to merge the lines labeled #1 and #2 together? As the lines are so similar it almost feels redundant to have both.
  2. If it is possible, is it advisable?
  3. If not, what is the benefit of having a query structured in this way?
const AddUserQuery = gql`
  /*#1*/mutation addUser($firstName: String!, $lastName: String!, $email: String!) {
    /*#2*/addUser(firstName: $firstName, lastName: $lastName, email: $email) {
      id,
      firstName,
      lastName,
      email
    }
  }`;
...
const [addUser, {data}] = useMutation(AddUserQuery);

Thanks in advance,

4

1 回答 1

2

不。基本上#1是你,告诉 Apollo 你想要一个突变,这取决于你是否命名它,然后,在 中#2,你告诉 Apollo,你想使用哪个突变。

于 2019-10-20T18:24:20.643 回答