Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jaydenseric/graphql-http-test
A JavaScript API and CLI to test a GraphQL server for GraphQL over HTTP spec compliance.
https://github.com/jaydenseric/graphql-http-test
graphql node npm
Last synced: 15 days ago
JSON representation
A JavaScript API and CLI to test a GraphQL server for GraphQL over HTTP spec compliance.
- Host: GitHub
- URL: https://github.com/jaydenseric/graphql-http-test
- Owner: jaydenseric
- Created: 2020-02-25T15:33:54.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-28T15:18:39.000Z (over 4 years ago)
- Last Synced: 2024-10-04T14:20:59.374Z (about 1 month ago)
- Topics: graphql, node, npm
- Language: JavaScript
- Homepage:
- Size: 78.1 KB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- Funding: .github/funding.yml
Awesome Lists containing this project
README
# graphql-http-test
[![npm version](https://badgen.net/npm/v/graphql-http-test)](https://npm.im/graphql-http-test) [![CI status](https://github.com/jaydenseric/graphql-http-test/workflows/CI/badge.svg)](https://github.com/jaydenseric/graphql-http-test/actions)
A JavaScript [API](#api) and [CLI](#cli) to test a GraphQL server for [GraphQL over HTTP spec](https://github.com/graphql/graphql-over-http) compliance.
## Setup
To install from [npm](https://npmjs.com) run:
```sh
npm install graphql-http-test --save-dev
```Use either the [CLI](#cli) command [`graphql-http-test`](#command-graphql-http-test) or the [API](#api) function [`graphqlHttpTest`](#function-testgraphqlhttp) to test your GraphQL server.
## Support
- Linux, macOS.
- Node.js `^10.17.0 || ^12.0.0 || >= 13.7.0`.## CLI
### Command graphql-http-test
The `graphql-http-test` command tests that a GraphQL server at a given URI is [GraphQL over HTTP spec](https://github.com/graphql/graphql-over-http) compliant. It outputs test results to `stdout` and `stderror` accordingly, and exits with status `1` if tests failed.
It implements the function [`graphqlHttpTest`](#function-testgraphqlhttp) and has one argument; the GraphQL server URI.
[npx](https://npm.im/npx) example:
```sh
npx graphql-http-test http://localhost:3001/graphql
```## API
### Table of contents
- [function graphqlHttpTest](#function-graphqlhttptest)
- [function reportAuditResult](#function-reportauditresult)
- [type AuditResult](#type-auditresult)
- [type AuditResultStatus](#type-auditresultstatus)### function graphqlHttpTest
Audits that a GraphQL server at a given URI is [GraphQL over HTTP spec](https://github.com/graphql/graphql-over-http) compliant.
| Parameter | Type | Description |
| :-------- | :----- | :------------------ |
| `uri` | string | GraphQL server URI. |**Returns:** Promise<[AuditResult](#type-auditresult)> — Resolves once tests are complete.
#### Examples
_Ways to `import`._
> ```js
> import { graphqlHttpTest } from 'graphql-http-test';
> ```
>
> ```js
> import graphqlHttpTest from 'graphql-http-test/public/graphqlHttpTest.js';
> ```_Ways to `require`._
> ```js
> const { graphqlHttpTest } = require('graphql-http-test');
> ```
>
> ```js
> const graphqlHttpTest = require('graphql-http-test/public/graphqlHttpTest');
> ```---
### function reportAuditResult
Reports the result of an audit in a human readable format either to `stderr` if the root audit has an `error` status, or else to `stdout`. Only intended for use in a Node.js environment.
| Parameter | Type | Description |
| :------------ | :------------------------------- | :--------------- |
| `auditResult` | [AuditResult](#type-auditresult) | An audit result. |#### Examples
_Ways to `import`._
> ```js
> import { reportAuditResult } from 'graphql-http-test';
> ```
>
> ```js
> import reportAuditResult from 'graphql-http-test/public/reportAuditResult.js';
> ```_Ways to `require`._
> ```js
> const { reportAuditResult } = require('graphql-http-test');
> ```
>
> ```js
> const reportAuditResult = require('graphql-http-test/public/reportAuditResult');
> ```---
### type AuditResult
An audit result.
**Type:** object
| Property | Type | Description |
| :-- | :-- | :-- |
| `description` | string | Audit description. |
| `status` | [AuditResultStatus](#type-auditresultstatus) | Audit result status. |
| `children` | Array<[AuditResult](#type-auditresult)>? | Child audit results. |---
### type AuditResultStatus
An audit result status.
**Type:** `ok` | `warn` | `error`