{"id":15020069,"url":"https://github.com/apollographql/graphql-testing-library","last_synced_at":"2025-04-05T13:02:49.615Z","repository":{"id":244435386,"uuid":"802167010","full_name":"apollographql/graphql-testing-library","owner":"apollographql","description":"Testing utilities that encourage good practices for apps built with GraphQL.","archived":false,"fork":false,"pushed_at":"2025-02-19T11:37:47.000Z","size":3172,"stargazers_count":52,"open_issues_count":20,"forks_count":2,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-02-19T12:56:07.304Z","etag":null,"topics":["graphql","msw","testing-library"],"latest_commit_sha":null,"homepage":"https://apollographql.github.io/graphql-testing-library/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/apollographql.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-17T16:42:09.000Z","updated_at":"2025-02-17T13:48:48.000Z","dependencies_parsed_at":"2024-07-12T22:32:11.678Z","dependency_job_id":"4bef3262-5e00-4316-9e13-346c2f8db926","html_url":"https://github.com/apollographql/graphql-testing-library","commit_stats":{"total_commits":104,"total_committers":4,"mean_commits":26.0,"dds":"0.42307692307692313","last_synced_commit":"b4766fed2e4eecc5bd903e3fd71daa737e8a14f8"},"previous_names":["apollographql/graphql-testing-library"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apollographql%2Fgraphql-testing-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apollographql%2Fgraphql-testing-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apollographql%2Fgraphql-testing-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apollographql%2Fgraphql-testing-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apollographql","download_url":"https://codeload.github.com/apollographql/graphql-testing-library/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247339148,"owners_count":20923013,"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":["graphql","msw","testing-library"],"created_at":"2024-09-24T19:54:32.708Z","updated_at":"2025-04-05T13:02:49.593Z","avatar_url":"https://github.com/apollographql.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\" data-test\u003e\n  \u003ca href=\"https://graphql.org/\"\u003e\n    \u003cimg width=\"150\" height=\"150\" src=\"https://upload.wikimedia.org/wikipedia/commons/1/17/GraphQL_Logo.svg\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://mswjs.io/\"\u003e\n    \u003cimg width=\"150\" height=\"150\" src=\"https://raw.githubusercontent.com/mswjs/msw/main/media/msw-logo.svg\"\u003e\n  \u003c/a\u003e\n\n  \u003ch1\u003eGraphQL Testing Library\u003c/h1\u003e\n\n  \u003cp\u003eGenerate Mock Service Worker handlers for your GraphQL APIs.\u003c/p\u003e\n\n[![npm version](https://badge.fury.io/js/%40apollo%2Fgraphql-testing-library.svg)](https://badge.fury.io/js/%40apollo%2Fgraphql-testing-library) ![badge](https://img.shields.io/endpoint?url=https://gist.githubusercontent.com/alessbell/3fd56e82b55e134ee9cf57f28b0b3d49/raw/jest-coverage-comment__main.json) ![workflow](https://github.com/apollographql/graphql-testing-library/actions/workflows/test.yml/badge.svg)\n\n\u003c/div\u003e\n\u003chr /\u003e\n\n**GraphQL Testing Library** provides utilities that make it easy to generate [Mock Service Worker](https://mswjs.io/) handlers for any GraphQL API.\n\nMSW is the [Testing Library-recommended](https://testing-library.com/docs/react-testing-library/example-intro/#full-example) way to declaratively mock API communication in your tests without stubbing `window.fetch`.\n\nThis library currently supports incremental delivery features `@defer` and `@stream` out of the box, with plans to support subscriptions over multipart HTTP as well as other transports such as WebSockets, [currently in beta in MSW](https://github.com/mswjs/msw/discussions/2010).\n\n\u003e This project is not affiliated with the [\"Testing Library\"](https://github.com/testing-library) ecosystem that inspired it. We're just fans :)\n\n## Installation\n\nThis library has `peerDependencies` listings for `msw` at `^2.0.0` and `graphql` at `^15.0.0 || ^16.0.0`. Install them along with this library using your preferred package manager:\n\n```\nnpm install --save-dev @apollo/graphql-testing-library msw graphql\npnpm add --save-dev @apollo/graphql-testing-library msw graphql\nyarn add --dev @apollo/graphql-testing-library msw graphql\nbun add --dev @apollo/graphql-testing-library msw graphql\n```\n\n## Usage\n\n### `createHandler`\n\n```typescript\nimport { createHandler } from \"@apollo/graphql-testing-library\";\n\n// We suggest using @graphql-tools/mock and @graphql-tools/schema\n// to create a schema with mock resolvers.\n// See https://the-guild.dev/graphql/tools/docs/mocking for more info.\nimport { addMocksToSchema } from \"@graphql-tools/mock\";\nimport { makeExecutableSchema } from \"@graphql-tools/schema\";\nimport typeDefs from \"./schema.graphql\";\n\n// Create an executable schema\nconst schema = makeExecutableSchema({ typeDefs });\n\n// Add mock resolvers\nconst schemaWithMocks = addMocksToSchema({\n  schema,\n  resolvers: {\n    Query: {\n      products: () =\u003e\n        Array.from({ length: 5 }, (_element, id) =\u003e ({\n          id: `product-${id}`,\n        })),\n    },\n  },\n});\n\n// `createHandler` returns an object with a `handler` and `replaceSchema`\n// function: `handler` is a MSW handler that will intercept all GraphQL\n// operations, and `replaceSchema` allows you to replace the mock schema\n// the `handler` use to resolve requests against.\nconst { handler, replaceSchema } = createHandler(schemaWithMocks, {\n  // It accepts a config object as the second argument where you can specify a\n  // delay duration, which uses MSW's delay API:\n  // https://mswjs.io/docs/api/delay\n  // Default: \"real\" (100-400ms in browsers, 20ms in Node-like processes)\n  delay: number | \"infinite\" | \"real\",\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollographql%2Fgraphql-testing-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapollographql%2Fgraphql-testing-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollographql%2Fgraphql-testing-library/lists"}