/test-graphql-http

A JavaScript API and CLI to test a GraphQL server for GraphQL HTTP spec compliance.

Primary LanguageJavaScript

test-graphql-http

CI status

A JavaScript API and CLI to test a GraphQL server for GraphQL HTTP spec compliance.

Setup

To install from npm run:

npm install test-graphql-http --save-dev

Then create and run a GraphQL server that implements the test schema.

Finally use either the function testGraphqlHttp or the CLI with the GraphQL server URI to run the tests.

Support

  • Linux, macOS.
  • Node.js v10+.

CLI

The test-graphql-http command tests that a GraphQL server at a given URI implements the test schema and complies with the GraphQL HTTP spec. It outputs test results to stdout and stderror accordingly, and exits with status 1 if tests failed.

It implements the function testGraphqlHttp and has one argument; the GraphQL server URI.

npx example:

npx test-graphql-http http://localhost:3001/graphql

API

Table of contents

function testGraphqlHttp

Tests that a GraphQL server at a given URI implements the test schema and complies with the GraphQL HTTP spec. It outputs test results to the console, and if tests failed sets the process.exitCode to 1, optionally throwing an error.

Parameter Type Description
uri string GraphQL server URI.
throwOnFailure boolean? After tests run, should an error be thrown if some failed.

Returns: Promise<void> — Resolves once tests are complete.

Examples

How to import.

const { testGraphqlHttp } = require('test-graphql-http')

constant schema

The test GraphQL schema that a GraphQL server should implement for testing with testGraphqlHttp.

Type: GraphQLSchema

Examples

How to import.

const { schema } = require('test-graphql-http')