Skip to content

Commit

Permalink
docs(example): add example for apollo graphql [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
alvinkl committed Mar 27, 2019
1 parent dd03ed7 commit dd46c6d
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
15 changes: 15 additions & 0 deletions example/apollo-graphql/_wrap.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import Wrap from '@airy/maleo/wrap';
import { ApolloProvider } from 'react-apollo';

import client from './src/client';

export default class CustomWrap extends Wrap{
render() {
return (
<ApolloProvider client={client}>
{super.render()}
</ApolloProvider>
)
}
}
22 changes: 22 additions & 0 deletions example/apollo-graphql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "apollo-graphql-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "maleo dev",
"build": "export NODE_ENV=production && maleo build",
"start": "export NODE_ENV=production && node .maleo/server.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@airy/maleo": "^0.0.14",
"apollo-boost": "^0.3.1",
"graphql": "^14.1.1",
"graphql-tag": "^2.10.1",
"react": "^16.8.5",
"react-apollo": "^2.5.3"
}
}
6 changes: 6 additions & 0 deletions example/apollo-graphql/routes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"path": "/",
"page": "./src/RootComponent"
}
]
47 changes: 47 additions & 0 deletions example/apollo-graphql/src/RootComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { Query } from 'react-apollo'
import gql from 'graphql-tag'

const query = gql`
{
todos{
description
status
user {
id
name
}
}
}
`

export default class extends React.Component {
render() {
return (
<Query query={query}>
{({ loading, error, data }) => {
if (loading) return 'Loading...';
if (error) return `Error! ${error.message}`;

return (
<ul>
{data.todos.map((d) => (
<li key={d.id}>
<p>
{d.description}
</p>
<p>
{d.status}
</p>
<p>
{d.user.name}
</p>
</li>
))}
</ul>
)
}}
</Query>
)
}
}
11 changes: 11 additions & 0 deletions example/apollo-graphql/src/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ApolloClient from 'apollo-boost';

export const client = new ApolloClient({
// By default, this client will send queries to the
// `/graphql` endpoint on the same host
// Pass the configuration option { uri: YOUR_GRAPHQL_API_URL } to the `HttpLink` to connect
// to a different host
uri: 'https://mini-ws-todo.herokuapp.com/graphql'
});

export default client

0 comments on commit dd46c6d

Please sign in to comment.