This application integrates the following technologies:
- Apollo Client 2.0 to communicate with GraphQL Server
- graphcool providing the GraphQL Server
- Create React App
You can add todos and toggle their status. If you open different windows each will be updated accordingly.
If you have any questions feel free to ping me on @gerardsans.
First, clone the repo via git:
$ git clone https://github.com/gsans/todo-apollo-v2-react.git
And then install dependencies:
$ cd todo-apollo-v2-react && npm i
In order to run this project you need to create the data model (schema) below using graphcool console online or graphcool CLI.
This is the schema used
type Todo @model {
id: ID! @isUnique
text: String!
complete: Boolean!
}
Create a GraphQL Server using this schema and graphcool CLI. On the todo-apollo-v2-react
folder run the following commands:
$ npm install -g graphcool
graphcool init server
cd server
graphcool deploy
Edit /src/client.js
and replace ADD_YOUR_API_KEY_HERE
with the endpoints from the previous step.
function setupLink() {
const httpLink = new HttpLink({
uri: `https://api.graph.cool/simple/v1/ADD_YOUR_API_KEY_HERE`
});
...
const wsLink = new WebSocketLink({
uri: `wss://subscriptions.graph.cool/v1/ADD_YOUR_API_KEY_HERE`,
options: { reconnect: true }
});
$ npm start
Navigate to http://localhost:3000
. The app will automatically reload if you change any of the source files.
Note: requires a node version >=6.x
MIT © Gerard Sans