adonis-apollo-server [WIP]
GraphQL implementation using Apollo Server for Adonis
This package integrates Apollo GraphQL Server with the AdonisJS framework. It allows you to use Apollo server in your AdoinsJS app.
NOTE: This package requires @adonisjs/bodyparser and graphql
Installation
yarn add --exact @lukinco/adonis-apollo-server
Registering provider
Make sure to register the provider inside start/app.js
file.
const providers = [
'adonis-apollo-server/providers/ApolloServerProvider'
]
That's all!
Usage
Now you can use the provider by pulling it from IoC container
'use strict'
const Route = use('Route')
const ApolloServer = use('ApolloServer')
const { makeExecutableSchema } = require('graphql-tools')
const typeDefs = `
type Query {
testString: String
}
`
const resolvers = {
Query: {
testString () {
return 'Seems to be working!'
}
}
}
const schema = makeExecutableSchema({ typeDefs, resolvers })
Route.post('/graphql', ({ auth, request, response }) => {
return ApolloServer.graphql({
options: {
schema,
context: { auth }
},
request,
response,
onError: (errors) => {
}
})
})
Route.get('/graphiql', ({ request, response }) => {
return ApolloServer.graphiql({
options: { endpointURL: '/graphql' },
request,
response
})
})
Uploads
TODO
License
MIT