Pass obtained field to another query in GraphQL

前端 未结 2 402
野趣味
野趣味 2020-12-03 20:53

Imagine the following query:

query {
  user {
    id
  }
  SomeOtherStuff(id: <--- I want to pass the id obtained from user) {
    id
  }
}
2条回答
  •  北海茫月
    2020-12-03 21:23

    I agree with @DanielRearden. You should make type-resolvers so you can go infinitely deep into the graph. I made a simple server example here that shows deep relationships. Because all the noun-fields are references, it goes infinitely deep for any query.

    With that server, you can run a query like this, for example:

    {
      hero {
        name
        friends {
          name
          friends {
            name
            friends {
              name
              friends: {
                name
              }
            }
          }
        }
      }
    }
    

    So, in your example, structure it like this:

    query {
      user {
        id
        otherStuff {
          id
        }
      }
    }
    

提交回复
热议问题