Skip to content

Commit

Permalink
Updated docs, integrated morpher
Browse files Browse the repository at this point in the history
  • Loading branch information
theodorDiaconu committed Jun 25, 2018
1 parent 584eb04 commit 7a7b1f2
Show file tree
Hide file tree
Showing 31 changed files with 778 additions and 229 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Features:

* Plug and Play Zero-Config GraphQL Server
* GraphiQL + Subscription Support
* Apollo Live Features (Reactive Scalable Queries)
* MongoDB Tailored
* Date and JSON scalars
* HTTP and Subscription built-in Authentication (+ GraphiQL Authentication Support)
* Meteor Accounts (Plug & Play)
- Plug and Play Zero-Config GraphQL Server
- GraphiQL + Subscription Support
- Apollo Live Features (Reactive Scalable Queries)
- MongoDB Tailored
- Date and JSON scalars
- HTTP and Subscription built-in Authentication (+ GraphiQL Authentication Support)
- Meteor Accounts (Plug & Play)

## Install

Expand All @@ -19,7 +19,7 @@ meteor create --bare graphql-baby
cd graphql-baby

# Now we install our npm dependencies
meteor npm i -S graphql graphql-load subscriptions-transport-ws apollo-live-server apollo-live-client apollo-client apollo-cache-inmemory apollo-link apollo-link-http apollo-link-ws express apollo-server-express uuid graphql-subscriptions body-parser graphql-tools graphql-type-json
meteor npm i -S graphql graphql-load subscriptions-transport-ws apollo-live-server apollo-live-client apollo-client apollo-cache-inmemory apollo-link apollo-link-http apollo-link-ws express apollo-server-express uuid graphql-subscriptions body-parser graphql-tools graphql-type-json apollo-morpher

