{"id":15433936,"url":"https://github.com/abhinaba-ghosh/testcafe-graphql-mock","last_synced_at":"2025-04-19T18:09:10.566Z","repository":{"id":39147692,"uuid":"282728900","full_name":"abhinaba-ghosh/testcafe-graphql-mock","owner":"abhinaba-ghosh","description":"custom plugin for testcafe to mock graphql server","archived":false,"fork":false,"pushed_at":"2022-06-02T21:15:22.000Z","size":1081,"stargazers_count":3,"open_issues_count":13,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T00:34:25.576Z","etag":null,"topics":["graphql","mock","testcafe"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/testcafe-graphql-mock","language":"JavaScript","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/abhinaba-ghosh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-26T20:35:26.000Z","updated_at":"2021-04-07T14:23:00.000Z","dependencies_parsed_at":"2022-09-26T20:31:33.917Z","dependency_job_id":null,"html_url":"https://github.com/abhinaba-ghosh/testcafe-graphql-mock","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-graphql-mock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-graphql-mock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-graphql-mock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/abhinaba-ghosh%2Ftestcafe-graphql-mock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/abhinaba-ghosh","download_url":"https://codeload.github.com/abhinaba-ghosh/testcafe-graphql-mock/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249758701,"owners_count":21321581,"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","mock","testcafe"],"created_at":"2024-10-01T18:36:11.466Z","updated_at":"2025-04-19T18:09:10.546Z","avatar_url":"https://github.com/abhinaba-ghosh.png","language":"JavaScript","funding_links":["https://www.patreon.com/user?u=32109749\u0026fan_landing=true"],"categories":[],"sub_categories":[],"readme":"![GraphQL Mocker logo](./docs/logo.png)\n\n# testcafe-graphql-mock\n\n[![Build Status](https://circleci.com/gh/abhinaba-ghosh/testcafe-graphql-mock.svg?style=shield\u0026branch-=master)](https://app.circleci.com/pipelines/github/abhinaba-ghosh/testcafe-graphql-mock)\n[![NPM release](https://img.shields.io/npm/v/testcafe-graphql-mock.svg 'NPM release')](https://www.npmjs.com/package/testcafe-graphql-mock)\n[![npm](https://img.shields.io/npm/l/graphql-faker.svg)](https://github.com/abhinaba-ghosh/testcafe-graphql-mock/blob/master/LICENSE)\n\nsimple testcafe commands for executing a mocked GraphQL server using only the client.\n\n## Installation\n\n```ssh\nnpm i -D testcafe-graphql-mock\n```\n\n## API available\n\n```ts\ninterface MockGraphQLOptions {\n  schema: string | string[] | IntrospectionQuery;\n  mock: IMocks;\n  delay?: number;\n}\n\nmockGraphQL(options: MockGraphQLOptions, req, res);\n```\n\n## Basic Usage\n\n```js\nimport { mockGraphQL } from 'testcafe-graphql-mock';\n\n// define the schema\nconst schema = `\ntype Person {\n  firstname: String!\n  surname: String!\n}\n\ntype Query {\n  people: [Person]\n}\n`;\n\n// define the mock\nconst mock = {\n  Query: () =\u003e ({\n    people: () =\u003e [\n      {\n        firstname: 'Lee',\n        surname: 'Byron',\n      },\n    ],\n  }),\n};\n\n// create traditional testcafe request mock\nconst requestMock = RequestMock()\n  .onRequestTo({ url: 'http://localhost:3000/graphql', method: 'POST' })\n  .respond(async (req, res) =\u003e {\n    await mockGraphQL(\n      {\n        schema,\n        mock,\n      },\n      req,\n      res\n    );\n  });\n\n// now call the testcafe request mock in fixures as request hooks\nfixture(`GraphQL Mock test`)\n  .page('http://localhost:3000/')\n  .requestHooks(requestMock);\n\ntest('test graphql mock data', async (t) =\u003e {\n  await t.click(Selector('button'));\n  await expect(Selector('div')).contains('Lee Byron');\n});\n```\n\n## Read schema from .graphql file\n\nYou need to use `graphQLSchemaFromFile` method from the library.\n\n```js\nimport { graphQLSchemaFromFile } from 'testcafe-graphql-mock';\n\n// use the graphql schema reader method in your request mocks\nconst requestMock = RequestMock()\n  .onRequestTo({ url: 'http://localhost:3000/graphql', method: 'POST' })\n  .respond(async (req, res) =\u003e {\n    await mockGraphQL(\n      {\n        schema: graphQLSchemaFromFile(\n          `${process.cwd()}/test/test-schema.graphql`\n        ),\n        mock,\n      },\n      req,\n      res\n    );\n  });\n```\n\n## Delay the GraphQL mocked response\n\nuse the `delay` (in milliseconds) parameter in `mockGraphQL({})` options\n\n```js\nconst requestMock = RequestMock()\n  .onRequestTo({ url: 'http://localhost:3000/graphql', method: 'POST' })\n  .respond(async (req, res) =\u003e {\n    await mockGraphQL(\n      {\n        schema,\n        mock,\n        delay: 5000,\n      },\n      req,\n      res\n    );\n  });\n```\n\n### License\n\nMIT\n\n## Tell me your issues\n\nyou can raise any issue [here](https://github.com/abhinaba-ghosh/testcafe-graphql-mock/issues)\n\n## Contribution\n\nAny pull request is welcome.\n\nIf this plugin helps you in your automation journey, choose to [Sponsor](https://www.patreon.com/user?u=32109749\u0026fan_landing=true)\n\nIf it works for you , give a [Star](https://github.com/abhinaba-ghosh/testcafe-graphql-mock)! :star:\n\n_- Copyright \u0026copy; 2020- [Abhinaba Ghosh](https://www.linkedin.com/in/abhinaba-ghosh-9a2ab8a0/)_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinaba-ghosh%2Ftestcafe-graphql-mock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fabhinaba-ghosh%2Ftestcafe-graphql-mock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fabhinaba-ghosh%2Ftestcafe-graphql-mock/lists"}