- fragments lets us break down GQL queries intall smaller queries. like spreading an object in javascript.
fragment addressDetails on User {
name
street
zipcode
city
}
{
allUsers {
...addressDetails
}
}
it’s possible to paramtize and add default args to queries:
type Query {
allUsers(olderThan: Int = -1): [User!]!
}
use aliases when making multiples queires with different args
{
first: User(id: "1") {
name
}
second: User(id: "2") {
name
}
}
Union types work exaclty like TS:
type Adult {
name: String!
work: String!
}
type Child {
name: String!
school: String!
}
union Person = Adult | Child
Then we can use conditional fragments if the out of the union type returns different things:
{
allPersons {
name # works for `Adult` and `Child`
... on Child {
school
}
... on Adult {
work
}
}
}