forked from airyrooms/maleo.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(example): add example for apollo graphql [skip ci]
- Loading branch information
Showing
5 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[ | ||
{ | ||
"path": "/", | ||
"page": "./src/RootComponent" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |