2

I've read the docs and I cannot seem to figure out how to structure my GraphQL for a particular query. For my data I have:

child
  |_ school
       |_ class

A child has schools and schools have classes, but a child is only assigned to specific classes in a school.

I want to query a specific child to get only the classes they are in.

query={
  child(id:$id){
    schools{
      name
      classes{
        name
      }
    }
  }
}

I can technically filter the classes while resolving the schools field in the child type by looking deep down the fields but I wanted to clarify that this is still conforming to GraphQL. Should I be placing the classes as a field in the child type instead?

1 Answer 1

2

A child also have classes, so it makes sense to create a classes field in the child object. This, in addition to the classes field in the school object.

Of course you could also filter the classes while resolving it but it's just another extra work with no particular reason.

Since there is a direct relationship between a child and his classes it seems better for a child to have a classes field.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.