{"_id":"@cruglobal/graphql-ergonomock","_rev":"10-42d9f1bbf0a826c90a39989825af0910","name":"@cruglobal/graphql-ergonomock","dist-tags":{"latest":"1.2.2"},"versions":{"1.2.0-beta.1":{"name":"@cruglobal/graphql-ergonomock","version":"1.2.0-beta.1","keywords":["apollo-client","apollo","factory","fixture","graphql","jest","mock","MockedProvider","mocking","mocks","resolvers","test","testing","typescript"],"author":{"name":"Joel Marcotte"},"license":"MIT","_id":"@cruglobal/graphql-ergonomock@1.2.0-beta.1","maintainers":[{"name":"canac-cru","email":"caleb.cox@cru.org"},{"name":"jcwatson11","email":"jon@sherlockwatson.com"},{"name":"daniel.bizz","email":"daniel@bizz-websites.com"},{"name":"frett","email":"daniel.frett@gmail.com"},{"name":"omicron7","email":"brian.zoetewey@cru.org"},{"name":"johnplastow","email":"john.plastow@cru.org"}],"dist":{"shasum":"5c07a2c68816950b8d69dd05385b2cf24e50e7f0","tarball":"https://registry.npmjs.org/@cruglobal/graphql-ergonomock/-/graphql-ergonomock-1.2.0-beta.1.tgz","fileCount":29,"integrity":"sha512-0KoDkHrrIE8FfV/NuUlul1J4eqvjAKNmIygkInLzyamaLIeU6VHOtsgMrnC+rlsTOna2cJ4nP4ww6nehpzvOpw==","signatures":[{"sig":"MEYCIQD1GfZdKajQDtnXT5FDEziGus3/TG8/r8cnmu3ZnNiN3QIhAJXEuejUBvHByCtuo/tOa+RhZzQ0zz7yCKVYhGEKYULv","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":52928},"main":"dist/index.js","scripts":{"test":"jest --coverage","build":"rimraf ./dist && tsc","prepublishOnly":"npm run build","semantic-release":"semantic-release"},"_npmUser":{"name":"canac-cru","email":"caleb.cox@cru.org"},"renovate":{"extends":["config:js-lib"]},"repository":{"url":"https://github.com/joual/graphql-ergonomock.git","type":"git"},"description":"Automatic mocking of GraphQL operations.","directories":{},"licenseText":"MIT License\n\nCopyright (c) 2020 Joel Marcotte\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"graphql":"^15.0.0","seedrandom":"^3.0.5","fast-json-stable-stringify":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"26.6.3","react":"17.0.2","ts-jest":"26.5.6","prettier":"2.3.2","react-dom":"17.0.2","typescript":"4.3.5","@types/react":"17.0.18","jest-extended":"0.11.5","@apollo/client":"3.4.8","@types/react-dom":"17.0.9","semantic-release":"17.4.5","@types/seedrandom":"3.0.1","@testing-library/react":"11.2.7","@testing-library/jest-dom":"5.14.1"},"_npmOperationalInternal":{"tmp":"tmp/graphql-ergonomock_1.2.0-beta.1_1730250803121_0.5209621668154183","host":"s3://npm-registry-packages"}},"1.2.0-beta.2":{"name":"@cruglobal/graphql-ergonomock","version":"1.2.0-beta.2","keywords":["apollo-client","apollo","factory","fixture","graphql","jest","mock","MockedProvider","mocking","mocks","resolvers","test","testing","typescript"],"author":{"name":"Joel Marcotte"},"license":"MIT","_id":"@cruglobal/graphql-ergonomock@1.2.0-beta.2","maintainers":[{"name":"canac-cru","email":"caleb.cox@cru.org"},{"name":"jcwatson11","email":"jon@sherlockwatson.com"},{"name":"daniel.bizz","email":"daniel@bizz-websites.com"},{"name":"frett","email":"daniel.frett@gmail.com"},{"name":"omicron7","email":"brian.zoetewey@cru.org"},{"name":"johnplastow","email":"john.plastow@cru.org"}],"dist":{"shasum":"de99ac69c512c8f4d88252eeea56c28de9eb5ae4","tarball":"https://registry.npmjs.org/@cruglobal/graphql-ergonomock/-/graphql-ergonomock-1.2.0-beta.2.tgz","fileCount":29,"integrity":"sha512-ZheY/tpZX27YlwYZ4F9NYteRgOPJ/10inUhAMDirGsPK/bwZQS759Zeo7NGLtBUGB8TGps8kIk2kQPZ7A9il5A==","signatures":[{"sig":"MEYCIQCm5Fgi4L7wme7Q8zLcDXxVBp25zonZbr4yYtB8jft2MgIhAMVUTxp+GOw+DUPc4sBguiWHGR0ybowBdikv/YhD52Rj","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":52928},"main":"dist/index.js","scripts":{"test":"jest --coverage","build":"rimraf ./dist && tsc","prepublishOnly":"npm run build","semantic-release":"semantic-release"},"_npmUser":{"name":"canac-cru","email":"caleb.cox@cru.org"},"renovate":{"extends":["config:js-lib"]},"repository":{"url":"https://github.com/joual/graphql-ergonomock.git","type":"git"},"description":"Automatic mocking of GraphQL operations.","directories":{},"licenseText":"MIT License\n\nCopyright (c) 2020 Joel Marcotte\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"graphql":"^15.0.0","seedrandom":"^3.0.5","fast-json-stable-stringify":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"26.6.3","react":"17.0.2","ts-jest":"26.5.6","prettier":"2.3.2","react-dom":"17.0.2","typescript":"4.3.5","@types/react":"17.0.18","jest-extended":"0.11.5","@apollo/client":"3.4.8","@types/react-dom":"17.0.9","semantic-release":"17.4.5","@types/seedrandom":"3.0.1","@testing-library/react":"11.2.7","@testing-library/jest-dom":"5.14.1"},"_npmOperationalInternal":{"tmp":"tmp/graphql-ergonomock_1.2.0-beta.2_1730250985189_0.4093439552703271","host":"s3://npm-registry-packages"}},"1.2.1":{"name":"@cruglobal/graphql-ergonomock","version":"1.2.1","keywords":["apollo-client","apollo","factory","fixture","graphql","jest","mock","MockedProvider","mocking","mocks","resolvers","test","testing","typescript"],"author":{"name":"Joel Marcotte"},"license":"MIT","_id":"@cruglobal/graphql-ergonomock@1.2.1","maintainers":[{"name":"canac-cru","email":"caleb.cox@cru.org"},{"name":"jcwatson11","email":"jon@sherlockwatson.com"},{"name":"daniel.bizz","email":"daniel@bizz-websites.com"},{"name":"frett","email":"daniel.frett@gmail.com"},{"name":"omicron7","email":"brian.zoetewey@cru.org"},{"name":"johnplastow","email":"john.plastow@cru.org"}],"dist":{"shasum":"e48b76ec309c27d6b2c6fe6ce8aa7b79f2895472","tarball":"https://registry.npmjs.org/@cruglobal/graphql-ergonomock/-/graphql-ergonomock-1.2.1.tgz","fileCount":26,"integrity":"sha512-9xpzLT4m2yvJqKegboxNFtU5RG4/JYPyxPfSAr3rUS5s33O2o4jqPOs6m7F+GPUU7ywl7s3BvBktqCwmuWHnnQ==","signatures":[{"sig":"MEYCIQCoBlCAcC6jekoNuKVNXt8N3hUjHuFF81W/C7W34RZ8cAIhAPECUDFTendPEGpEnPN9fCdCJ66qLKtqb+ykPuMK2rIz","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":52597},"main":"dist/index.js","scripts":{"test":"jest --coverage","build":"rimraf ./dist && tsc","prepublishOnly":"npm run build","semantic-release":"semantic-release"},"_npmUser":{"name":"canac-cru","email":"caleb.cox@cru.org"},"renovate":{"extends":["config:js-lib"]},"repository":{"url":"https://github.com/joual/graphql-ergonomock.git","type":"git"},"description":"Automatic mocking of GraphQL operations.","directories":{},"licenseText":"MIT License\n\nCopyright (c) 2020 Joel Marcotte\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"graphql":"^16.9.0","seedrandom":"^3.0.5","fast-json-stable-stringify":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"26.6.3","react":"17.0.2","ts-jest":"26.5.6","prettier":"2.3.2","react-dom":"17.0.2","typescript":"4.3.5","@types/react":"17.0.18","jest-extended":"0.11.5","@apollo/client":"3.4.8","@types/react-dom":"17.0.9","semantic-release":"17.4.5","@types/seedrandom":"3.0.1","@testing-library/react":"11.2.7","@testing-library/jest-dom":"5.14.1"},"_npmOperationalInternal":{"tmp":"tmp/graphql-ergonomock_1.2.1_1730393207424_0.3598479969796504","host":"s3://npm-registry-packages"}},"1.2.2":{"name":"@cruglobal/graphql-ergonomock","version":"1.2.2","keywords":["apollo-client","apollo","factory","fixture","graphql","jest","mock","MockedProvider","mocking","mocks","resolvers","test","testing","typescript"],"author":{"name":"Joel Marcotte"},"license":"MIT","_id":"@cruglobal/graphql-ergonomock@1.2.2","maintainers":[{"name":"canac-cru","email":"caleb.cox@cru.org"},{"name":"jcwatson11","email":"jon@sherlockwatson.com"},{"name":"daniel.bizz","email":"daniel@bizz-websites.com"},{"name":"frett","email":"daniel.frett@gmail.com"},{"name":"omicron7","email":"brian.zoetewey@cru.org"},{"name":"johnplastow","email":"john.plastow@cru.org"}],"dist":{"shasum":"b7d4dd603b2c8ce2485f631dea3607b1db235c9f","tarball":"https://registry.npmjs.org/@cruglobal/graphql-ergonomock/-/graphql-ergonomock-1.2.2.tgz","fileCount":26,"integrity":"sha512-qrm4nI6jMGjmq7Ce9zXNHrDyTba8o+ihMXh4OvtLAkj2nDIWdvNKumKvMra5XaLEwYD1RG64dCHjbFmyj+qBoQ==","signatures":[{"sig":"MEYCIQDcHHtEh0MWvb9ah607ohWYl6B/0FJjYFRfX4btaf76GAIhAM0c8SgkqRRqbl+FzM52Dekaz/xyOCaJKeF2DrufIxPM","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":53067},"main":"dist/index.js","scripts":{"test":"jest --coverage","build":"rimraf ./dist && tsc","prepublishOnly":"npm run build","semantic-release":"semantic-release"},"_npmUser":{"name":"canac-cru","email":"caleb.cox@cru.org"},"renovate":{"extends":["config:js-lib"]},"repository":{"url":"https://github.com/joual/graphql-ergonomock.git","type":"git"},"description":"Automatic mocking of GraphQL operations.","directories":{},"licenseText":"MIT License\n\nCopyright (c) 2020 Joel Marcotte\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","dependencies":{"graphql":"^16.9.0","seedrandom":"^3.0.5","fast-json-stable-stringify":"^2.1.0"},"_hasShrinkwrap":false,"devDependencies":{"jest":"26.6.3","react":"17.0.2","ts-jest":"26.5.6","prettier":"2.3.2","react-dom":"17.0.2","typescript":"4.3.5","@types/react":"17.0.18","jest-extended":"0.11.5","@apollo/client":"3.4.8","@types/react-dom":"17.0.9","semantic-release":"17.4.5","@types/seedrandom":"3.0.1","@testing-library/react":"11.2.7","@testing-library/jest-dom":"5.14.1"},"_npmOperationalInternal":{"tmp":"tmp/graphql-ergonomock_1.2.2_1731688429689_0.2057406260109753","host":"s3://npm-registry-packages"}}},"time":{"created":"2024-10-30T01:13:23.021Z","modified":"2026-08-25T17:24:26.309Z","1.2.0-beta.1":"2024-10-30T01:13:23.417Z","1.2.0-beta.2":"2024-10-30T01:16:25.462Z","1.2.1":"2024-10-31T16:46:47.617Z","1.2.2":"2024-11-15T16:33:49.964Z"},"author":{"name":"Joel Marcotte"},"license":"MIT","keywords":["apollo-client","apollo","factory","fixture","graphql","jest","mock","MockedProvider","mocking","mocks","resolvers","test","testing","typescript"],"repository":{"url":"https://github.com/joual/graphql-ergonomock.git","type":"git"},"description":"Automatic mocking of GraphQL operations.","maintainers":[{"email":"josh.starcher@cru.org","name":"twinge"},{"email":"jon@sherlockwatson.com","name":"jcwatson11"},{"email":"caleb.cox@cru.org","name":"canac-cru"},{"email":"daniel.frett@gmail.com","name":"frett"},{"email":"daniel@bizz-websites.com","name":"daniel.bizz"},{"email":"brian.zoetewey@cru.org","name":"omicron7"},{"email":"ryan.guinee@cru.org","name":"rwguinee"},{"email":"william.james@cru.org","name":"wjames1111"}],"readme":"\n<!-- PROJECT SHIELDS -->\n<!--\n*** I'm using markdown \"reference style\" links for readability.\n*** Reference links are enclosed in brackets [ ] instead of parentheses ( ).\n*** See the bottom of this document for the declaration of the reference variables\n*** for contributors-url, forks-url, etc. This is an optional, concise syntax you may use.\n*** https://www.markdownguide.org/basic-syntax/#reference-style-links\n-->\n[![CircleCI][circleci-shield]][circleci-url]\n[![CodeCov][codecov-shield]][codecov-url]\n[![Contributors][contributors-shield]][contributors-url]\n[![Forks][forks-shield]][forks-url]\n[![Stargazers][stars-shield]][stars-url]\n[![Issues][issues-shield]][issues-url]\n[![Version][version-shield]][version-url]\n[![MIT License][license-shield]][license-url]\n\n\n\n<!-- PROJECT LOGO -->\n<br />\n<p align=\"center\">\n  <a href=\"https://github.com/SurveyMonkey/graphql-ergonomock\">\n  </a>\n\n  <h3 align=\"center\">GraphQL Ergonomock</h3>\n\n  <p align=\"center\">\n    🔮 Developer-friendly automagical mocking for GraphQL\n    <br />\n    <a href=\"https://github.com/SurveyMonkey/graphql-ergonomock/issues\">Report Bug</a>\n    ·\n    <a href=\"https://github.com/SurveyMonkey/graphql-ergonomock/issues\">Request Feature</a>\n  </p>\n</p>\n\n\n\n<!-- TABLE OF CONTENTS -->\n## Table of Contents\n\n- [Table of Contents](#table-of-contents)\n- [About The Project](#about-the-project)\n  - [Basic Example](#basic-example)\n  - [Basic Example (Apollo)](#basic-example-apollo)\n  - [Built With](#built-with)\n- [Getting Started](#getting-started)\n  - [Installation](#installation)\n  - [Usage](#usage)\n    - [Default Case](#default-case)\n    - [ErgonoMockedProvider for Use with Apollo-Client](#ergonomockedprovider-for-use-with-apollo-client)\n    - [Providing Functions as Resolver in the Mock Shape](#providing-functions-as-resolver-in-the-mock-shape)\n    - [Mocking Errors](#mocking-errors)\n    - [Mocking Mutations](#mocking-mutations)\n- [API](#api)\n  - [`ergonomock()`](#ergonomock)\n  - [`<ErgonoMockedProvider>`](#ergonomockedprovider)\n- [Roadmap](#roadmap)\n- [Contributing](#contributing)\n- [License](#license)\n- [Contact](#contact)\n- [Acknowledgements](#acknowledgements)\n\n\n\n<!-- ABOUT THE PROJECT -->\n## About The Project\n\nThis library provides a developer-friendly method to mock your GraphQL requests. By default, it ships with the following features:\n\n* **Automatic mocking** of types and fields based on schema definition.\n* **Deterministic randomization** of mocked values based on the provided mock shape, to support usage of features such as snapshots.\n* Support for queries using **fragments, unions & interfaces**.\n* Allows usage of **functions as mock values**, which have the signature of a GraphQL resolver, and are resolved at runtime.\n\n### Basic Example\n\n```js\nimport { ergonomock } from 'graphql-ergonomock';\n\n// Given a particular GraphQL Schema, ...\nconst schema = gql`\n  type Shape {\n    id: ID!\n    returnInt: Int\n    nestedShape: Shape\n    returnBoolean: Boolean\n  }\n\n  type Query {\n    getShape: Shape\n  }\n`;\n\n// ...a GraphQL query, ...\nconst query = gql`\n{\n  getShape {\n    id\n    nestedShape {\n      returnInt\n      nestedShape {\n        returnInt\n        returnBoolean\n      }\n    }\n  }\n}\n`;\n\n// ...and a partial, possibly nested shape of data...\nconst mocks = {\n  getShape: {\n    nestedShape: {\n      returnInt: 5,\n      nestedShape: {\n        returnInt: 10\n      }\n    }\n  }\n};\n\n// ... provides the expected object filled with mock data\nconst resp = ergonomock(schema, query, { mocks });\nexpect(resp.data).toMatchObject({\n  id: expect.toBeString(),\n  nestedShape: {\n    returnInt: 5,\n    nestedShape: {\n      returnInt: 10,\n      returnBoolean: expect.toBeBoolean()\n    }\n  }\n}); // ✅ test pass\n```\n\n### Basic Example (Apollo)\n\n```js\nimport { ErgonoMockedProvider as MockedProvider } from \"graphql-ergonomock\";\n\n// Given a particular GraphQL Schema, ...\nconst schema = gql`\n  type Shape {\n    id: ID!\n    returnString: String\n    returnBoolean: Boolean\n  }\n\n  type Query {\n    getShape: Shape\n  }\n`;\n\n// ...a component making a query ...\nconst QUERY = gql`\nquery MyQuery {\n  getShape {\n    id\n    returnString\n    returnBoolean\n  }\n}\n`;\nconst MyComponent = () => {\n  const { loading, error, data } = useQuery(QUERY);\n  if (loading) return <p>Loading</p>;\n  if (error) return <p>Error</p>;\n\n  return (\n    <div>\n      MyComponent.\n      <div>String: {data.getShape.returnString}</div>\n      <div>Boolean: {data.getShape.returnBoolean.toString()}</div>\n    </div>\n  );\n};\n\ntest(\"MyComponent can render the query results.\", async () => {\n  const mocks = {\n    MyQuery: {\n      getShape: { returnString: \"John Doe\" }\n    }\n  };\n  const { findByText } = render(\n    <MockedProvider schema={schema} mocks={mocks}>\n      <MyComponent />\n    </MockedProvider>\n  );\n  expect(await findByText(/String: John Doe/)).toBeVisible();\n  expect(await findByText(/Boolean: (true|false)/)).toBeVisible();\n}); // ✅ test pass\n```\n\n### Built With\n* [Typescript](https://www.typescriptlang.org/)\n* [GraphQL](https://graphql.org)\n* [Jest](https://jestjs.io)\n\n\n\n<!-- GETTING STARTED -->\n## Getting Started\n\n### Installation\n\n```shell\nnpm i graphql-ergonomock --save-dev\n```\n\n<!-- USAGE EXAMPLES -->\n### Usage\n\n#### Default Case\nThe `ergonomock()` function can be used on its own to create mock responses out of GraphQL queries.\n\n<details>\n<summary>See example</summary>\n<p>\n\n```js\nimport { ergonomock } from 'graphql-ergonomock';\nimport schema from '../my-schema.graphql';\n\ntest(\"I can mock a response\", () => {\n  const resp = ergonomock(schema, 'query MyCrucialOperation { car { id, plateNumber } }', {\n    mocks: { car: { plateNumber: '123abc' } }\n  });\n\n  expect(resp).toMatchObject({\n    data: {\n      car: {\n        id: expect.toBeString(),\n        plateNumber: '123abc'\n      }\n    }\n  });\n});\n```\n</p>\n</details>\n\n#### ErgonoMockedProvider for Use with Apollo-Client\n\nIf your app uses Apollo-Client, you can also use `ErgonoMockedProvider` which wraps `ergonomock()`. The generated values are stable & deterministic based on the query name, shape, and variables (this is so you can leverage testing snapshots if you are so inclined).\n\n<details>\n<summary>See example</summary>\n<p>\n\n```jsx\nimport { ErgonoMockedProvider as MockedProvider } from 'graphql-ergonomock';\nimport schema from '../my-schema.graphql';\n\ntest(\"I can mock a response\", () => {\n  const mocks = {\n    MyCrucialOperation: {\n      car: { plateNumber: '123abc' }\n    }\n  };\n  const { findByText } = render(\n    <MockedProvider schema={schema} mocks={mocks}>\n      <MyApp />\n    </MockedProvider>\n  );\n  expect(await findByText(/'123abc'/)).toBeVisible();\n});\n```\n</p>\n</details>\n\nIf a particular component is called multiple times in the React tree (but with different variables), you can provide a function as value for an operation, and the function will be called with the `operation: GraphQLOperation` as first and only argument.\n<br />\n<details>\n<summary>See example</summary>\n<p>\n\n```jsx\nimport { ErgonoMockedProvider as MockedProvider } from 'graphql-ergonomock';\nimport schema from '../my-schema.graphql';\n\ntest(\"I can mock a response with a function\", () => {\n  let cardinality = 0;\n  const mocks = {\n    MyCrucialOperation: (operation) => ({ plateNumber: `aaa00${cardinality++}` })\n  };\n  const { findAllByText } = render(\n    <MockedProvider schema={schema} mocks={mocks}>\n      <MyApp />\n    </MockedProvider>\n  );\n  expect(await findAllByText(/'aaa00'/)).toHaveLength(3);\n});\n```\n</p></details>\n\nFinally, you can spy on executed operations via the `onCall` prop.\n<br />\n<details>\n<summary>See example</summary><p>\n\n```jsx\nconst spy = jest.fn();\nconst { findByText } = render(\n  <MockedProvider schema={schema} onCall={spy}>\n    <MyComponent id=\"1\" />\n    <MyComponent id=\"2\" />\n    <MyComponent id=\"3\" />\n  </MockedProvider>\n);\n\n//...\nexpect(spy.mock.calls).toHaveLength(3);\nconst { operation, response } = spy.mock.calls[0][0];\nexpect(operation.variables.id).toEqual(\"1\");\n```\n</p></details>\n\n\n\n\n#### Providing Functions as Resolver in the Mock Shape\n\nYou can use functions for any part of the nested mock, and it will be used as a resolver for this field. The typical signature for a resolver is `(root, args, context, info) => any`.\n\n<details>\n<summary>See example</summary><p>\n\n```js\n// ...\nconst mocks = {\n  returnShape: {\n    returnInt: 4321,\n    nestedShape: (root: any, args: any, ctx: any, info: any) => {\n      return {\n        returnInt: root.someField ? 1234 : 5678\n      };\n    }\n  }\n}\n//...\n```\n</p></details>\n\n\n#### Providing default mock resolver functions\n\nIf you have custom scalar types or would like to provide default mock resolver functions for certain types, you can pass your mock functions via the `resolvers` option.\n\n<details>\n<summary>See example</summary><p>\n\n```js\nconst schema = gql`\n  type Shape = {\n    id: ID!\n    returnInt: Int\n    date: Date\n    nestedShape: Shape\n  }\n\n  type Query {\n    getShape: Shape\n  }\n`;\n\nconst testQuery = gql`\n{\n  getShape {\n    id\n    returnInt\n    date\n    nestedShape {\n      date\n    }\n  }\n}\n`;\n\nconst resp = ergonomock(schema, testQuery, {\n  resolvers: {\n    Date: () => \"2021-04-09\"\n  }\n});\nexpect(resp.data).toMatchObject({\n  id: expect.toBeString(),\n  returnInt: expect.toBeNumber(),\n  date: '2021-04-09'\n  nestedShape {\n    date: '2021-04-09'\n  }\n});\n```\n</p></details>\n\n#### Mocking Errors\n\nYou can return or throw errors within the mock shape.\n\n<details>\n<summary>See example</summary><p>\n\n```js\nconst testQuery = gql`\n  {\n    getCar {\n      id\n    }\n  }\n`;\n\nconst resp = ergonomock(schema, testQuery, {\n  mocks: {\n    getCar: () => { throw new Error(\"Server Error\"); }\n    // or simply getCar: new Error(\"Server Error\")\n  }\n});\n\nconsole.log(resp.data.getCar); // null\nconsole.log(resp.errors[0]); // { message: \"Server Error\", ...}\n```\n</p></details>\n\n\n#### Mocking Mutations\n\nYou can mock mutations, but if you are using `ergonomock()` directly, you'll have to provide the correct variables for the operation in order for it to not fail.\n\n<details>\n<summary>See example</summary><p>\n\n```jsx\ntest(\"Can partially mock mutations\", () => {\n  const query = /* GraphQL */ `\n    mutation SampleQuery($input: ShapeInput!) {\n      createShape(input: $input) {\n        id\n        returnInt\n        returnString\n      }\n    }\n  `;\n\n  const resp: any = ergonomock(schema, query, {\n    mocks: {\n      createShape: { id: \"567\" }\n    },\n    variables: {\n      input: { someID: \"123\", someInt: 123 }\n    }\n  });\n\n  expect(resp.data.createShape).toMatchObject({\n    id: \"567\",\n    returnInt: expect.toBeNumber(),\n    returnString: expect.toBeString()\n  });\n});\n```\n</p></details>\n\n\n## API\n\n### `ergonomock()`\n\nThe `ergonomock(schema, query, options)` function takes 3 arguments\n\n1. _(required)_ A GraphQL **schema** (not in SDL form).\n2. _(required)_ A GraphQL **query**, either in SDL (string) form, or `DocumentNode`.\n3. _(optional)_ An option object.\n   1. `mocks` is an object that can partially or fully match the expected response shape.\n   2. `seed` is a string used to seed the random number generator for automocked values.\n   3. `variables` is the variable values object used in the query or mutation.\n\n\n### `<ErgonoMockedProvider>`\n\nThis component's props are very similar to Apollo-Client's [MockedProvider](https://www.apollographql.com/docs/react/api/react-testing/#mockedprovider). The only differences are:\n\n- `mocks` is an object where keys are the operation names and the values are the `mocks` input that `ergonomock()` would accept. (i.e. could be empty, or any shape that matches the expected response.)\n- `onCall` is a handler that gets called by any executed query. The call signature is `({operation: GraphQLOperation, response: any}) => void` where response is the full response being returned to that single query. The purpose of `onCall` is to provide some sort of spy (or `jest.fn()`) to make assertions on which calls went through, with which variables, and get a handle on the generated values from `ergonomock()`.\n- `resolvers` is an object where the keys are the `gql` type and the values are the mock resolver functions. It's designed to allow users to override or provide a default mock function for certain types. (e.g. custom scalar types) The call signature is `(root, args, context, info) => any`.\n\n<!-- ROADMAP -->\n## Roadmap\n\nSee the [open issues](https://github.com/SurveyMonkey/graphql-ergonomock/issues) for a list of proposed features (and known issues).\n\n\n<!-- CONTRIBUTING -->\n## Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the Project\n2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n4. Push to the Branch (`git push origin feature/AmazingFeature`)\n5. Open a Pull Request\n\n\n\n<!-- LICENSE -->\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n\n<!-- CONTACT -->\n## Contact\n\nMaintainer: Joel Marcotte (Github [@joual](https://github.com/joual))\n\nProject Link: [https://github.com/SurveyMonkey/graphql-ergonomock](https://github.com/SurveyMonkey/graphql-ergonomock)\n\n\n<!-- ACKNOWLEDGEMENTS -->\n## Acknowledgements\n\n* [A new approach to mocking GraphQL Data](https://www.freecodecamp.org/news/a-new-approach-to-mocking-graphql-data-1ef49de3d491/)\n* [GraphQL-Tools](https://github.com/apollographql/graphql-tools)\n* [GraphQL-JS](https://github.com/graphql/graphql-js)\n\n\n<!-- MARKDOWN LINKS & IMAGES -->\n<!-- https://www.markdownguide.org/basic-syntax/#reference-style-links -->\n[contributors-shield]: https://img.shields.io/github/contributors/SurveyMonkey/graphql-ergonomock.svg?style=flat-square\n[contributors-url]: https://github.com/SurveyMonkey/graphql-ergonomock/graphs/contributors\n[forks-shield]: https://img.shields.io/github/forks/SurveyMonkey/graphql-ergonomock.svg?style=flat-square\n[forks-url]: https://github.com/SurveyMonkey/graphql-ergonomock/network/members\n[stars-shield]: https://img.shields.io/github/stars/SurveyMonkey/graphql-ergonomock.svg?style=flat-square\n[stars-url]: https://github.com/SurveyMonkey/graphql-ergonomock/stargazers\n[version-url]:https://www.npmjs.com/package/graphql-ergonomock\n[version-shield]:https://img.shields.io/npm/v/graphql-ergonomock.svg?style=flat-square\n[issues-shield]: https://img.shields.io/github/issues/SurveyMonkey/graphql-ergonomock.svg?style=flat-square\n[issues-url]: https://github.com/SurveyMonkey/graphql-ergonomock/issues\n[license-shield]: https://img.shields.io/github/license/SurveyMonkey/graphql-ergonomock.svg?style=flat-square\n[license-url]: https://github.com/SurveyMonkey/graphql-ergonomock/blob/master/LICENSE.txt\n[circleci-shield]: https://circleci.com/gh/SurveyMonkey/graphql-ergonomock.svg?style=shield\n[circleci-url]: https://app.circleci.com/pipelines/github/SurveyMonkey/graphql-ergonomock\n[codecov-shield]: https://codecov.io/gh/SurveyMonkey/graphql-ergonomock/branch/master/graph/badge.svg\n[codecov-url]: https://codecov.io/gh/SurveyMonkey/graphql-ergonomock\n","readmeFilename":"README.md"}