In GraphQL the Schema defines the root execution queries and mutations as well as the types for your data.
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]
}
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
}
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
}
}
}
}
}