@secture/adonis-apollo-server

1.0.3 • Public • Published

adonis-apollo-server

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

Installation

adonis install 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

// start/routes.js

'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.route('/graphql', ({ request, response }) => {
    return ApolloServer.graphql({ schema }, request, response)
}, ['GET', 'POST'])

Route.get('/graphiql', ({ request, response }) => {
    return ApolloServer.graphiql({ endpointURL: '/graphql' }, request, response)
})

Package Sidebar

Install

npm i @secture/adonis-apollo-server

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

4.47 kB

Total Files

4

Last publish

Collaborators

  • thenasker
  • dperezl
  • caxilomo
  • supertowers