by Gerard Sans | @gerardsans
by Gerard Sans | @gerardsans
Spoken at 77 events in 24 countries
900
1.4K
React In Flip Flops
GraphQL created at Facebook
React is released
React Native is released
GraphQL is open sourced
Relay Classic is open sourced
New GraphQL website graphql.org
First GraphQL Summit
GitHub announces GraphQL API
Relay Modern 1.0
Apollo Client 2.0
Prisma 1.0
Apollo Engine
Apollo Client 2.1
// GET '/graphql'
{
allTodoes(first: 1) {
text
complete
}
}
// result
{
"allTodoes": [{
"text": "Learn GraphQL",
"complete": true
}]
}
schema {
query: Query
mutation: Mutation
subscription: Subscription
}
type Query {
allTodoes(first: Int): [Todo]
}
type Todo {
id: ID!
text: String!
complete: Boolean!
}
source: blog
🦇
🦇
🦇
import ApolloClient from 'apollo-boost'
import { ApolloProvider } from 'react-apollo'
const client = new ApolloClient({
uri: "https://your-ad-here/graphql"
})
const ApolloWrapper = () => (
<ApolloProvider client={client}>
<App/>
</ApolloProvider>
)
index.js
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
export const client = new ApolloClient({
link: new HttpLink({
uri: "https://time-travel-today/graphql"
}),
cache: new InMemoryCache()
});
client.js
const TODOS = gql`query todos {
allTodoes { id text complete }
}`
const withTodos = graphql(TODOS, {
props: ({ data }) => {
if (data.loading) return { loading: true }
if (data.error) return { hasErrors: true }
return {
todos: data.allTodoes || [],
}
},
});
export default withTodos(App)
src/App.js
class App extends Component {
render() {
return (
{ this.props.loading && <CircularProgress /> }
{ this.props.hasErrors && <div>Woot can't load todos!😱<div/> }
{ this.props.todos && this.props.todos.map(todo => (
<Todo key={todo.id} todo={todo}/>
)) }
);
}
}
src/App.js
const TODOS = gql`query todos {
allTodoes { id text complete }
}`;
const Todos = () => (
<Query query={TODOS}>
{({ loading, error, data }) => {
if (loading) return <CircularProgress/>;
if (error) return <div>Woot can't load todos!😱<div/>;
return data.allTodoes.map(todo => (
<Todo key={todo.id} todo={todo}/>
));
}}
</Query>
);
src/App.js
const ApolloCache = () => (
<ApolloConsumer>
{(client) => (
<pre>{client.extract()}</pre>
)}
</ApolloConsumer>
)
src/App.js
GrAMPS
Apollo Server
Prisma