{"_id":"@4c/graphql-mocking","_rev":"8-c527271e86860aa1bd338c0b10adca86","name":"@4c/graphql-mocking","dist-tags":{"latest":"0.0.4"},"versions":{"0.0.1":{"name":"@4c/graphql-mocking","version":"0.0.1","main":"index.js","repository":{"type":"git","url":"git+https://github.com/4Catalyzer/graphql-mocking.git"},"author":{"name":"4Catalyzer"},"license":"MIT","publishConfig":{"access":"public"},"prettier":"@4c/prettier-config","gitHooks":{"pre-commit":"lint-staged"},"lint-staged":{"*":["yarn 4c lint --fix","git add"]},"jest":{"preset":"@4c/jest-preset","testEnvironment":"jsdom"},"release":{"conventionalCommits":true,"publishDir":"lib"},"dependencies":{"@graphql-tools/mock":"^8.1.3","@graphql-tools/schema":"^7.1.5","@graphql-tools/utils":"^7.10.0","@types/faker":"^5.5.6","@types/lodash":"^4.14.170","faker":"^5.5.3","graphql":"^15.5.0","graphql-relay":"^0.7.0","lodash":"^4.17.21","seed-random":"^2.2.0"},"bugs":{"url":"https://github.com/4Catalyzer/graphql-mocking/issues"},"homepage":"https://github.com/4Catalyzer/graphql-mocking#readme","_id":"@4c/graphql-mocking@0.0.1","_nodeVersion":"14.15.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-a2Z66HHTdLpe5xbm2OAYc76ojlDEdtY1xiciQlV5SXqAuluFqVYUMXYvSXhR8AkZOxLAnqEy5/j4eqs9Okh3wQ==","shasum":"f3bf49bfb1cf9a5f49962543f9975a650148baa5","tarball":"https://registry.npmjs.org/@4c/graphql-mocking/-/graphql-mocking-0.0.1.tgz","fileCount":14,"unpackedSize":33572,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJg9wsqCRA9TVsSAnZWagAAJv0QAJphpOipdHP3mqsUtnjg\nCe/LVY8De/cDE6ghQyQwmK2JVp/fgmYh/62gzftIaee2M7qqRUDAH5d6opoc\nCNbxYmfigc0mbIWlJ6UoE7KI+qM4E9zzjDlnJJrFza8yr9pW4JWaQV3btrW3\nrXP18+RRF7UyRb6HZ2Z+BQEST1xB5CF1Ix/KgM9847wkb/6T3MTIKNJz/eQk\nzsmeHTV4sPlSmVjkF2VRg8IQ0KxMtOCJUErmHwvvdjh4kOgTa9zFwZVPYot+\nEtiIaOR84AHOZM8aQqgeQTsQ88sNdSEUt5AMvVjIraYKUJ0933kGHojTsvWA\n+JiDBwz3Ra+8bB//mnKYdNmNOWltoXUQKIgoR+jaEQHEiZaCI9AgmhG6fAoR\n3dgTiGrtqoRxgwLU1vHIgNekYvwwRFTYQZ7Oy9t21dSvShIVHMQXtk1K/xrS\nXX5t0D/UFOXdUzEog9lQdXo6fjrpJIrG5fTVA6DgclF2Y9zofn9DiITMrLHh\n/QhwzOTHcnC0vPY72UaTkruwEIBBCkNqcVb++NwEV/Eh+GIZmPMWvaGM6Gk7\nY0rGZhsq+av4OjWTAkHlF7z56ENnEX8idk1U22eXB5NUe5Oxzsoqo2QCZTFJ\nOLGHejekLnQHtb/xSfl+Uos8meVeuUFEtfnOp+5n8STdGRxSLHfwZxXTTjum\nuXQC\r\n=D2Bk\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGEhQQaUOWfiXPGz2JutQaZeuVvqsAqgk0gAbu59gHyEAiBJmFUeJo/NZJpDwwoAscYmY9DlLgC9sCQNUCUP/oR1fg=="}]},"_npmUser":{"name":"monastic.panic","email":"monastic.panic@gmail.com"},"directories":{},"maintainers":[{"name":"monastic.panic","email":"monastic.panic@gmail.com"},{"name":"itajaja","email":"giacomo.tag@gmail.com"},{"name":"sloria","email":"sloria1@gmail.com"},{"name":"everes","email":"ethanveres@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mocking_0.0.1_1626802986457_0.5743023298537144"},"_hasShrinkwrap":false},"0.0.2":{"name":"@4c/graphql-mocking","version":"0.0.2","main":"index.js","repository":{"type":"git","url":"git+https://github.com/4Catalyzer/graphql-mocking.git"},"author":{"name":"4Catalyzer"},"license":"MIT","publishConfig":{"access":"public"},"prettier":"@4c/prettier-config","gitHooks":{"pre-commit":"lint-staged"},"lint-staged":{"*":["yarn 4c lint --fix","git add"]},"jest":{"preset":"@4c/jest-preset","testEnvironment":"jsdom"},"release":{"conventionalCommits":true,"publishDir":"lib"},"dependencies":{"@graphql-tools/mock":"^8.1.3","@graphql-tools/schema":"^7.1.5","@graphql-tools/utils":"^7.10.0","@types/faker":"^5.5.6","@types/lodash":"^4.14.170","faker":"^5.5.3","graphql":"^15.5.0","graphql-relay":"^0.7.0","lodash":"^4.17.21","seed-random":"^2.2.0"},"bugs":{"url":"https://github.com/4Catalyzer/graphql-mocking/issues"},"homepage":"https://github.com/4Catalyzer/graphql-mocking#readme","_id":"@4c/graphql-mocking@0.0.2","_nodeVersion":"14.15.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-4VW3j+5rMeS2iPVqtBcmIpkrgVdwheYuCKPjULu88nWJRsTTDkF9zifFNc9xQPvfIgOQ4SHpb93Pc/AlZWt2TA==","shasum":"f859bbae7ae2fa025152e390a8022f044f5fc2af","tarball":"https://registry.npmjs.org/@4c/graphql-mocking/-/graphql-mocking-0.0.2.tgz","fileCount":14,"unpackedSize":33819,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhDTgNCRA9TVsSAnZWagAA25kP/i4pbOkycYASfZ4uXMGn\nWqpFr7iJB1j6IpGe++4kJDs3P8u9vxRHzxDnYymu11p91vTwHwQgd+Uwn3s/\nimn90Ag5qhsEiXwH3nzCXwG2JpmxcXrhPRQ0Z0GATeWma8M/HToDG0/1jJA1\ns50TdPYgB18GVPK3J2TSltrAEYvzED52WPFoJ3J06Qbbl1ENs+B8YNkuFVc3\nwqGBAGitAsEgCsJu5pvKbtV2dsGYJc7NueILtWVaAbNmqIuq99rXlH9gGdZB\ngswZ0psM7bpSZ9+1jS/NqdI2B1geTSRjN/Qe1+I1csKF6saUEu4k4n4WIszQ\nbPCJvsuPau9HOlwzvfjj+U+h8uMG6lx9ZoutB3KU0Ha2qqasqYbfxmmEMnJ6\ncNRqLOuBOVZODBtq72QWaPAaICD6HB5Jqa4aBYaBkiUkzRb4KpsNyPRbc2nB\nBz/XuRtUQSqSzB3RgjSWUF3RyPi0EPA0i0+PUKv/kueAP4MJjjZkjn099Ymz\nYpgzY+3oy6B2dJlVimc+qoWKycMy9gStJ1YyfOGtk5cvhjdFjTK+pXQ5ZGjh\nsz2XscvjTagclRUWhEAaIKIUH2XooLb5pharLy5DYepoj4/w3IwVgwEz6S8w\nmG3FdOhskR2UYywAL2fTWTWlNH/sXgMDw4x+tiU+ENkgOPBWrksuBgW5sJ1E\n3eIj\r\n=gNLZ\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCMA/Uql71oj3w/wbcWL3WljPbZBSf/kARV9zujqXHJtAIgUj5y8Oev2kOc8LN6ndhQzYi4etZcwwYjbUs9DYP2QMI="}]},"_npmUser":{"name":"monastic.panic","email":"monastic.panic@gmail.com"},"directories":{},"maintainers":[{"name":"monastic.panic","email":"monastic.panic@gmail.com"},{"name":"itajaja","email":"giacomo.tag@gmail.com"},{"name":"sloria","email":"sloria1@gmail.com"},{"name":"everes","email":"ethanveres@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mocking_0.0.2_1628256269500_0.5633723981946737"},"_hasShrinkwrap":false},"0.0.3":{"name":"@4c/graphql-mocking","version":"0.0.3","main":"index.js","repository":{"type":"git","url":"git+https://github.com/4Catalyzer/graphql-mocking.git"},"author":{"name":"4Catalyzer"},"license":"MIT","publishConfig":{"access":"public"},"prettier":"@4c/prettier-config","gitHooks":{"pre-commit":"lint-staged"},"lint-staged":{"*":["yarn 4c lint --fix","git add"]},"jest":{"preset":"@4c/jest-preset","testEnvironment":"jsdom"},"release":{"conventionalCommits":true,"publishDir":"lib"},"dependencies":{"@graphql-tools/mock":"^8.1.3","@graphql-tools/schema":"^7.1.5","@graphql-tools/utils":"^7.10.0","@types/faker":"^5.5.6","@types/lodash":"^4.14.170","faker":"^5.5.3","graphql":"^15.5.0","graphql-relay":"^0.7.0","lodash":"^4.17.21","seed-random":"^2.2.0"},"bugs":{"url":"https://github.com/4Catalyzer/graphql-mocking/issues"},"homepage":"https://github.com/4Catalyzer/graphql-mocking#readme","_id":"@4c/graphql-mocking@0.0.3","_nodeVersion":"14.15.0","_npmVersion":"6.14.13","dist":{"integrity":"sha512-NbIZgXUoGDgvY3QaTyczk8Kqe5aBAlxen7lGV/UCmUOYARpjbqzyLTY07BQeDmKGnfANvtFmNQL4hbsoKNElyg==","shasum":"454b5f0598eb8269ec73ff98d7ed7f057b02ccb2","tarball":"https://registry.npmjs.org/@4c/graphql-mocking/-/graphql-mocking-0.0.3.tgz","fileCount":14,"unpackedSize":34600,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhEWhICRA9TVsSAnZWagAAy/sP/06Eckoly9Lcm4U5rORp\nACY8ntjoeOG5yd9IRgJIidbgYjxJV+y3KGhSx08xrGdEAwCLEdmsyAZB2Ium\n+ttXqQd9roVwQDLcO7RxNVxy6DklWKOWqgxqH/WuBZWZ32op5pXaYUE7HZoY\n/qXX7hSA8/DWkfA1E66CkN+CUtqet3TrAco2OnTm2/pEOkBjuQqfXF4fExnM\nUr+6KqSmm61rMeI5U2+es2471lM1b33ZTH3d0KbTUnWyRUBnoba21LkaW6n8\nC/Gl4V6ZUFPRcwl3bJ0oKzT8M36Q/sHfQ57taHJcJQjA01gIRX8yFA/dJyjd\nqjWZH3WLutiWTpc2AzdfZjOd+OovoAvZqlNhMKHchwYgEXpkB9aAFwhbOFGY\ntBEk9nGyTLVtyAm/te+UggYWd8mOC2kcq1kaVHT8i7Ka+M4x8566H4fw2ONr\nr/vRk0XXDbrmXz6qkjN95B0AXAhOOzhjC3rX5agm5cCa3cMQISn2E5IQA4+I\nLvOg2zVJYxklWXyj0JHm1wQc2Xia01AV2WomqVYFhwr03ZaoLKKUFtkhydcy\nD5TnC9jJDFlSjiXfyVOII58lsaNEOn8oJ0sq57hx7Zg5OO2kio2gIG+sdA65\nCik+lEHDsKJh41L0YbzN4RlFx+XI1u8JVVk0uFh8lTOX6J7cmn+ag+mMvw9N\n93Qj\r\n=19cm\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC73vTCpDMde/kcKK0YXhzeSm/zYdCJSAF5bvlfdiRxJwIhAOHGW2IusP3mEIPnRr73qWl3FHOMhXneCO+RqzDIyeVx"}]},"_npmUser":{"name":"monastic.panic","email":"monastic.panic@gmail.com"},"directories":{},"maintainers":[{"name":"monastic.panic","email":"monastic.panic@gmail.com"},{"name":"itajaja","email":"giacomo.tag@gmail.com"},{"name":"sloria","email":"sloria1@gmail.com"},{"name":"everes","email":"ethanveres@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mocking_0.0.3_1628530760283_0.019923666457025258"},"_hasShrinkwrap":false},"0.0.4":{"name":"@4c/graphql-mocking","version":"0.0.4","main":"index.js","repository":{"type":"git","url":"git+https://github.com/4Catalyzer/graphql-mocking.git"},"author":{"name":"4Catalyzer"},"license":"MIT","publishConfig":{"access":"public"},"prettier":"@4c/prettier-config","gitHooks":{"pre-commit":"lint-staged"},"lint-staged":{"*":["yarn 4c lint --fix","git add"]},"jest":{"preset":"@4c/jest-preset","testEnvironment":"jsdom"},"release":{"conventionalCommits":true,"publishDir":"lib"},"dependencies":{"@graphql-tools/mock":"^8.1.3","@graphql-tools/schema":"^7.1.5","@graphql-tools/utils":"^7.10.0","@types/faker":"^5.5.6","@types/lodash":"^4.14.170","faker":"^5.5.3","graphql":"^15.5.0","graphql-relay":"^0.7.0","lodash":"^4.17.21","seed-random":"^2.2.0"},"description":"Quickly mock out any GraphQL API with examples and augmented with smart autogenerated data.","bugs":{"url":"https://github.com/4Catalyzer/graphql-mocking/issues"},"homepage":"https://github.com/4Catalyzer/graphql-mocking#readme","_id":"@4c/graphql-mocking@0.0.4","_nodeVersion":"14.18.0","_npmVersion":"6.14.15","dist":{"integrity":"sha512-PJv9nd9gDNl9DJCGtLWfiaK8Azt4SxfpKYt5POLhdZWBwwFCM1jDYFHTcrBLhaBC8Ta1NCN3XSNcAcXXS9CTOw==","shasum":"7c9fb9b9a5ee5883d86c87e79a2087655e5fa3ce","tarball":"https://registry.npmjs.org/@4c/graphql-mocking/-/graphql-mocking-0.0.4.tgz","fileCount":15,"unpackedSize":46487,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJhuhl4CRA9TVsSAnZWagAABlAQAIbNzUFCOL9yl6SRp9Wj\nX2wy3IxYK87j037TqTuCaf30mvynekOL5OyJxYaWBcAcHTECZHDW4YkG7OHu\nt6qo9pViYmT7oeisqHfrnpz7rKRJ0+Mqti8w/fyXT4bnfsBWlR5ARnC5Yyil\nAv1lasi86vt8v28ZfnuW9p7LHTes+q5NjDK0U8D3My3j0MdkAKEWG45ywsur\nD9RSu8xN7Cyjk/Dalsq6Cu6DB9Q5rjxGoN9VoLAI8C/EycgQjx1DfGuYoxIp\n6Lpvlkgowr6tISBLzfhNtA5BXlKzbx9iGlOW5PU7nmkD2IzaPnnhI22TeaN5\nfhA1mpai0o0GWZUgcOmoTvoBBaG/NiGL4n6bGnT9aAKgVCFXI0QirhUcsKyA\naESNLwGnPs0uidlkBa5chcoI6CYp62SgH3gDkhg2QFSLln/Kb7lYnQn1irqP\nQl2dWm7XFJgKrQ0eh0DYbcPl4xIOLk5xuKa86/xoEDL0FZu/jc/leQ1MFdcK\nPNxs4ubP+rWMaujFfuT5ZyNOkD41zIrn+B+QlAArfr+FXRvoYRqcvbHudS+H\nHbqAJZ7JvTOa/9onqGM8C2w0l7IAudPYghN/PNlEGewRMJBjMOsWaY7zj9M2\nWYgw32VK4Y7WNxRyOUy9Iq2U159igmAGrQINTQxogTT9rQWuRPjDiUxzP+8J\nKgSZ\r\n=M9GL\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDhwkzzNPOsQG4O5A+vdyFvMcd6oheDjPXTsQztMhQWoAiEAkMvuQCmEpXIIpsw6jmx3TVE9FMdeNGpZJ+5VrnsikeI="}]},"_npmUser":{"name":"monastic.panic","email":"monastic.panic@gmail.com"},"directories":{},"maintainers":[{"name":"monastic.panic","email":"monastic.panic@gmail.com"},{"name":"itajaja","email":"giacomo.tag@gmail.com"},{"name":"sloria","email":"sloria1@gmail.com"},{"name":"everes","email":"ethanveres@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-mocking_0.0.4_1634933273631_0.7712497682992729"},"_hasShrinkwrap":false}},"time":{"created":"2021-07-20T17:43:06.393Z","0.0.1":"2021-07-20T17:43:06.601Z","modified":"2022-04-08T14:00:52.267Z","0.0.2":"2021-08-06T13:24:29.685Z","0.0.3":"2021-08-09T17:39:20.444Z","0.0.4":"2021-10-22T20:07:53.809Z"},"maintainers":[{"email":"stephen.liu@alumni.stanford.edu","name":"stephen_liu"},{"email":"monastic.panic@gmail.com","name":"monastic.panic"},{"email":"sloria1@gmail.com","name":"sloria"}],"homepage":"https://github.com/4Catalyzer/graphql-mocking#readme","repository":{"type":"git","url":"git+https://github.com/4Catalyzer/graphql-mocking.git"},"author":{"name":"4Catalyzer"},"bugs":{"url":"https://github.com/4Catalyzer/graphql-mocking/issues"},"license":"MIT","readme":"# GraphQL Mocking\n\nQuickly mock out any GraphQL API with examples and augmented with smart autogenerated data.\n\n## Overview\n\nAt a high level `graphql-mocking` is just a graphql-js \"server\" that processes\na request and resolves an return value. Instead of sourcing the data from an API\nor other backend, it uses an in memory graphql (like a simple ORM) built from\nexample data and data generated from type information.\n\nThe core export of `graphql-mocking` is a `MockStore` instance which encapsulates\na mocked GraphQL schema and the in memory data.\n\n```js\nimport Mocks from '@4c/graphql-mocking';\nimport graphql from from 'graphql';\n\nconst store = new Mocks(`\n  type Root {\n    person(id: ID): Person\n  }\n\n  type Person {\n    name: String\n  }\n\n  schema {\n    query: Root\n  }\n`)\n\nconst result = await graphql(store.mockedSchema, `\n  query {\n    person(id: 1) {\n      name\n    }\n  }\n`);\n```\n\nWithout any additional configuration `mockedSchema` will resolve valid\nqueries with seed generated data. Even better, a number of common\nschema patterns will be implemented automatically, such as Relay style\nConnections with pagination.\n\n### How data is generated.\n\nSince testing UIs backed by a GraphQL server is a main use case. It's not\nsufficient to simply generate randon data. Data that changes every run\nmakes for bad tests. To avoid this each field has access to a \"seeded\"\ndata generator, which means data will be consistently generated for that\nfield every time a resolution is run.\n\n## Customizing mocks\n\nGenerally fully generated data isn't sufficient for most mocking. Eventually\nyou want to add specific examples and custom mocking. To accomplish this we\nneed to introduce two concepts:\n\n- Mocks\n- Examples\n\n### Mocks\n\nMocks control schema resolution logic. They are similar\nin spirit to a GraphQL field resolver, expect they have a different \"pivot\".\nNormally a resolver is defined _per field_. A schema have many different\ntypes with the `Person` field type, and each one defines it's own resolver\nfrom the source object. Mocks, work _per type_ instead, meaning you can define\nhow \\*_any_ `Person` is resolved regardless of it's parent type.\n\nThis is a powerful way to define schema behavior without needing to\nclarify behavior for every usage of a type in your schema. For instance\nwe can implement a lookup for fields with arguments:\n\n```js\n// fake data\nconst people = {\n  1: { name: 'James' },\n  2: { name: 'Besty' },\n};\n\n// Mock the 'person' field on the tooy Query type\nstore.mock('Query', () => ({\n  person: (args, context, info) => people[args.id],\n}));\n\nconst result = await graphql(\n  store.mockedSchema,\n  gql`\n    query {\n      person(id: 1) {\n        name\n      }\n    }\n  `,\n);\n\nresult.data.person; // { name: 'James' }\n```\n\nMocks return a \"source\" object used by GraphQL to resolve the\nvalue of the type, you are mocking. For an overview of what this\nentails we suggest reading: https://graphql.org/graphql-js/object-types/\nbut quickly, mocks can return a concrete value, as in the case of scalars\nlike `String`, `Boolean`, etc. Or an object with functions that return a\nconcrete value.\n\n```js\nstore.mock('String', () => 'hello world'); // 'hello world' will be used for all strings\n\nstore.mock('Person', () => ({\n  name: () => generateName(),\n}));\n```\n\nAS seen in the person example above. Mock field resolvers are also based\nthe field arguments as well as the graphql `context` and `info` objects.\n\n### Examples\n\nExamples are static data for a graphql type, think of it as the data from\nyour database that provides the source objects for GraphQL resolution. For\ninstance the following are \"examples\" of a `Person` from our schema:\n\n```js\nconst people = store.addExamples('Person', [\n  {\n    id: 'a575bf7b-3eda-4015-98f9-6077a68a91e8',\n    name: 'James',\n    age: 68,\n  },\n  {\n    id: 'e78ac19b-6d06-401e-9ff4-6a4f20dea718',\n    name: 'Betsy',\n    age: 42,\n  },\n]);\n```\n\nWhen you add examples, they are used as a pool to pull from when\nresolving types. Examples don't need to be conprehensive,\nany fields in the GQL type that don't have a corresponding example\nfield will be generated normally.\n\nExamples often differ structurally from the GraphQL type they resolve to!\nFor instance our `Person` might look like:\n\n```graphql\ntype Person {\n  id: ID\n  personId: String\n  name: String!\n  isRetirementAge: Boolean\n}\n```\n\nHere instead of exposing `age` directly, Person defines `isRetirementAge` which\nis derived from age. However, when we try and add an example with `age` we get\nan error:\n\n```ts\nstore.addExample('Person', {\n  id: 'e78ac19b-6d06-401e-9ff4-6a4f20dea718',\n  name: 'Betsy',\n  age: 42,\n});\n\n// TypeError: `age does not exist on type Person`\n```\n\nThis is helpful guardrail to ensure that our mock data is explicit\nabout which properties map to GraphQL fields. If we want to\nexplicitly deviate we need to prefix our field with `$` to mark it\nas \"internal\".\n\n```ts\nstore.addExample('Person', {\n  id: 'e78ac19b-6d06-401e-9ff4-6a4f20dea718',\n  name: 'Betsy',\n\n  $age: 42,\n});\n```\n\nNow we can pair our example with a Mock to derive the correct\nvalue for `isRetirementAge`.\n\n```js\nconst store = new Mocks(schema);\n\nstore.addExample('Person', {\n  id: 'e78ac19b-6d06-401e-9ff4-6a4f20dea718',\n  name: 'Betsy',\n  age: 42,\n});\n\nstore.mock('Person', () => ({\n  isRetirementAge() {\n    // this is the source object in a graphql resolver\n    this.$age >= 65;\n  },\n}));\n```\n\n### Defining a graph\n\nExamples provide the mocked schema with concrete values to use\nwhen resolving types, as well as _defining_ relationships between\ndata in the graph. As with databases, examples should provide a\n**primary key** (by default either `id` or `$id`). Pks are used to create explicit\nrelationships between other examples in the graph.\n\nConsider the following schema defniing `Person` and blog `Post`:\n\n```graphql\ntype Post {\n  id: ID\n  title: String\n  content: String\n}\n\ntype Person {\n  id: ID\n  name: String!\n  posts: [Post]\n}\n```\n\nIf we wanted to add examples that defined links we could do so like:\n\n```ts\nstore.addExample('Person', [\n  {\n    id: 'person1',\n    name: 'James',\n  },\n  {\n    id: 'person2',\n    name: 'Betsy',\n  },\n]);\n\nstore.addExamples('Post', [\n  {\n    id: 'post1',\n    $personId: 'person1',\n    title: 'Building a graphql mocking library',\n  },\n  {\n    id: 'post2',\n    $personId: 'person1',\n    title: 'Funny looking birds',\n  },\n  {\n    id: 'post3',\n    $personId: 'person2',\n    title: 'The Ultimate Answer',\n  },\n]);\n```\n\nNow we can relate these two types with a mock using the built-in `related` helper\n\n```js\nimport { related } from '@4c/graphql-mocking';\n\nstore.mock('Person', () => ({\n  posts: related({\n    relatedFieldName: '$personId',\n    idField: '$id',\n  }),\n}));\n```\n\nnow when we query for posts on people it will \"Just Work\"\n\n```js\nconst result = await graphql(\n  store.mockedSchema,\n  gql`\n    query {\n      person(id: \"person1\") {\n        name\n        posts {\n          title\n        }\n      }\n    }\n  `,\n);\n// results in\ndata: {\n  person: {\n    name: 'James',\n    posts: [\n      { title: 'Building a graphql mocking library' },\n      { title: 'Funny looking birds' }\n    ]\n  }\n}\n```\n\n(This works for one-to-many or one-to-one relationships equally well).\n\nBecause this is such a common pattern, the library will automatically set up\nthese relationships if it can infer from the example and type.\n\n> Heads: Internal keys that end with `Id` are automatically\n> considered **foreign key** to it's connected type.\n\nThe mocking is also smart enough to infer fields as foreign keys\nif the schema type for the field is an object type and the example value\nis a string, it will assume it's an `id` reference.\n\n```js\nstore.addExamples('Post', [\n  {\n    $id: 'post1',\n    person: 'person1',\n    title: 'Building a graphql mocking library',\n  },\n```\n\nNo other configuration needed.\n\n### Connections and Relay\n\ngraphql-mocking, comes with out of the box support for Relay schema additions,\nwhich include:\n\n#### Node Interface\n\nWhen the schema has a `Node` interface and `node` query field, graphql-mocking\nwill automatically mock them to work with example data.\n\n```graphql\nquery {\n  node(id: \"RmlsbToy\") {\n    ... on Person {\n      name\n    }\n  }\n}\n```\n\n#### Global IDs\n\nIn addition a specialized `ID` scalar mock is configured to return Relay compatible \"global Ids\",\nwhich are base64 encodings of the type name and local identifier. **Note** this requires that\nexamples use a different field for their id than `id`, we recommend `$id` since it works out\nof the box.\n\n```js\nstore.addExample('Person', [\n  {\n    $id: 'person1',\n    name: 'James',\n  },\n  {\n    $id: 'person2',\n    name: 'Betsy',\n  },\n]);\n\nconst result = await graphql(\n  store.mockedSchema,\n  gql`\n    query {\n      people {\n        name\n      }\n    }\n  `,\n);\n```\n\n#### Connections\n\nPagination with connections also works out of the box just like `List` type\ngeneration and inference. Connections can also be configured directly via:\n\n```js\nimport { connection } from '@4c/graphql-mocking/relay';\n\nstore.mock('Person', {\n  postConnection: connection({ relatedIdField: '$personId' }),\n});\n```\n","readmeFilename":"README.md","description":"Quickly mock out any GraphQL API with examples and augmented with smart autogenerated data."}