Installation

Dependencies

npm install graphql-thinky --save

To initialize the the package, simply create a file ex: graphql-thiky.js

// graphql-thinky.js
import GraphQLThinky from 'graphql-thinky';
import models from './../models'; // import your models so they can be bound to thinky
import thinky from '../thinky'; // thinky instance


export default new GraphQLThinky(thinky);

Here is the only place where you will import the package. In all other files you will import this local file so that you can work on the GraphqlThinky instance.

Next: We need to make sure that we pass to the graphql context the ready to use Loaders created by the library. Here as follow:

// server.js
import GT from './graphql-thinky';

const app = express();

app.use(bodyParser.json());
// We are going to create new instances of the Loaders
// for every request
app.use('/graphql',expressGraphql(request => ({ 
  schema,
  context: {
  	loaders: GT.getModelLoaders() 
  },
  graphiql: true,
  pretty: true
})));

app.listen(7000, function() {
  console.log("Server started at port: 7000");
});