Getting started with graphql – Schema Definition

In GraphQL the Schema defines the root execution queries and mutations as well as the types for your data.

Schema Object Type

The Person type has two fields, one is a standard Scalar type and the other represents a relationship to a list of other Person types that are ‘friends’. Linking other types is what makes GraphQL so powerful. Now in GraphQL Query Language (GQL), the client can traverse the friends graph without any additional code or advanced querying.

type Person {
  id: ID
  name: String
  friends: [Person]
}

Schema Query

The person query looks up a single person by it’s id. This is the entry point to your data for clients using GQL.

type Query {   
  person(id: ID!): Person
}

Query Nick’s Friend’s Friend’s Friends

Now that we have a Person type and a person root query we can look up a person and as many degrees of separation we want of the person’s friends network.

query {
  person(id: 'nick'){
    id
    name
    friends{
      id
      name
      friends{
        id
        name
        friends{
          id
          name
        }
      }
    }
  }
}

if you want to reproduce, please indicate the source:
Getting started with graphql – Schema Definition - CodeDay