Rita Krutikova
* Crash course
/api/v1/users
/graphql/v1
{
users: [
{
id: 1234
name: ...
email: ...
fullName: ...
}
]
}
query {
users {
id
fullName
}
}
query {
users {
id
fullName
todos {
id
text
}
}
projects {
name
}
}
type Todo {
id: Int!
text: String!
}
type Query {
users: [User!]
todo(id: String!): Todo
}
type Mutation {
addTodo(text: String!): Todo
}
type User {
id: Int!
email: String!
todos: [Todo!]
}
Client
Introspection query
Schema in json
(meta API call 😉)
Response shape is flexible
Client fetches only data it needs
Smaller payload
Strongly typed vs JSON in REST
Tooling/discoverability
Developer experience
Rita Krutikova
@apollo/react-hooks
reason-apollo
reason-apollo-hooks
graphql_ppx_re
module Query = [%graphql
{|
query {
todos {
id
text
completed
}
}
|}];
const query = gql`
query {
todos {
id
text
completed
}
}`
module Todos = [%graphql{|
query {
todos {
id
text
}
}
|}];
{
.
"todos":
Js.Array.t({
.
"id": string,
"text": string,
}),
};
module Fragment = [%graphql {|
fragment TodoItem on TodoItem {
id
text
}
|}];
module TodosQuery = [%graphql {|
query {
todos {
...Fragment.TodoItem
}
}
|}];
** Examples show soon-to-be released new amazing API of reason-apollo-hooks 😅
module Todos = [%graphql {|...|}];
switch (simple) {
| Loading => <Spinner />
| Data(data) => <TodoList data />
| NoData => React.null
| Error(_) => <Error />
}
* simple
let (simple, full) = useQuery((module Todos));
module Todo = [%graphql {|
query ($id: Int!) ...
} |}];
let variables = Todo.make(~id=42, ())##variables;
let (s, _) = useQuery(~variables, (module Todo));
* variables
let (_, full) = useQuery((module Todos));
full.fetchMore(...);
full.refetch();
* advanced
// pagination
// imperative refresh
* mild panic