简体   繁体   English

GraphQL 查询结构

[英]GraphQL query structure

I'm learning GraphQL and am working with Apollo (client and server) I still have some confusion with the structure of GraphQL queries.我正在学习 GraphQL 并且正在使用 Apollo(客户端和服务器)我仍然对 GraphQL 查询的结构有些困惑。

Questions:问题:

  1. Is it possible to merge the lines labeled #1 and #2 together?是否可以将标记为#1#2的行合并在一起? 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,提前致谢,

No. Basically #1 is you, telling Apollo you want a mutation, it's up to you if you name it or not, then, in #2 , you're telling Apollo, which mutation you want to use.不。基本上#1是你,告诉 Apollo 你想要一个突变,你是否命名它取决于你,然后,在#2中,你告诉 Apollo,你想使用哪个突变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM