Last active
August 25, 2018 21:15
-
-
Save jcuffe/e89a25a1d0758103ae1e189af8223062 to your computer and use it in GitHub Desktop.
Apollo server and client together
This file contains hidden or 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
const typeDefs = ` | |
type Query { | |
hello: String | |
} | |
`; | |
const resolvers = { | |
Query: { | |
hello: () => "Hello, world!" | |
} | |
}; | |
export default { typeDefs, resolvers }; |
This file contains hidden or 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
import React from 'react'; | |
import { Query } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
const query = gql` | |
{ | |
hello | |
} | |
`; | |
export default () => { | |
<Query query={query}> | |
{({ loading, error, data }) => { | |
if (loading) return <p>Loading...</p>; | |
if (error) return <p>{error}</p>; | |
return <p>Hello</p>; | |
}} | |
</Query> | |
} |
This file contains hidden or 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
import UniversalEvents, { UniversalEventsToken } from 'fusion-plugin-universal-events'; | |
import ApolloServer, { ApolloServerEndpointToken } from 'fusion-plugin-apollo-server'; | |
import GetApolloClient, { ApolloClientEndpointToken } from 'fusion-apollo-universal-client'; | |
import App, { ApolloClientToken, GraphQLSchemaToken } from 'fusion-apollo'; | |
import {makeExecutableSchema} from 'graphql-tools'; | |
import {FetchToken} from 'fusion-tokens'; | |
import unfetch from 'unfetch'; | |
import React from 'react'; | |
import Router from 'fusion-plugin-react-router'; | |
import Styletron from 'fusion-plugin-styletron-react'; | |
import root from './root.js'; | |
import schema from './graphql/schema.js'; | |
const graphqlEndpoint = '/graphql'; | |
export default () => { | |
const app = new App(root); | |
app.register(Styletron); | |
app.register(Router); | |
app.register(UniversalEventsToken, UniversalEvents); | |
app.register(ApolloServer); | |
app.register(ApolloClientToken, GetApolloClient); | |
app.register(ApolloServerEndpointToken, graphqlEndpoint); | |
app.register(ApolloClientEndpointToken, graphqlEndpoint); | |
app.register(GraphQLSchemaToken, makeExecutableSchema(schema)); | |
__NODE__ && app.register(FetchToken, unfetch); | |
return app; | |
}; |
This file contains hidden or 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
import React from 'react'; | |
import {Router, Route, Switch} from 'fusion-plugin-react-router'; | |
import Header from './components/header.js'; | |
import Home from './pages/home.js'; | |
import PageNotFound from './pages/pageNotFound.js'; | |
import Styles from './pages/styles.js'; | |
const root = ( | |
<div> | |
<Header /> | |
<Switch> | |
<Route exact path="/" component={Home} /> | |
<Route exact path="/styles" component={Styles} /> | |
<Route component={PageNotFound} /> | |
</Switch> | |
</div> | |
); | |
export default root; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment