Git Product home page Git Product logo

graphql-tester's People

Contributors

grahamcox-oclc avatar kasbah avatar naoto-ida avatar sazzer 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  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  avatar  avatar

graphql-tester's Issues

Support for authenticating against remote service

Often a GraphQL Service will require authentication to perform all of the required actions. It would be useful to be able to do this in the test tool.

Ideally this should be flexible enough to support arbitrary authentication systems, and certainly it needs to be able to support authentications systems that are more complex than just Basic Auth - e.g. OAuth. In the most complicated case, the authentication details might be dependant on the payload that is being sent to the server.

Support for earlier versions of Node

Currently we only support Node 5+. However, not everybody can use this version. There's no technical reason we can't support earlier versions though, so make sure it works.

Add a requestOptions parameter?

Would be great to be able to handle cookies somehow. For my purposes this works:

diff --git a/src/main/index.js b/src/main/index.js
index 28c1254..c974ef6 100644
--- a/src/main/index.js
+++ b/src/main/index.js
@@ -8,7 +8,7 @@ export function tester({
     contentType = 'application/graphql',
     authorization = null
 }) {
-    return (query) => {
+    return (query, jar) => {
         return new Promise((resolve, reject) => {
             if (server) {
                 freeport((err, port) => {
@@ -40,7 +40,8 @@ export function tester({
                     method,
                     uri: url,
                     headers: headers,
-                    body: query
+                    body: query,
+                    jar: jar
                 }, (error, message, body) => {
                     if (server && typeof(server.shutdown) === 'function') {
                         server.shutdown();

But maybe there would be a more general way to include request options. How about using Object.assign to change/add options to the request and have (query, requestOptions) => as the main function?

Support for hapi

Just as a reminder...I'll start poking around here too, to see if I can lend a hand.

Please Release v0.0.6

The currently latest available Release via npm and GitHub is
v0.0.5.
Since then ~3 commits have been made to master: v0.0.5...master
One of them being the merge of PR #10, adding a parameter to specify request options when running a query.
That Feature would allow the user of this Tool to specify headers other than content-type and authorization which are already supported.

@sazzer To ease the release cycle of npm packages there exists a tool called semantic-release which automatically creates GitHub and NPM releases when the master build goes green in CI. If you are interested I could come up with a PR.

@sazzer If you are no longer interested in maintaining this repository it would be awesome if you'd add a little note to the README on GitHub and NPM so that people know what they are up to.
Also I'd be happy to help maintain this project in the future.

fixes #13

GraphQL Tester Can't Handle Redirects

I have a GraphQL endpoint that requires authentication. I protect with some very simple (passport-based) middleware:

const redirectIfNotAuthenticated = (request, response, next) =>
  request.isAuthenticated() && request.session.user
    ? next()
    : response.redirect('/login');

// ...
app.use('/graphql', redirectIfNotAuthenticated, graphqlHTTP(request => ({ //...

This works great ... but not so great for testing. When GraphQL Tester gets that redirect response ('Found. Redirecting to /login') it tries to parse it like JSON:

// main/index.js
if (error) {
  reject(error);
} else {
  var result = JSON.parse(body); // body isn't JSON, its a redirect
  resolve({ //...

It'd be really great if the library could detect redirects and resolve with its details, but if that doesn't fit the library then at the least it should reject the promise with the proper details (instead of throwing an un-catachable exception).

In other words, instead of the current behavior of throwing an error:

SyntaxError: Unexpected token F in JSON at position 0
    at JSON.parse (<anonymous>)
    at Request._callback (server/node_modules/graphql-tester/lib/main/index.js:72:43)
    at Request.self.callback (server/node_modules/request/request.js:186:22)
    at Request.<anonymous> (server/node_modules/request/request.js:1163:10)
    at IncomingMessage.<anonymous> (server/node_modules/request/request.js:1085:12)
    at endReadableNT (_stream_readable.js:1056:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)

it would be better if it did something like:

} else {
  try {
    preValidateThatBodyIsJSON(body);
    var result = JSON.parse(body); 
    resolve({ //...
 } catch (parseError) {
   reject(parseError);
 }

(where preValidateThatBodyIsJSON throws a catch-able error if the body is not JSON)

Support for providing a configured application server

In the same way that Supertest does, it could be useful to configure GraphQL-Tester with a configured application server - Express, Hapi, Koa, etc - and a URL path into that application server. The test tool should then start up the application server on an available port, and make calls to that instead. This will make it possible to do in-process integration testing - which includes the ability to mock out external services, and to better control what the service is doing.

Can't

My application is working in production and works perfectly with graphiql, but i'm getting this response when i use this package:

{ raw: '{"errors":[{"message":"Must provide query string."}]}',
data: undefined,
errors: [ { message: 'Must provide query string.' } ],
headers:
{ 'x-powered-by': 'Express',
'access-control-allow-origin': '*',
'content-type': 'application/json; charset=utf-8',
'content-length': '53',
etag: 'W/"35-1vperDe+r7EpHry/i+J3wg"',
date: 'Sun, 17 Sep 2017 17:39:45 GMT',
connection: 'close' },
status: 400,
success: false }

What can i do to make it work?

be able to pass in custom headers

our graphql requires a couple of custom headers for authentication. Would be nice to be able to pass in custom headers through _ref.

Support for throwing connection errors for provided url

I'm still getting used to testing libraries so please correct me if my approach is wrong.

When the provided GraphQL endpoint cannot be connected to,
the test still continues against that unreachable URL.

When you instantiate a tester, shouldn't an introspection query be thrown via the url supplied or check that it returns 200 or something, and if it doesn't, stop the test there?
I'd be down to write something.

Cannot switch to express wrapper

Hey, thanks for this tester!

I just tried switching my fairly simple integration test to an internal wrapped express server but the newly modified test times out and prints:

(node:16407) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): AssertionError: expected false to be truthy
    1) responds with session id
(node:16407) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 4): AssertionError: expected false to be truthy

What am I doing wrong?

As an aside, is there a good way to send cookies along with requests?

Can we pass Authentication in header?

We need to test our API end point which uses Authentication in header, whereas the tester function will take url, server, method and contenttype.

Can we have Authentication in tester function?

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.