{"id":13660699,"url":"https://github.com/grug/data-mocks","last_synced_at":"2025-09-04T10:09:47.135Z","repository":{"id":36605873,"uuid":"106805606","full_name":"grug/data-mocks","owner":"grug","description":"Library to mock local data requests using Fetch or XHR","archived":false,"fork":false,"pushed_at":"2023-01-04T21:54:08.000Z","size":936,"stargazers_count":62,"open_issues_count":9,"forks_count":12,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-08-09T04:24:20.330Z","etag":null,"topics":["api-mock","fetch-mock","test-framework","testing","unit-testing","web-development"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ovotech/data-mocks","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/grug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-10-13T09:35:08.000Z","updated_at":"2025-04-23T23:23:10.000Z","dependencies_parsed_at":"2023-01-17T03:15:41.550Z","dependency_job_id":null,"html_url":"https://github.com/grug/data-mocks","commit_stats":null,"previous_names":["ovotech/data-mocks"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/grug/data-mocks","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grug%2Fdata-mocks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grug%2Fdata-mocks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grug%2Fdata-mocks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grug%2Fdata-mocks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grug","download_url":"https://codeload.github.com/grug/data-mocks/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grug%2Fdata-mocks/sbom","scorecard":{"id":446774,"data":{"date":"2025-08-11","repo":{"name":"github.com/grug/data-mocks","commit":"f241cc2267bee7205ea635af23d23f11f811325d"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Code-Review","score":2,"reason":"Found 6/29 approved changesets -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/pr_open_update.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr_open_update.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/grug/data-mocks/pr_open_update.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/pr_open_update.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/grug/data-mocks/pr_open_update.yml/master?enable=pin","Info:   0 out of   2 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 10 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"43 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GHSA-968p-4wvh-cqc8","Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92","Warn: Project is vulnerable to: GHSA-6chw-6frg-f759","Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw","Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw","Warn: Project is vulnerable to: GHSA-4w2v-q235-vp99","Warn: Project is vulnerable to: GHSA-cph5-m8f7-6c5x","Warn: Project is vulnerable to: GHSA-wf5p-g6vw-rhxx","Warn: Project is vulnerable to: GHSA-jr5f-v2jv-69x6","Warn: Project is vulnerable to: GHSA-v6h2-p8h4-qcjw","Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg","Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5","Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275","Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c","Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq","Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q","Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c","Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc","Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp","Warn: Project is vulnerable to: GHSA-fjxv-7rqg-78g4","Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj","Warn: Project is vulnerable to: GHSA-896r-f27r-55mw","Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h","Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw","Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9","Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm","Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv","Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3","Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m","Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h","Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g","Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p","Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9","Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j","Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp","Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6","Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw","Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v","Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3","Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7","Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693","Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q","Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-19T06:56:32.300Z","repository_id":36605873,"created_at":"2025-08-19T06:56:32.300Z","updated_at":"2025-08-19T06:56:32.300Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273589359,"owners_count":25132861,"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","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["api-mock","fetch-mock","test-framework","testing","unit-testing","web-development"],"created_at":"2024-08-02T05:01:24.727Z","updated_at":"2025-09-04T10:09:47.076Z","avatar_url":"https://github.com/grug.png","language":"TypeScript","readme":"# data-mocks\n\n[![GitHub license](https://img.shields.io/github/license/ovotech/data-mocks.svg)](https://github.com/grug/data-mocks)\n![npm](https://img.shields.io/npm/dm/data-mocks.svg)\n\n\u003cimg src=\"https://i.imgur.com/gEG3io2.jpg\" height=\"250\"\u003e\n\nLibrary (written in TypeScript) to mock REST and GraphQL requests\n\n\u003c!-- @import \"[TOC]\" {cmd=\"toc\" depthFrom=1 depthTo=6 orderedList=false} --\u003e\n\n\u003c!-- code_chunk_output --\u003e\n\n- [Why is this library useful](#why-is-this-library-useful)\n- [Setup](#setup)\n  - [Integration patterns](#integration-patterns)\n    - [React](#react)\n    - [Angular](#angular)\n    - [No framework (just vanilla JS)](#no-framework-just-vanilla-js)\n- [REST + GraphQL](#rest-graphql)\n- [Examples](#examples)\n  - [Basic mock injection without scenarios](#basic-mock-injection-without-scenarios)\n  - [Mock injection with scenarios](#mock-injection-with-scenarios)\n  - [Basic GraphQL mock injection](#basic-graphql-mock-injection)\n- [Exported types](#exported-types)\n  - [Scenarios](#scenarios)\n  - [HttpMock](#httpmock)\n  - [GraphQLMock](#graphqlmock)\n  - [Mock](#mock)\n  - [Operation](#operation)\n  - [MockConfig](#mockconfig)\n- [Exported functions](#exported-functions)\n  - [injectMocks](#injectmocks)\n  - [extractScenarioFromLocation](#extractscenariofromlocation)\n- [Gotchas](#gotchas)\n\n\u003c!-- /code_chunk_output --\u003e\n\n## Why is this library useful\n\nWhen developing web applications locally, it is not uncommon to request data from an API. However, the API might not actually exist yet, or we might want to control what the responses are.\n\nTypically, this sort of problem has been solved by either writing a separate mock API service alongside the project (i.e. having a Node service running locally with your application) or creating a development database that replicates staging or production environments. Both of these approaches are heavy and can lead to using incorrect data if schemas are out of sync.\n\nThis library aims to allow rapid local development without the dependency of a database or fully implemented APIs.\n\n## Setup\n\n- Either `npm install data-mocks` or `yarn add data-mocks`\n- Optional: extract the scenario from URL using the imported `extractScenarioFromLocation()` function\n  - Or you can just hardcode a string to pass through instead\n- Import `injectMocks()` function into your project with `import { injectMocks } from 'data-mocks'`\n- Create an array of `Scenario`'s you would like to use (see examples)\n- Pass array of `Scenario`'s to `injectMocks()`\n- Hooray, all HTTP requests to mocked endpoints will now respond with the mocked data you have specified\n\n### Integration patterns\n\nRegardless of framework or CLI tool used to generate your project, integrating `data-mocks` into your project is easy. Here are how it may look for you:\n\n#### React\n\n```js\nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from './App';\n\nasync function main() {\n  if (process.env.NODE_ENV === 'development') {\n    const { injectMocks, extractScenarioFromLocation } = await import(\n      'data-mocks'\n    );\n\n    // You could just define your mocks inline if you didn't want to import them.\n    const { getMocks } = await import('./path/to/your/mock/definitions');\n\n    injectMocks(getMocks(), extractScenarioFromLocation(window.location));\n  }\n\n  ReactDOM.render(\u003cApp /\u003e, document.getElementById('root'));\n}\n\nmain();\n```\n\n#### Angular\n\n```ts\nimport { enableProdMode } from '@angular/core';\nimport { platformBrowserDynamic } from '@angular/platform-browser-dynamic';\n\nimport { AppModule } from './app/app.module';\nimport { environment } from './environments/environment';\n\nasync function setupMocks() {\n    const { injectMocks, extractScenarioFromLocation } = await import(\n      'data-mocks'\n    );\n    // You could just define your mocks inline if you didn't want to import them.\n    const { getMocks } = await import('./path/to/your/mock/definitions');\n\n    injectMocks(getMocks(), extractScenarioFromLocation(window.location));\n}\n\nasync function main() {\n  if (environment.production) {\n    enableProdMode();\n  }\n\n  if (!environment.production) {\n    await setupMocks();\n  }\n\n  platformBrowserDynamic()\n    .bootstrapModule(AppModule)\n    .catch((err) =\u003e console.error(err));\n}\n\nmain();\n```\n\n#### No framework (just vanilla JS)\n\n```ts\nasync function main() {\n  if (process.env.NODE_ENV === 'development') {\n    const { injectMocks, extractScenarioFromLocation } = await import(\n      'data-mocks'\n    );\n\n    // You could just define your mocks inline if you didn't want to import them.\n    const { getMocks } = await import('./path/to/your/mock/definitions');\n\n    injectMocks(getMocks(), extractScenarioFromLocation(window.location));\n  }\n}\n\nmain();\n```\n\nIn these examples, we dynamically import `data-mocks` and our mock definitions as to not increase production bundle sizes (given that we will never need/want to use these files in production environments).\n\nIt is not a requirement to dynamically import `data-mocks` or your mock definitions - it is just a recommendation :)\n\n## REST + GraphQL\n\n`data-mocks` works with either REST or GraphQL requests. It is also possible to easily mock both in the same application.\n\nSee the examples below to see how this is done.\n\n## Examples\n\n### Basic mock injection without scenarios\n\n```javascript\nimport { injectMocks } from 'data-mocks';\nimport axios from 'axios';\n\nconst scenarios = {\n  default: [\n    {\n      url: /login/,\n      method: 'POST',\n      response: { some: 'good response' },\n      responseCode: 200,\n    },\n    {\n      url: /some-other-endpoint/,\n      method: 'GET',\n      response: { another: 'response' },\n      responseCode: 200,\n      delay: 1000,\n    },\n    {\n      url: /endpoint-with-headers/,\n      method: 'GET',\n      response: { same: 'response' },\n      responseHeaders: { token: 'mock-token' },\n      responseCode: 200,\n    },\n  ],\n};\n\ninjectMocks(scenarios);\n\nfetch('http://foo.com/login', { method: 'POST', body: {} })\n  .then((response) =\u003e response.json())\n  .then((myJson) =\u003e console.log(myJson)); // resolves with { some: 'good response' } after a 200ms delay\n\nfetch('http://foo.com/some-other-endpoint')\n  .then((response) =\u003e response.json())\n  .then((myJson) =\u003e console.log(myJson)); // resolves with { another: 'response' } after a 1 second delay\n\naxios\n  .post('http://foo.com/login', {})\n  .then((response) =\u003e console.log(response)); // resolves with { another: 'response' } after a 200ms delay\n\naxios\n  .get('http://foo.com/some-other-endpoint')\n  .then((response) =\u003e console.log(response)); // resolves with { another: 'response' } after a 1 second delay\n```\n\nIn this example, we define a default scenario in our `scenarios` map. The Scenario objects are described by the [Scenario interface](#scenario). We then inject the scenarios into our application via the [injectMocks() function](#injectMocks). Finally, when we use fetch / XHR to make a request to endpoints that match our scenario objects, the mocked responses are returned.\n\nN.B\n\nIn the above example we are using `axios` as our XHR library of choice. However\n`data-mocks` will work with any library that uses `XMLHttpRequest` under the hood.\n\n---\n\n### Mock injection with scenarios\n\n```javascript\nimport { injectMocks, extractScenarioFromLocation } from 'data-mocks';\nimport axios from 'axios';\n\nconst scenarios = {\n  default: [\n    {\n      url: /login/,\n      method: 'POST',\n      response: { some: 'good response' },\n      responseCode: 200,\n    },\n    {\n      url: /some-other-endpoint/,\n      method: 'GET',\n      response: { another: 'response' },\n      responseCode: 200,\n      delay: 1000,\n    },\n  ],\n  failedLogin: [\n    {\n      url: /login/,\n      method: 'POST',\n      response: { some: 'bad things happened' },\n      responseCode: 401,\n    },\n  ],\n};\n\ninjectMocks(scenarios, 'failedLogin');\n\nfetch('http://foo.com/login', { method: 'POST', body: {} }).then((response) =\u003e\n  console.log(response)\n); // resolves with a 401 after a 200ms delay\n\nfetch('http://foo.com/some-other-endpoint').then((response) =\u003e\n  console.log(response)\n); // resolves with { another: 'response' } after a 1 second delay\n\naxios\n  .post('http://foo.com/login', {})\n  .then((response) =\u003e console.log(response)); // resolves with a 401 after a 200ms delay\n\naxios\n  .get('http://foo.com/some-other-endpoint')\n  .then((response) =\u003e console.log(response)); // resolves with { another: 'response' } after a 1 second delay\n```\n\nIn this example, if we load our site up with `?scenario=failedLogin` in the querystring and then attempt to hit the `login` endpoint, it will fail with a 401. However, the `some-other-endpoint` endpoint will still respond with the response in the `default` scenario as we have not provided one in the `failedLogin` scenario.\n\n### Basic GraphQL mock injection\n\nHere, we have a React application using `urql` as a GraphQL client. This shows how GraphQL queries work and it can be assumed that if you want to use REST mocks in this application, you can do so as you normally would (see examples above).\n\nIn reality, the mock definitions would live at a higher level (like the entrypoint into the application) where they could be injected only if we were in development mode.\n\n```tsx\nimport React from 'react';\nimport { injectMocks, extractScenarioFromLocation } from 'data-mocks';\nimport gql from 'graphql-tag';\n\nconst mocks = {\n  default: [\n    {\n      url: /graphql/,\n      method: 'GRAPHQL',\n      operations: [\n        {\n          operationName: 'Query',\n          type: 'query',\n          response: { data: { test: 'test' } },\n        },\n        {\n          operationName: 'Mutation',\n          type: 'mutation',\n          response: { data: { test: 'test' } },\n        },\n      ],\n    },\n  ],\n};\n\ninjectMocks(mocks, extractScenarioFromLocation(window.location));\n\nconst Component = () =\u003e {\n  const [result] = useQuery({ query: Query }); // result will be { data: { test: 'test' } }\n\n  return \u003c\u003e{result.data.test}\u003c/\u003e;\n};\n```\n\n## Exported types\n\n### Scenarios\n\n| Property   | Type   | Required | Description                                                                                       |\n| ---------- | ------ | -------- | ------------------------------------------------------------------------------------------------- |\n| default    | Mock[] | ✅       | The default scenario mapping. Provides a default set of mocked responses.                         |\n| [scenario] | Mock[] | ❌       | Additional scenario mappings. The key is the name of the scenario and is what is used in the URL. |\n\n### HttpMock\n\n| Property        | Type             | Required | Description                                                          |\n| --------------- | ---------------- | -------- | -------------------------------------------------------------------- |\n| url             | RegExp           | ✅       | Regular expression that matches part of the URL.                     |\n| method          | string           | ✅       | HTTP method matching one of 'GET', 'POST', 'PUT', 'PATCH', 'DELETE'. |\n| response        | object \\| string | ✅       | Body of the response.                                                |\n| responseCode    | number           | ❌       | Response code. Defaults to 200.                                      |\n| responseHeaders | object           | ❌       | Response headers. Defaults to empty.                                 |\n| delay           | number           | ❌       | Delay (in milliseconds) before response is returned. Defaults to 0.  |\n\n### GraphQLMock\n\n| Property   | Type               | Required | Description                                               |\n| ---------- | ------------------ | -------- | --------------------------------------------------------- |\n| url        | RegExp             | ✅       | Regular expression that matches part of the URL.          |\n| method     | string             | ✅       | Must be 'GRAPHQL' to specify that this is a GraphQL mock. |\n| operations | Array\\\u003cOperation\\\u003e | ✅       | Array of GraphQL operations for this request.             |\n\n### Mock\n\nUnion type of [`HttpMock`](#HttpMock) and [`GraphQLMock`](#GraphQLMock).\n\n### Operation\n\n| Property        | Type   | Required | Description                                                         |\n| --------------- | ------ | -------- | ------------------------------------------------------------------- |\n| type            | string | ✅       | GraphQL operation type. Must be either `query` or `mutation`.       |\n| operationName   | string | ✅       | GraphQL operation name.                                             |\n| response        | object | ✅       | Body of the response.                                               |\n| responseCode    | number | ❌       | Response code. Defaults to 200.                                     |\n| responseHeaders | object | ❌       | Response headers. Defaults to empty.                                |\n| delay           | number | ❌       | Delay (in milliseconds) before response is returned. Defaults to 0. |\n\n### MockConfig\n\n| Property                       | Type    | Required | Description                                                                                                        |\n| ------------------------------ | ------- | -------- | ------------------------------------------------------------------------------------------------------------------ |\n| allowXHRPassthrough            | boolean | ❌       | Any unmatched routes for XHR will pass through to the actual endpoint, rather than be mocked. Defaults to false.   |\n| allowFetchPassthrough          | boolean | ❌       | Any unmatched routes for fetch will pass through to the actual endpoint, rather than be mocked. Defaults to false. |\n| disableConsoleWarningsForFetch | boolean | ❌       | When enabled, this will suppress any console warnings generated by fetch-mock fallbacks                            |\n\n## Exported functions\n\n### injectMocks\n\n| Parameter | Type                            | Required | Description                                                                 |\n| --------- | ------------------------------- | -------- | --------------------------------------------------------------------------- |\n| scenarios | [Scenarios](#Scenarios)[]       | ✅       | A mapping of scenarios and their responses                                  |\n| scenario  | keyof [Scenarios](#Scenarios)[] | ❌       | The scenario to run. Defaults to `default`                                  |\n| config    | MockConfig                      | ❌       | Config object that allows for different behaviour of how mocks are injected |\n\n### extractScenarioFromLocation\n\n| Parameter | Type                                                                  | Required | Description                                                                                                      |\n| --------- | --------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------------------------------------------------- |\n| location  | [Location](https://developer.mozilla.org/en-US/docs/Web/API/Location) | ✅       | The browser location object. The value for the `scenario` part of the querystring will be extracted and returned |\n\n## Gotchas\n\n- GraphQL operations must have an operation name.\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrug%2Fdata-mocks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrug%2Fdata-mocks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrug%2Fdata-mocks/lists"}