Skip to content

Commit

Permalink
docs(readme): Add supported types and queries to the README
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton committed Jul 27, 2015
1 parent c002cad commit c1ff505
Showing 1 changed file with 50 additions and 6 deletions.
56 changes: 50 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
# graffiti-mongoose

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

## Install

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

## Test
## Example

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

## Usage

```javascript
// ES6 imports
import mongoose from 'mongoose';
import {graphql} from 'graphql';
import {getSchema} from '@risingstack/graffit-mongoose';

// usual mongoose stuff
var UserSchema = new mongoose.Schema({
name: {
type: String
},
age: {
type: Number,
indexed: true
},
friends: [{
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
Expand All @@ -33,10 +37,11 @@ var UserSchema = new mongoose.Schema({

var User = mongoose.model('User', UserSchema);

// graffiti from here: easy, right?
var schema = getSchema([User]);

var query = `{
users {
users(age: 28) {
name
friends {
name
Expand All @@ -46,3 +51,42 @@ var query = `{

return yield graphql(schema, query);
```

## Supported mongoose types

* Number
* String
* Boolean
* Date
* [Number]
* [String]
* [Boolean]
* [Date]
* ObjectId with ref (reference to other document, populate)
* more types coming soon...

## Supported query types

* query
* singular: for example `user`
* plural: for example `users`

## Supported query arguments

* indexed fields
* "_id" on singular type
* array of "_id" 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"]) {}
```

## Test

```
npm test
```

0 comments on commit c1ff505

Please sign in to comment.