{"id":13700862,"url":"https://github.com/alexstrat/supertest-graphql","last_synced_at":"2025-09-27T12:31:35.931Z","repository":{"id":41968037,"uuid":"439468954","full_name":"alexstrat/supertest-graphql","owner":"alexstrat","description":"Extends supertest to test a GraphQL endpoint","archived":false,"fork":false,"pushed_at":"2023-01-24T09:39:09.000Z","size":648,"stargazers_count":34,"open_issues_count":12,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-11T16:04:10.023Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexstrat.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-12-17T21:51:48.000Z","updated_at":"2024-12-19T15:14:14.000Z","dependencies_parsed_at":"2023-02-13T19:45:44.036Z","dependency_job_id":null,"html_url":"https://github.com/alexstrat/supertest-graphql","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstrat%2Fsupertest-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstrat%2Fsupertest-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstrat%2Fsupertest-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstrat%2Fsupertest-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexstrat","download_url":"https://codeload.github.com/alexstrat/supertest-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234437325,"owners_count":18832454,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T20:01:03.779Z","updated_at":"2025-09-27T12:31:35.613Z","avatar_url":"https://github.com/alexstrat.png","language":"TypeScript","readme":"# supertest-graphql\n\u003cp\u003e\n  \u003ca href=\"https://badge.fury.io/js/supertest-graphql\"\u003e\u003cimg src=\"https://badge.fury.io/js/supertest-graphql.svg\" alt=\"npm version\" height=\"18\"\u003e\u003c/a\u003e\n  \u003ca href=\"#\" target=\"_blank\"\u003e\n    \u003cimg alt=\"License: ISC\" src=\"https://img.shields.io/badge/License-ISC-yellow.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/intuit/auto\"\u003e\u003cimg src=\"https://img.shields.io/badge/release-auto.svg?style=flat-square\u0026colorA=888888\u0026amp;colorB=9B065A\u0026amp;label=auto\u0026amp;logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAACzElEQVR4AYXBW2iVBQAA4O+/nLlLO9NM7JSXasko2ASZMaKyhRKEDH2ohxHVWy6EiIiiLOgiZG9CtdgG0VNQoJEXRogVgZYylI1skiKVITPTTtnv3M7+v8UvnG3M+r7APLIRxStn69qzqeBBrMYyBDiL4SD0VeFmRwtrkrI5IjP0F7rjzrSjvbTqwubiLZffySrhRrSghBJa8EBYY0NyLJt8bDBOtzbEY72TldQ1kRm6otana8JK3/kzN/3V/NBPU6HsNnNlZAz/ukOalb0RBJKeQnykd7LiX5Fp/YXuQlfUuhXbg8Di5GL9jbXFq/tLa86PpxPhAPrwCYaiorS8L/uuPJh1hZFbcR8mewrx0d7JShr3F7pNW4vX0GRakKWVk7taDq7uPvFWw8YkMcPVb+vfvfRZ1i7zqFwjtmFouL72y6C/0L0Ie3GvaQXRyYVB3YZNE32/+A/D9bVLcRB3yw3hkRCdaDUtFl6Ykr20aaLvKoqIXUdbMj6GFzAmdxfWx9iIRrkDr1f27cFONGMUo/gRI/jNbIMYxJOoR1cY0OGaVPb5z9mlKbyJP/EsdmIXvsFmM7Ql42nEblX3xI1BbYbTkXCqRnxUbgzPo4T7sQBNeBG7zbAiDI8nWfZDhQWYCG4PFr+HMBQ6l5VPJybeRyJXwsdYJ/cRnlJV0yB4ZlUYtFQIkMZnst8fRrPcKezHCblz2IInMIkPzbbyb9mW42nWInc2xmE0y61AJ06oGsXL5rcOK1UdCbEXiVwNXsEy/6+EbaiVG8eeEAfxvaoSBnCH61uOD7BS1Ul8ESHBKWxCrdyd6EYNKihgEVrwOAbQruoytuBYIFfAc3gVN6iawhjKyNCEpYhVJXgbOzARyaU4hCtYizq5EI1YgiUoIlT1B7ZjByqmRWYbwtdYjoWoN7+LOIQefIqKawLzK6ID69GGpQgwhhEcwGGUzfEPAiPqsCXadFsAAAAASUVORK5CYII=\" alt=\"Auto Release\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\u003e Extends [supertest](https://www.npmjs.com/package/supertest) to test a GraphQL endpoint\n\n## Install\n\n```sh\nnpm install supertest-graphql\n```\n\n## Usage\n\n```ts\nimport request from 'supertest-graphql'\nimport gql from 'graphql-tag'\n\ntest('should get pets', async () =\u003e {\n  const { data } = await request(app)\n    .query(gql`\n      query {\n        pets {\n          name\n          petType\n        }\n      }\n    `)\n    .expectNoErrors()\n  \n  expect(data.pets).toHaveLength(2)\n})\n```\n\n### Set expectations\n`expectNoErrors` will verify that the API response has no `errors` in\nits result payload.\n\n```ts\nawait request(app)\n  .query('blooop')\n  .expectNoErrors()\n  // expected no errors but got 1 error(s) in GraphQL response: Syntax Error: Unexpected Name \"blooop\".\n```\n### Variables\n```ts\nconst { data } = await request(app)\n  .query(gql`\n    query GetPets($first: Int){\n      pets(first: $first) {\n        name\n        petType\n      }\n    }\n  `)\n  .variables({ first: 4 })\n```\n\n### Mutation\n```ts\nconst { data } = await request(app)\n  .mutate(gql`\n    mutation PetAnimal($petId: ID!) {\n      petAnimal(petId: $petId) {\n        name\n        petType\n      }\n    }\n  `)\n  .variables({petId: 'my-cat' })\n```\n\n### Subscriptions with WebScoket\n```ts\nimport { supertestWs } from 'supertest-graphql'\nimport gql from 'graphql-tag'\n\n// for websocket the server needs to be started and stopped manually\nbeForeEach(() =\u003e server.listen(0, \"localhost\"))\nafterEach(() =\u003e server.close())\n\ntest('should get pets', async () =\u003e {\n  const sub = await supertestWs(app)\n    .subscribe(gql`\n      subscription {\n        newPetAdded {\n          name\n          petType\n        }\n      }\n    `)\n  \n  // will wait or pop the next value\n  const { data } = await sub.next().expectNoErrors()\n\n  expect(data.newPetAdded.name).toEqual('Fifi')\n})\n```\n\n### Authentication\n```ts\nconst { data } = await request(app)\n  .auth('username', 'password')\n  .query(...)\n```\n\nor via headers:\n```ts\nconst { data } = await request(app)\n  .set('authorization', 'my token')\n  .query(...)\n```\n\nFor WebSocket with `connectionParams`:\n```ts\nimport { supertestWs } from 'supertest-graphql'\n\nconst sub = await supertestWs(app)\n  .connectionParams({\n    token: 'my token'\n  })\n  .subscribe(...)\n```\n### Change GraphQL endpoint path\n\nBy default, the execution are sent to `/graphql`.\n\nYou can change this with `.path()`:\n\n```ts\nconst { data } = await request(app)\n  .path('/new-graphql')\n  .query(...)\n```\n\n### Use WebSocket legacy protocol\n\n```ts\nimport { supertestWs, LEGACY_WEBSOCKET_PROTOCOL } from 'supertest-graphql'\n\nconst sub = await supertestWs(app)\n  .protocol(LEGACY_WEBSOCKET_PROTOCOL)\n  .subscribe(...)\n```","funding_links":[],"categories":["Implementations"],"sub_categories":["JavaScript/TypeScript"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexstrat%2Fsupertest-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexstrat%2Fsupertest-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexstrat%2Fsupertest-graphql/lists"}