Giter VIP home page Giter VIP logo

adonis-apollo-server's Introduction

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)
})

adonis-apollo-server's People

Contributors

ammezie avatar marcusrognes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

adonis-apollo-server's Issues

Errors thrown from a custom type are not propagated/handled

Not sure if I am describing the issue correctly in the subject, but here is the problem. When I am throwing in a custom type, it actually results in a wrong error:

RangeError [ERR_HTTP_INVALID_STATUS_CODE]
Invalid status code: undefined

Example of a custom type definition:

const { InvalidArgumentException } = require('@adonisjs/generic-exceptions')

const Email = new GraphQLScalarType({
  name: 'Email',
  description: 'Email address.',
  parseValue (value) {
    return value
  },
  serialize (value) {
    return value
  },
  parseLiteral (ast) {
    if (emailValidator.validate(ast.value)) {
      return ast.value.toLowerCase()
    } else {
      throw new InvalidArgumentException('Not a valid email.', 400, 'E_INVALID_ARGUMENT')
    }
  }
})

Stack:

Side Note:

Not sure if relevant, but throwing from a mutator query works just fine and the errors get handled correctly.

Authentication

Could anyone provide an example of using the adonis authentication with this?
For example, I have a login resolver, where I want to create a JWT Token and return it to the user.

  login: async (parent, args, { auth }, info) => {
      try {
        const token = await auth.attempt(args.auth)
        return { token }
      } catch (error) {
        throw new GraphQLError(error.message)
      }
    }

I can see auth is passed in the context, but it just returns "Cannot convert object to primitive value" when I try to use it like the above. Would be glad of any help.

Thanks

Error handling

It appears that error handling is broken. The HTTP status is returned in statusCode attribute, rather than status for errors coming from GraphQL middleware.

response.status(error.status)

But, on top of that, I am questioning the need to handle errors there at all. Why not just let the error bubble up and be dealt with by an exceptions handler (app/Exceptions/Handler.js), which does need to be user-defined, but maybe add instructions for that.

Subscription

Any plans to make this compatible with Subscription Server?

Any plan for update version ?

This package is amazing, and everywhere we go, it points to this... but we are missing some featueres, so, there's any plan to update this ?!

CORS problem ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH

Hi,
I use adonis-apollo-server(^1.0.2) extension to create my own graphQL api.
Query request works fine, but when I use Mutation query, I have got this request error:

POST http://localhost:3333/graphql net::ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH ApolloError.js:34 Uncaught (in promise) Error: Network error: Failed to fetch at new ApolloError (ApolloError.js:34) at Object.error (QueryManager.js:122) at SubscriptionObserver.error (zen-observable.js:174) at httpLink.js:147 at

I tryed to change cors configs, but no changes.
With another graphQL API (express), I have not this error.

Thx for helping

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.