QuickstartΒΆ
Install graphql-factory and graphql in your project
npm install --save graphql graphql-factory
Import graphql-factory and graphql, then create a new factory
import * as graphql from 'graphql'
import GraphQLFactory from 'graphql-factory'
const factory = GraphQLFactory(graphql)
Create a factory definition
const definition = {
types: {
User: {
name: 'User',
fields: {
id: { type: 'ID', nullable: false },
name: { type: 'String', nullable: false },
email: { type: 'String' }
}
},
UsersQuery: {
listUsers: {
type: ['User'],
args: {
search: { type: 'String' }
},
resolve (source, args, context, info) {
return context.db
.table('user')
.filter(args)
}
}
}
},
schemas: {
Users: {
query: 'UsersQuery'
}
}
}
Make a library object from the definition
const lib = factory.make(definition)
Make a request
lib.Users(`
query Query ($search: String) {
listUsers (search: $search) {
id
name
email
}
}
`, {}, { db }, {
search: 'john'
})
.then(users => {
// process results
})