# Now we add the package
meteor add cultofcoders:apollo
Expand Down Expand Up @@ -71,8 +71,8 @@ query {

### Useful packages

* [graphql-load](https://www.npmjs.com/package/graphql-load?activeTab=readme)
* [disable-introspection](https://github.com/helfer/graphql-disable-introspection)
- [graphql-load](https://www.npmjs.com/package/graphql-load?activeTab=readme)
- [disable-introspection](https://github.com/helfer/graphql-disable-introspection)

## Premium Support

Expand Down
1 change: 1 addition & 0 deletions __tests__/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './morpher/morpher.test';
4 changes: 4 additions & 0 deletions __tests__/graphql/init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { load } from 'meteor/cultofcoders:apollo';
import { typeDefs } from './module';

load({ typeDefs });
26 changes: 26 additions & 0 deletions __tests__/graphql/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const typeDefs = `
type User @mongo(name:"users") {
_id: ID!
firstName: String
lastName: String
posts: [Post] @link(to: "author")
comments: [Comment] @link(to: "user")
}
type Post @mongo(name:"posts") {
_id: ID!
name: String
author: User @link(field: "authorId")
authorId: String
comments: [Comment] @link(to: "post")
}
type Comment @mongo(name:"comments") {
_id: ID!
text: String
user: User @link(field: "userId")
post: Post @link(field: "postId")
}
`;

export { typeDefs };
8 changes: 8 additions & 0 deletions __tests__/morpher/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { initialize } from 'meteor/cultofcoders:apollo';
import { setClient } from 'apollo-morpher';

const { client } = initialize();

setClient(client);

export default client;
12 changes: 12 additions & 0 deletions __tests__/morpher/init.server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { expose, db } from 'meteor/cultofcoders:apollo';

expose({
users: {
type: 'User',
collection: () => db.users,
update: () => true,
insert: () => true,
remove: () => true,
find: () => true,
},
});
89 changes: 89 additions & 0 deletions __tests__/morpher/morpher.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import db from 'apollo-morpher';
import client from './client';

describe('Morpher', () => {
it('Should work with insert()', done => {
db.users
.insert({
firstName: 'John',
lastName: 'Smith',
})
.then(result => {
assert.isString(result._id);
done();
});
});
it('Should work with update()', async () => {
const { _id } = await db.users.insert({
firstName: 'John',
lastName: 'Smith',
});

const response = await db.users.update(
{ _id },
{
$set: { lastName: 'Brown' },
}
);

assert.equal('ok', response);
});

it('Should work with remove()', async () => {
const { _id } = await db.users.insert({
firstName: 'John',
lastName: 'Smith',
});

const response = await db.users.remove({ _id });

assert.equal('ok', response);
});

it('Should work with find()', async () => {
const { _id } = await db.users.insert({
firstName: 'John',
lastName: 'Smith',
});

const users = await db.users.find(
{
_id: 1,
firstName: 1,
lastName: 1,
},
{
filters: { _id },
}
);

assert.lengthOf(users, 1);
assert.isObject(users[0]);
assert.equal(_id, users[0]._id);
assert.equal('John', users[0].firstName);
assert.equal('Smith', users[0].lastName);
});

it('Should work with findOne()', async () => {
const { _id } = await db.users.insert({
firstName: 'John',
lastName: 'Smith',
});

const user = await db.users.findOne(
{
_id: 1,
firstName: 1,
lastName: 1,
},
{
filters: { _id },
}
);

assert.isObject(user);
assert.equal(_id, user._id);
assert.equal('John', user.firstName);
assert.equal('Smith', user.lastName);
});
});
5 changes: 5 additions & 0 deletions __tests__/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { initialize } from 'meteor/cultofcoders:apollo';
import './graphql/init';
import './morpher/init.server';

initialize();
2 changes: 1 addition & 1 deletion docs/accounts.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ load({

---

### [Table of Contents](table-of-contents.md)
### [Table of Contents](index.md)
4 changes: 2 additions & 2 deletions docs/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ initialize({
})
```

* [Read more about React Apollo](https://www.apollographql.com/docs/react/)
- [Read more about React Apollo](https://www.apollographql.com/docs/react/)

---

### [Table of Contents](table-of-contents.md)
### [Table of Contents](index.md)
22 changes: 11 additions & 11 deletions docs/db.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ type Group @mongo(name: "groups") {

Above we have the following relationships:

* Post has one Author and it's stored in `authorId`
* Post has many Comments and is linked to the `post` link
* Comment is linked to a post, and that is stored in `postId`
* Author has many Posts and is linked to the `author` link
* Author belongs to many Groups and it's stored in `groupIds`
* Groups have many Authors and is linked to `groups` link
- Post has one Author and it's stored in `authorId`
- Post has many Comments and is linked to the `post` link
- Comment is linked to a post, and that is stored in `postId`
- Author has many Posts and is linked to the `author` link
- Author belongs to many Groups and it's stored in `groupIds`
- Groups have many Authors and is linked to `groups` link

And the beautiful part is that for prototyping this is so fast, because we inject the db inside our context:

Expand Down Expand Up @@ -94,14 +94,14 @@ export default {
};
```

* [Read more about Grapher](https://github.com/cult-of-coders/grapher)
* [Read more about Grapher's performance](https://github.com/theodorDiaconu/grapher-performance)
* [Read more about Grapher Directives](https://github.com/cult-of-coders/grapher-schema-directives)
* [Read more about Grapher & GraphQL](https://github.com/cult-of-coders/grapher/blob/master/docs/graphql.md)
- [Read more about Grapher](https://github.com/cult-of-coders/grapher)
- [Read more about Grapher's performance](https://github.com/theodorDiaconu/grapher-performance)
- [Read more about Grapher Directives](https://github.com/cult-of-coders/grapher-schema-directives)
- [Read more about Grapher & GraphQL](https://github.com/cult-of-coders/grapher/blob/master/docs/graphql.md)

Read more about advanced functionalities of Collections in Meteor:
http://www.meteor-tuts.com/chapters/3/persistence-layer.html

---

### [Table of Contents](table-of-contents.md)
### [Table of Contents](index.md)
2 changes: 1 addition & 1 deletion docs/ddp.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ The logic here is that you can use `fusion`, and when your app wants to scale an

---

### [Table of Contents](table-of-contents.md)
### [Table of Contents](index.md)
8 changes: 4 additions & 4 deletions docs/grapher.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

You can use Grapher to define your links in your types, for rapid prototyping:

* [Read more about Grapher](https://github.com/cult-of-coders/grapher)
* [Read more about Grapher Directives](https://github.com/cult-of-coders/grapher-schema-directives)
* [Read more about Grapher & GraphQL](https://github.com/cult-of-coders/grapher/blob/master/docs/graphql.md)
- [Read more about Grapher](https://github.com/cult-of-coders/grapher)
- [Read more about Grapher Directives](https://github.com/cult-of-coders/grapher-schema-directives)
- [Read more about Grapher & GraphQL](https://github.com/cult-of-coders/grapher/blob/master/docs/graphql.md)

## Sample

Expand Down Expand Up @@ -37,4 +37,4 @@ export default {

---

### [Table of Contents](table-of-contents.md)
### [Table of Contents](index.md)
17 changes: 17 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Table of Contents

Hi there, if anythings are unclear, please help us improve this documentation by asking questions as issues,
and doing a PR to fix it. Thank you!

- [Simple Usage](sample.md)
- [Work with Database](db.md)
- [Morph your database](morpher.md)
- [Accounts](accounts.md)
- [Scalars](scalars.md)
- [Live Queries](live_queries.md)
- [Client](client.md)
- [DDP](ddp.md)
- [Visualising](visualising.md)
- [Settings](settings.md)
- [React-Native Client Considerations](react-native-client.md)
- [Meteor Connectivty Simulation](meteor-connectivity.md)
17 changes: 12 additions & 5 deletions docs/live_queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ This package comes already with the [apollo-live-server](https://www.npmjs.com/p

```js
type Subscription {
users: ReactiveEventUser
users: SubscriptionEvent
}

type ReactiveEventUser {
// Subscription event is loaded automatically by this package and looks like this:
type SubscriptionEvent {
event: String,
doc: User
doc: JSON
}
```

Expand All @@ -36,6 +37,12 @@ export default {
}
```

Find out more: https://www.npmjs.com/package/apollo-live-server

## Client usage:

Please refer to the documentation here: https://github.com/cult-of-coders/apollo-live-client

## Simulate reactivity

```js
Expand All @@ -53,7 +60,7 @@ Meteor.setInterval(function() {
}, 2000);
```

You can now test your query inside GraphiQL:
You can now test your query inside GraphiQL, to see how easily it reacts to changes:

```js
subscription {
Expand All @@ -66,4 +73,4 @@ subscription {

---

### [Table of Contents](table-of-contents.md)
### [Table of Contents](index.md)
Loading

0 comments on commit 7a7b1f2

Please sign in to comment.