Server-side runtime for executing queries by using a type system you define for your data.
User
type User {
name: String!
posts: [Post!]! @relation(name: "PostOnUser")
}
Post
type Post {
title: String!
user: User @relation(name: "PostOnUser")
}
Query
{
allUsers {
name
}
}
Response
{
"allUsers": [
{ "name": "Raul" },
{ "name": "Gustavo" },
{ "name": "Pedro" }
]
}
mutation {
createUser(
name: "Jorge"
) {
id
name
}
}
Response
{
"createUser": {
"id": "1",
"name": "Jorge",
}
}
Sirve para integrar Graphql. Soporte para diferentes librerias y frameworks
yarn add react-apollo
yarn add apollo-client
yarn add apollo-link-http
yarn add apollo-cache-inmemory
import { ApolloProvider } from 'react-apollo'
import { ApolloClient } from 'apollo-client'
import { HttpLink } from 'apollo-link-http'
import { InMemoryCache } from 'apollo-cache-inmemory'
Proyecto base: https://github.com/raulghm/beerjs-valdivia-slides-02/tree/master/project
const httpLink = new HttpLink({ uri: '__SIMPLE_API_ENDPOINT__' })
Crear query
y mutation
para cada componente y pasar via props. (Revisar carpeta /components
)
Se utilizo este ejemplo para mostrar el funcionamiento en React: https://github.com/graphcool-examples/react-graphql/tree/master/quickstart-with-apollo
/server/types.graphql
para ver el modelo.