Must a GraphQL field be a Query type to be mentioned in a query?

Must a GraphQL field be a Query type to be mentioned in a query?


1

Say I have this GraphQL query:

query GetUser($user_id: Int) {
  user(user_id: $user_id) {
    name
  }
  groups(user_id $user_id) {
    name
  }
}

This query recieves user id, and returns:

  1. user’s name
  2. names of all the groups this user belongs to

I know that user should be defined in the SDL like this:

type Query{
  user(user_id: Int): User
}

and that the server should define a resolver function named user.

But – can I be sure that groups field is defined the same way?

More specifically – can I se sure that referring groups in a query is possible, i.e. like this:

query Groups($user_id: Int) {
  groups(user_id: $user_id) {
    name
  }
}

Thanks

New contributor

Yaniv Gabay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 7 more related questions


Show fewer related questions

0



Leave a Reply

Your email address will not be published. Required fields are marked *