EasyGraphQL / easygraphql-tester

Test GraphQL queries, mutations and schemas on an easy way! 🚀
https://easygraphql.com/docs/easygraphql-tester/overview
MIT License
314 stars 34 forks source link

Setup header properties on `.graphql` function #102

Closed marcogbarcellos closed 5 years ago

marcogbarcellos commented 5 years ago

I was wondering if we have a way to setup header properties through the .graphql function. I'm using apollo server and it seems that using it is bypassing some middlewares(like authentication/authorization stuff).

example on what would be nice to have:

tester.graphql(query, undefined, undefined, { isLocal: false, headers: { authorization: 'Bearer JWT AshufewmrgfddJWT_TOKEN_EX' } })
  .then(result => console.log(result))
  .catch(err => console.log(err))
estrada9166 commented 5 years ago

I hadn't try it yet, but maybe you can set on the context a new object with the req and also there with the headers. I think that doing that we can mock the request.

Here is a post from Apollo that maybe can be useful.

It can be something like

const context = {
  req: {
    authorization: 'Bearer JWT AshufewmrgfddJWT_TOKEN_EX'
  }
}

tester.graphql(query, undefined, context, { isLocal: false })
  .then(result => console.log(result))
  .catch(err => console.log(err))
estrada9166 commented 5 years ago

@marcogbarcellos does it works for you?

Can we close this issue?

marcogbarcellos commented 5 years ago

Yeah it worked! thanks!