Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonyThorpe committed Jun 16, 2017
1 parent 4211457 commit dd18bf0
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 31 deletions.
26 changes: 13 additions & 13 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
A knockoutjs extension to connect to a GraphQL endpoint through an ApolloClient instance

## Approach
* Provide public access to the an instance of the ApolloClient class, as well as, ObservableQuery for the query, subscribe, etc., methods (subscriptions not fully implemented yet)
* Utilise the structure and loading features of [ko.plus](http://stevegreatrex.github.io/ko.plus/)
* A thin wrapper around an instance of the ApolloClient class for GraphQL queries, mutations and subscriptions
* Utilises the structure and loading features of [ko.plus](http://stevegreatrex.github.io/ko.plus/) for queries and mutations

## How it works
Attaches additional methods to Observables/Observable Arrays via a [Custom Function](http://knockoutjs.com/documentation/fn.html).
Attaches additional methods to Observables/Observable Arrays via a [Custom Function](http://knockoutjs.com/documentation/fn.html). This library is strongly influenced by [Vue-Apollo](https://github.com/Akryum/vue-apollo).

## Requirements
* [Apollo Client](https://github.com/apollostack/apollo-client)
Expand All @@ -19,14 +19,14 @@ Attaches additional methods to Observables/Observable Arrays via a [Custom Funct
[Index](/docs/en/index.md)

## Demos
1) To run the demo open a terminal and:
1) To run a demo in localhost open a terminal and:
* `git clone https://github.com/AntonyThorpe/knockout-apollo.git`.
* And `cd knockout-apollo` and type `npm install --save-dev`.
* Next `cd test` and `meteor npm install -S`. Then after meteor and associated libraries have been installed `cd ..` back to the project root.
* Next `cd tests` and `meteor npm install -S`. Then after meteor and associated libraries have been installed `cd ..` back to the project root.
* Then `npm run test` (we use Meteor Tests as a server for the demo)
* Once Meteor is up and runing, open another terminal and cd to the project root and then `npm run demo`.
* Once Meteor is up and running, open another terminal and cd to the project root and then `npm run demo`.

2) (Doesn't currently work - need a new endpoint that works) Find out info about the Pokemon from https://graphql-pokemon.now.sh/ endpoint at [http://antonythorpe.github.io/knockout-apollo](http://antonythorpe.github.io/knockout-apollo)
2) (Doesn't currently work - need a new endpoint that works) Find out info about the Pokémon from https://graphql-pokemon.now.sh/ endpoint at [http://antonythorpe.github.io/knockout-apollo](http://antonythorpe.github.io/knockout-apollo)

## Example: Learn Apollo
Under the `learn_apollo_example` folder, is code modified from [Learn Apollo](https://www.learnapollo.com). If you want to get this up and running:
Expand All @@ -40,17 +40,17 @@ Under the `learn_apollo_example` folder, is code modified from [Learn Apollo](ht
Hope this works :)

## Tests
In the terminal cd to the `test` folder and `meteor test --driver-package=practicalmeteor:mocha --port 3002`. None there yet.
In the terminal cd to the `test` folder and `meteor test --driver-package=practicalmeteor:mocha --port 3002`. Or `npm run test`. No tests just yet.

## Updating the Apollo Bundle
## Updating the Bundles
* At the project root `npm install -D`.
* Then `./node_modules/webpack/bin/webpack.js`
* Then `npm run build`

## Todo
* write tests

## Contributions
Pull requests most welcome!
Pull requests are most welcome!

## Support
None sorry.
Expand All @@ -62,7 +62,7 @@ None sorry.
[MIT](LICENCE)

## Links
[GraphQL-APIs](https://github.com/APIs-guru/graphql-apis) - A collective list of public GraphQL APIs
[The Anatomy of a GraphQL Query](https://dev-blog.apollodata.com/the-anatomy-of-a-graphql-query-6dffa9e9e747) - Apollo Blog by Sashko Stubailo
[The Anatomy of a GraphQL Query](https://dev-blog.apollodata.com/the-anatomy-of-a-graphql-query-6dffa9e9e747) - Apollo Blog by Sashko Stubailo. The code follows these definitions.
[Apollo-Vue](https://github.com/Akryum/vue-apollo) - contains good non-React examples
[Meteor-Ticker](https://github.com/quintstoffers/meteornl-ticker) - Apollo+Meteor app showcasing GraphQL subscriptions in its simplest form
[GraphQL-APIs](https://github.com/APIs-guru/graphql-apis) - A collective list of public GraphQL APIs
1 change: 0 additions & 1 deletion docs/en/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Index of Knockout-Apollo

* [Installation and Configuration](installationconfiguration.md)
* [Configuration](configuration.md)
* [Queries](queries.md)
* [Mutations](mutations.md)
* [Subscriptions](subscriptions.md)
9 changes: 6 additions & 3 deletions docs/en/mutations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var self = this;
self.todoList = ko.observableArray().launchApollo(apolloClient, errorCallback); // A todo list because we are very busy

// Now we are ready to make mutation, etc. with Apollo. Outline below:
// Now we are ready to make a mutation
self.todoList.apollo({object for Apollo}, {object of callbacks});
```

Expand All @@ -15,7 +15,6 @@ On the server add the corresponding schema and resolver:
```javascript
// Schema
export const schema = `
type TodoList {
_id: ID
task: String
Expand Down Expand Up @@ -67,7 +66,7 @@ export const resolvers = {
};
```
## Client
On the client within the viewModel:
On the client within a viewModel:
```javascript
// Create the GraphQL documents
var createTodoMutation = gql`
Expand All @@ -94,6 +93,8 @@ var removeTodoMutation = gql`
}
`;

// Place the below mutations within your functions

// Create
self.todoList.apollo({
mutation: createTodoMutation,
Expand Down Expand Up @@ -141,3 +142,5 @@ self.todoList.apollo({
});
```

## Index
[Link](index.md)
5 changes: 4 additions & 1 deletion docs/en/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var self = this;
self.yourObservable = ko.observable().launchApollo(apolloClient, errorCallback);

// Now we are ready to make queries, etc. with Apollo. Outline below:
// Now we are ready to make a query
self.yourObservable.apollo({object for Apollo}, {object of callbacks});
```

Expand Down Expand Up @@ -67,3 +67,6 @@ Thanks to the `ko.plus` knockout plugin there are a couple of useful public obse

## Error Callback
The default `errorCallback` is to console log the error. To customise, provide a callback function as a second arguement to the `launchApollo` function when initialising (or the third option is that you can simply pass it in with the call). Note that `ko.plus` provides a `failMessage` observable that can be set within the error callback.

## Index
[Link](index.md)
26 changes: 14 additions & 12 deletions docs/en/subscriptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var self = this;
self.todoList = ko.observableArray().launchApollo(apolloClient, errorCallback).blastoffSubscription(apolloClient, errorCallback);

// Next step: populate via a [query](queries.md).
// Next step: populate via a query.
```
Note: the errorCallbacks are optional. The default is to `console.error` any error.

Expand Down Expand Up @@ -47,6 +47,7 @@ schema {
subscription: Subscription
}
`;
```

Create a Pubsub instance (server/pubsub.js) to be shared with the initialisation of the server, the publish event from the model and the Resolvers.
```javascript
Expand Down Expand Up @@ -95,7 +96,7 @@ new SubscriptionServer({
});
```

Import the pubsub instance into your model and publish upon a change event. The below example utilises [Astronomy](http://jagi.github.io/meteor-astronomy/), a [Meteor](http://docs.meteor.com) package, that has event hooks.
Import the pubsub instance into your model and publish upon a change event. The below example utilises [Astronomy](http://jagi.github.io/meteor-astronomy/), a [Meteor](http://docs.meteor.com) package, that has an event hook feature.
```javascript
import { Class } from 'meteor/jagi:astronomy';
import { pubsub } from "/server/pubsub";
Expand Down Expand Up @@ -143,7 +144,6 @@ const TodoList = Class.create({
```
Then in the Resolver (imports/api/resolver.js)
```javascript
import { TodoList } from "/imports/models/TodoList.js"; // Obtain the model where you have a publish event from
import { pubsub } from "/server/pubsub"; // also access the pubsub instance

export const resolvers = {
Expand Down Expand Up @@ -193,8 +193,8 @@ self.todoList.startGraphqlSubscription(
query: graphqlDocumentTodoList,
},
{
next: function(data) {
switch (data.todoList.status) {
next: function(data) {
switch (data.todoList.status) {
case "added":
self.todoList.insert(data.todoList.value);
break;
Expand All @@ -204,15 +204,17 @@ self.todoList.startGraphqlSubscription(
case "deleted":
var _id = data.todoList.value._id;
var exists = ko.utils.arrayFirst(self.todoList.peek(), function(item) {
return ko.unwrap(item._id) === _id;
});
if (exists) {
self.todoList.remove(exists);
}
return ko.unwrap(item._id) === _id;
});
if (exists) {
self.todoList.remove(exists);
}
break;
}
}
}
}
}
);
```

## Index
[Link](index.md)
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ <h3 data-bind="visible: pokemon.apollo.isRunning">Loading</h3>
</div>
</div>
</body>
<script src="dist/onlinedemo.bundle.js"></script>
<script src="dist/onlinedemo.umd.bundle.js"></script>
</html>

0 comments on commit dd18bf0

Please sign in to comment.