TodoApolloV2
Technology stack
This application integrates the following technologies:
- Apollo Client 2.0 to communicate with GraphQL Server
- graphcool providing the GraphQL Server
- Angular CLI version 1.5.0
Usage
You can add todos and toggle their status. If you open different windows each will be updated accordingly.
Development
If you have any questions feel free to ping me on @gerardsans.
Install
First, clone the repo via git:
$ git clone https://github.com/gsans/todo-apollo-v2.git
And then install dependencies:
$ cd todo-apollo-v2 && npm i
graphcool GraphQL Server Setup
In order to run this project you need to create the data model (schema) below using graphcool console online or graphcool CLI.
Todo App Schema
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
folder run the following commands:
$ npm install -g graphcool
$ graphcool push
$ graphcool endpoints
Replace client URIs
Edit /src/app/graphql.module.ts
and replace ADD_YOUR_API_KEY_HERE
with the endpoints from the previous step.
private setupLink() {
// queries and mutations link (http)
const http = this.httpLink.create({
uri: 'https://api.graph.cool/simple/v1/ADD_YOUR_API_KEY_HERE'
});
// subscriptions link (websockets)
const websocket = new WebSocketLink(
new SubscriptionClient('wss://subscriptions.graph.cool/v1/ADD_YOUR_API_KEY_HERE', {
reconnect: true
})
);
Run
$ ng serve
Navigate to http://localhost:4200/
. The app will automatically reload if you change any of the source files.
Note: requires a node version >=6.x
License
MIT © Gerard Sans