Skip to content

Commit

Permalink
chore(npm): update peer deps
Browse files Browse the repository at this point in the history
* also remove circleci badge now that we have github actions
  • Loading branch information
brysgo committed Aug 30, 2019
1 parent 7adec05 commit c88fb2d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,64 @@
# GraphQL + BookshelfJS

[![CircleCI][build-badge]][build]
[![npm package][npm-badge]][npm]
[![Greenkeeper badge][greenkeeper-badge]][greenkeeper]

[![peerDependency Status](https://david-dm.org/brysgo/graphql-bookshelf/peer-status.svg)](https://david-dm.org/brysgo/graphql-bookshelf#info=peerDependencies)

This is an early version of the `BookshelfType` I wrote to help me link up my Bookshelf models (built on top of Postgres) to my GraphQL schema.

### Install

`npm install --save graphql-bookshelf`

...

`var BookshelfType = require('graphql-bookshelf');`

### Example use...

Use `BookshelfType` inside of `GraphQLObjectType`...

```js
export default new GraphQLObjectType(BookshelfType({
name: 'Classroom',
description: 'Need I say more?',
// ...and an object gets passed into the fields to help with your model.
fields: (model) => ({
```
Simply wrap with `model.attr()`...
```js
id: model.attr({
type: new GraphQLNonNull(GraphQLInt),
description: 'The id of the classroom.',
// ...and you don't need to resolve table attributes.
}),
```
Or wrap with model.belongsTo()...
```js
subject: model.belongsTo({
type: SubjectType, // And use the right association type...
description: 'The subject of the classroom.',
// And you get one-to-one relationships for free
}),
```
Use model.hasMany()...
```js
students: model.hasMany({
type: new GraphQLList(StudentType), // And make sure you use `GraphQLList`
description: 'Students in the classroom.',
// Now you have associated collections for free
}),
```
Need to do more on your associated collection?
```js
homeworks: model.hasMany({
type: new GraphQLList(HomeworkType),
Expand All @@ -58,7 +70,9 @@ Need to do more on your associated collection?
}
}),
```
Or just leave it alone...
```js
size: {
type: GraphQLInt,
Expand All @@ -71,17 +85,17 @@ Or just leave it alone...
}),
}));
```

Are you using graphql-relay-js? Define some connection associations.

At the top:

```js
import {
connectionDefinitions,
connectionArgs
} from 'graphql-relay';

import { connectionDefinitions, connectionArgs } from "graphql-relay";
```

And in your schema...

```js
homeworks: model.hasMany({
type: connectionDefinitions({nodeType: HomeworkType}).connectionType,
Expand All @@ -99,19 +113,16 @@ Another thing this library could help with is optimization. Turing graphql queri
[See this example in action via the tests...](https://github.com/brysgo/graphql-bookshelf/blob/master/schema/ClassroomType.js)

### Contributing
1. Install sqlite3, clone repo, npm install
2. Create database in project root by running `sqlite3 graphql_bookshelf.sqlite`
3. Run migrations, `knex migrate:latest`
4. Run the tests with `npm test`
5. When they pass, submit a PR

1. Install sqlite3, clone repo, npm install
2. Create database in project root by running `sqlite3 graphql_bookshelf.sqlite`
3. Run migrations, `knex migrate:latest`
4. Run the tests with `npm test`
5. When they pass, submit a PR

[build-badge]: https://circleci.com/gh/brysgo/graphql-bookshelf.svg?style=shield
[build]: https://circleci.com/gh/brysgo/graphql-bookshelf

[npm-badge]: https://img.shields.io/npm/v/graphql-bookshelf.png?style=flat-square
[npm]: https://www.npmjs.org/package/graphql-bookshelf


[greenkeeper-badge]: https://badges.greenkeeper.io/brysgo/graphql-bookshelf.svg
[greenkeeper]: https://greenkeeper.io/
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
]
},
"peerDependencies": {
"bookshelf": "^0.14.2",
"graphql": "^14.1.1"
"bookshelf": "^0.15.1",
"graphql": "^14.5.4"
}
}

0 comments on commit c88fb2d

Please sign in to comment.