waterline-to-graphql
Stability status: alpha
Waterline to graphql adapter. This library converts waterline models to graphql types. You can execute graphql query which in turns resolves into waterline queries behind the scenes.
Basic Usage: (See waterline-example in examples folder)
; ...
- Pass in intialized models aka waterline collections.
- If you are using standalone waterline models need to be patched with associations array. See here . See waterline-example in examples folder
- If you are passing in sails.models, you dont need the above patch
let schema = ;
- Execute graphql query
var query = '{ users{firstName,lastName posts{text,comments{text}}} }'; ;
- Example transformation Waterline
moduleexports = identity: 'user' attributes: firstName: type: 'string' required: true lastName: type: 'string' required: true email: type: 'email' required: true phone: 'string' posts: collection: 'post' via: 'from' comments: collection: 'comment' via: 'from' ;
GraphQL
// Userlet UserType = name: 'user' firstName: type: GraphQLString lastName: type: GraphQLString email: type: GraphQLString phone: GraphQLString posts: type: PostType comments: type: CommentType interfaces:Node;
Using with sails,express,relay:
If you are using with express/sails , you can define graphql middleware as below.
npm i waterline-to-graphql
- Add the following in config/http.js.
{ console; if requrl === '/graphql' var schema = ; schema: schema pretty: true req res; else return ; }
See (react-relay-graphql-sails-example)
TODO
Add mutations Add frontend code for react-relay-graphql-sails-example