Skip to content

Commit

Permalink
docs(readme): update docs for relay compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Oct 8, 2015
1 parent d573fc6 commit c406009
Showing 1 changed file with 34 additions and 11 deletions.
45 changes: 34 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
# graffiti-mongoose

[![Build Status](https://travis-ci.org/RisingStack/graffiti-mongoose.svg)](https://travis-ci.org/RisingStack/graffiti-mongoose)
[![Build Status](https://travis-ci.org/RisingStack/graffiti-mongoose.svg)](https://travis-ci.org/RisingStack/graffiti-mongoose)

[Mongoose](http://mongoosejs.com) (MongoDB) adapter for the [graffiti](https://github.com/RisingStack/graffiti) [GraphQL](https://github.com/graphql/graphql-js) ORM.

`graffiti-mongoose` generates `GraphQL` types and schemas from your existing `mongoose` models, that's how simple it is.
`graffiti-mongoose` generates `GraphQL` types and schemas from your existing `mongoose` models, that's how simple it is. The generated schema is compatible with [Relay](https://facebook.github.io/relay/).

For quick jump check out the [Usage section](https://github.com/RisingStack/graffiti-mongoose#graffiti-mongoose-1).

## Install

```
```shell
npm install graphql @risingstack/graffiti-mongoose --save
```

## Example

Check out the [/example](https://github.com/RisingStack/graffiti-mongoose/tree/master/example) folder.

```shell
cd graffiti-mongoose
npm install # install dependencies in the main folder
cd example
npm install # install dependencies in the example folder
node . # run the example application and open your browser: http://localhost:8080
```

## Usage

This adapter is written in `ES6` with [Babel](https://babeljs.io) but it's published as transpiled `ES5` JavaScript code to `npm`, which means you don't need `ES6` support in your application to run it.
This adapter is written in `ES6` and `ES7` with [Babel](https://babeljs.io) but it's published as transpiled `ES5` JavaScript code to `npm`, which means you don't need `ES7` support in your application to run it.

##### usual mongoose model(s)
```javascript
Expand Down Expand Up @@ -52,8 +60,20 @@ var schema = getSchema([User]);
var query = `{
users(age: 28) {
name
friends {
name
friends(first: 2) {
egdes {
cursor
node {
name
age
}
}
pageInfo {
startCursor
endCursor
hasPreviousPage
hasNextPage
}
}
}
}`;
Expand Down Expand Up @@ -82,24 +102,27 @@ graphql(schema, query)
* query
* singular: for example `user`
* plural: for example `users`
* [node](https://facebook.github.io/relay/docs/graphql-object-identification.html): takes a single argument, a unique `!ID`, and returns a `Node`

## Supported query arguments

* indexed fields
* "_id" on singular type
* array of "_id" on plural type
* "id" on singular type
* array of "id"s on plural type

Which means, you are able to filter like below, if the age is indexed in your mongoose model:

```
users(age: 19) {}
user(_id: "mongoId1") {}
users(_id: ["mongoId", "mongoId2"]) {}
user(id: "mongoId1") {}
user(id: "relayId") {}
users(id: ["mongoId", "mongoId2"]) {}
users(id: ["relayId1", "relayId2"]) {}
```

## Test

```
```shell
npm test
```

Expand Down

0 comments on commit c406009

Please sign in to comment.