April MayJuneJuly Team 1 Team 2 Team 3 Team 4 Player 1 Team 5 rank points rank points rank points rank points rank points Player 2 Player 3 Player 4 Player 5 Player 6 Player 7 Player 8 Player 9 Player 10 Player 12 Player 13
they need • Strongly-typed schema - describe all the data • Introspective - allows clients to see what data is available (auto documentation, code generation, static validation, IDE integration) A DECLARATIVE QUERY LANGUAGE FOR API’S created by Facebook in 2012 OS in 2015
type User { id: ID! name: String email: String username: String points: Int avatar: String teams: [Team] } type Team { id: ID! name: String crest: String formation: String value: Int budget: Int players: [Player] user: User } type Player { id: ID! name: String position: Positions club: String price: Int image: Int matches: Int goals: Int assists: Int yellowCards: Int redCards: Int goalsConceded: Int }
avatar, teams } avatar name teams { id, name, players }, name name player player { id, name } { id, name } name name { id, name, players } resolvers Execution starts at the top. Resolve functions at the same level are executed concurrently.
field in the result if the argument is true. @skip(if: Boolean) Skip this field if the argument is true. query dynamic_team($tid: ID!) { team(teamId: $tid) { name players @include(if: $withPlayers) { name } } } { "tid": 1 "withPlayers": true } Unions union Searchable = User | Team | Player type Query { search(text: String!): [Searchable]! } query { search(text: "ro") { ... on User { name } ... on Team { name } ... on Player { name } } } Interfaces interface Searchable { searchText: String! } type User implements Searchable { searchText: String! … } type Team implements Searchable { searchText: String! … } type Player implements Searchable { searchText: String! … } type Query { search(text: String!): [Searchable]! }
field in the result if the argument is true. @skip(if: Boolean) Skip this field if the argument is true. query dynamic_team($tid: ID!) { team(teamId: $tid) { name players @include(if: $withPlayers) { name } } } { "tid": 1 "withPlayers": true } Unions union Searchable = User | Team | Player type Query { search(text: String!): [Searchable]! } query { search(text: "ro") { ... on User { name } ... on Team { name } ... on Player { name } } } Interfaces interface Searchable { searchText: String! } type User implements Searchable { searchText: String! … } type Team implements Searchable { searchText: String! … } type Player implements Searchable { searchText: String! … } type Query { search(text: String!): [Searchable]! }
field in the result if the argument is true. @skip(if: Boolean) Skip this field if the argument is true. query dynamic_team($tid: ID!) { team(teamId: $tid) { name players @include(if: $withPlayers) { name } } } { "tid": 1 "withPlayers": true } Unions union Searchable = User | Team | Player type Query { search(text: String!): [Searchable]! } query { search(text: "ro") { ... on User { name } ... on Team { name } ... on Player { name } } } Interfaces interface Searchable { searchText: String! } type User implements Searchable { searchText: String! … } type Team implements Searchable { searchText: String! … } type Player implements Searchable { searchText: String! … } type Query { search(text: String!): [Searchable]! }
{ avatar name teams @stream { name players @defer { name } } } } subscription teams { createTeam { name user } } { all_players { avatar name points @live } }
{ avatar name teams @stream { name players @defer { name } } } } subscription teams { createTeam { name user } } { all_players { avatar name points @live } }
{ avatar name teams @stream { name players @defer { name } } } } subscription teams { createTeam { name user } } { all_players { avatar name points @live } }