{"_id":"@ambroos/graphql-codegen-preset-monorepo-client","_rev":"5-c2ee1c762ee786b3ca5037013ff1df9b","name":"@ambroos/graphql-codegen-preset-monorepo-client","dist-tags":{"latest":"1.1.1"},"versions":{"0.1.0-beta.1":{"name":"@ambroos/graphql-codegen-preset-monorepo-client","version":"0.1.0-beta.1","type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"default":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"main":"dist/index.js","module":"dist/index.js","typings":"dist/typings/index.d.ts","scripts":{"build":"tsc && vite build","format":"prettier --write ."},"dependencies":{"@graphql-codegen/add":"^5.0.0","@graphql-codegen/gql-tag-operations":"^4.0.1","@graphql-codegen/plugin-helpers":"^5.0.1","@graphql-codegen/typed-document-node":"^5.0.1","@graphql-codegen/typescript":"^4.0.1","@graphql-codegen/typescript-operations":"^4.0.1","@graphql-codegen/visitor-plugin-common":"^4.0.1","@graphql-tools/documents":"^1.0.0","@graphql-tools/utils":"^10.0.0","@graphql-typed-document-node/core":"3.2.0","tslib":"~2.6.0"},"devDependencies":{"@types/node":"^20.8.5","prettier":"^3.0.3","prettier-plugin-packagejson":"^2.4.6","typescript":"^5.0.2","vite":"^4.4.5","vite-plugin-dts":"^3.6.0","vite-plugin-externalize-deps":"^0.7.0"},"peerDependencies":{"graphql":"^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"},"_id":"@ambroos/graphql-codegen-preset-monorepo-client@0.1.0-beta.1","gitHead":"e48bbda3c63a3de991d328578a6499e9263cd15d","description":"Like client-preset, but with support for monorepos sharing a single schema, without duplicated types! Provides a graphql-codegen preset for:","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-nnhOs4RsxOp1YmXMimzAG5O2XXdsZWbs8supN7/OHKnc2tpy1yFE4cBVnC44slvUhDj04bDwBevLlBvJh/UzjQ==","shasum":"f475b033deffd29fcef2413b747db51a2d90221b","tarball":"https://registry.npmjs.org/@ambroos/graphql-codegen-preset-monorepo-client/-/graphql-codegen-preset-monorepo-client-0.1.0-beta.1.tgz","fileCount":10,"unpackedSize":54345,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIELvUcqIOfNaeep84h8t/NtLG3B/jRIjzcvmCsT+zraTAiEAvjRiDlWFtcZ5Fi9q4w9qG54rL/8RUV6UG6kSh7QvGHI="}]},"_npmUser":{"name":"ambroos","email":"ambroosv@gmail.com"},"directories":{},"maintainers":[{"name":"ambroos","email":"ambroosv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-codegen-preset-monorepo-client_0.1.0-beta.1_1697204588329_0.8104498508828815"},"_hasShrinkwrap":false,"deprecated":"versions before v1.1.1 had some minor issues making them less useful"},"0.1.0":{"name":"@ambroos/graphql-codegen-preset-monorepo-client","version":"0.1.0","repository":{"type":"git","url":"git+https://github.com/ambroos/graphql-codegen-preset-monorepo-client.git"},"type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"default":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"main":"dist/index.js","module":"dist/index.js","typings":"dist/typings/index.d.ts","scripts":{"build":"tsc && vite build","format":"prettier --write ."},"dependencies":{"@graphql-codegen/add":"^5.0.0","@graphql-codegen/gql-tag-operations":"^4.0.1","@graphql-codegen/plugin-helpers":"^5.0.1","@graphql-codegen/typed-document-node":"^5.0.1","@graphql-codegen/typescript":"^4.0.1","@graphql-codegen/typescript-operations":"^4.0.1","@graphql-codegen/visitor-plugin-common":"^4.0.1","@graphql-tools/documents":"^1.0.0","@graphql-tools/utils":"^10.0.0","@graphql-typed-document-node/core":"3.2.0","tslib":"~2.6.0"},"devDependencies":{"@types/node":"^20.8.5","prettier":"^3.0.3","prettier-plugin-packagejson":"^2.4.6","typescript":"^5.0.2","vite":"^4.4.5","vite-plugin-dts":"^3.6.0","vite-plugin-externalize-deps":"^0.7.0"},"peerDependencies":{"graphql":"^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"},"_id":"@ambroos/graphql-codegen-preset-monorepo-client@0.1.0","gitHead":"bdec92e7330a07601142e6a2a4f96fbaf6d92357","description":"Like client-preset, but with support for monorepos sharing a single schema, without duplicated types! Provides a graphql-codegen preset for:","bugs":{"url":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client/issues"},"homepage":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-8VkacByt5YH5qNGbFxK8/Mirfhb+xlNReCwcplfMdLVmNCUnm/j6+k22rZUczcLkFNgiwx9rRBAhTqrkKGbYLw==","shasum":"3f108f36948229f95ae9472acba253f7179a3db4","tarball":"https://registry.npmjs.org/@ambroos/graphql-codegen-preset-monorepo-client/-/graphql-codegen-preset-monorepo-client-0.1.0.tgz","fileCount":10,"unpackedSize":54411,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCNfKXXhpLzyM8PHp/Ot6osVZAViW4pF2kfFdHj1+552AIgUAInKO545Y2yq7Qm+IezeYiIbxPJQD2HhaOhlc3qmvs="}]},"_npmUser":{"name":"ambroos","email":"ambroosv@gmail.com"},"directories":{},"maintainers":[{"name":"ambroos","email":"ambroosv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-codegen-preset-monorepo-client_0.1.0_1697204806977_0.3441954441983117"},"_hasShrinkwrap":false,"deprecated":"versions before v1.1.1 had some minor issues making them less useful"},"1.0.0":{"name":"@ambroos/graphql-codegen-preset-monorepo-client","version":"1.0.0","repository":{"type":"git","url":"git+https://github.com/ambroos/graphql-codegen-preset-monorepo-client.git"},"license":"MIT","type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"default":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"main":"dist/index.js","module":"dist/index.js","typings":"dist/typings/index.d.ts","scripts":{"build":"tsc && vite build","format":"prettier --write ."},"dependencies":{"@graphql-codegen/add":"^5.0.0","@graphql-codegen/gql-tag-operations":"^4.0.1","@graphql-codegen/plugin-helpers":"^5.0.1","@graphql-codegen/typed-document-node":"^5.0.1","@graphql-codegen/typescript":"^4.0.1","@graphql-codegen/typescript-operations":"^4.0.1","@graphql-codegen/visitor-plugin-common":"^4.0.1","@graphql-tools/documents":"^1.0.0","@graphql-tools/utils":"^10.0.0","@graphql-typed-document-node/core":"3.2.0","tslib":"~2.6.0"},"devDependencies":{"@types/node":"^20.8.5","prettier":"^3.0.3","prettier-plugin-packagejson":"^2.4.6","typescript":"^5.0.2","vite":"^4.4.5","vite-plugin-dts":"^3.6.0","vite-plugin-externalize-deps":"^0.7.0"},"peerDependencies":{"graphql":"^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"},"_id":"@ambroos/graphql-codegen-preset-monorepo-client@1.0.0","gitHead":"399210c85f8617e404549279b00035d7a68e69b0","description":"Like client-preset, but with support for monorepos sharing a single schema, without duplicated types! Provides a graphql-codegen preset for:","bugs":{"url":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client/issues"},"homepage":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-lOGYi7kzumP+Wkz1tGnr3asp59NQpIGV+MHRdjEwY3VazgmrwCWZolvt4jaUMblEsOgJKNl0+1gm8Tj3VScZVQ==","shasum":"af17e3dc349ed9503d73400963e39af8ae5a367f","tarball":"https://registry.npmjs.org/@ambroos/graphql-codegen-preset-monorepo-client/-/graphql-codegen-preset-monorepo-client-1.0.0.tgz","fileCount":10,"unpackedSize":54487,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIA3PsWn7GXfGxp3YL/ATaJcjRNTL/M5HdQwn83/dDnCYAiA1uZHuEkqJPD3fKFsENzTyFdQPNVt99ibv3eHe/tpT+Q=="}]},"_npmUser":{"name":"ambroos","email":"ambroosv@gmail.com"},"directories":{},"maintainers":[{"name":"ambroos","email":"ambroosv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-codegen-preset-monorepo-client_1.0.0_1697205031731_0.4374883762441517"},"_hasShrinkwrap":false,"deprecated":"versions before v1.1.1 had some minor issues making them less useful"},"1.1.0":{"name":"@ambroos/graphql-codegen-preset-monorepo-client","version":"1.1.0","repository":{"type":"git","url":"git+https://github.com/ambroos/graphql-codegen-preset-monorepo-client.git"},"license":"MIT","type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"default":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"main":"dist/index.js","module":"dist/index.js","typings":"dist/typings/index.d.ts","scripts":{"build":"tsc && vite build","format":"prettier --write ."},"dependencies":{"@graphql-codegen/add":"^5.0.0","@graphql-codegen/gql-tag-operations":"^4.0.1","@graphql-codegen/plugin-helpers":"^5.0.1","@graphql-codegen/typed-document-node":"^5.0.1","@graphql-codegen/typescript":"^4.0.1","@graphql-codegen/typescript-operations":"^4.0.1","@graphql-codegen/visitor-plugin-common":"^4.0.1","@graphql-tools/documents":"^1.0.0","@graphql-tools/utils":"^10.0.0","@graphql-typed-document-node/core":"3.2.0","tslib":"~2.6.0"},"devDependencies":{"@types/node":"^20.8.5","prettier":"^3.0.3","prettier-plugin-packagejson":"^2.4.6","typescript":"^5.0.2","vite":"^4.4.5","vite-plugin-dts":"^3.6.0","vite-plugin-externalize-deps":"^0.7.0"},"peerDependencies":{"graphql":"^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"},"_id":"@ambroos/graphql-codegen-preset-monorepo-client@1.1.0","gitHead":"83f744073a5de915b9a07cc76d9ab1135decbd0d","description":"Like client-preset, but more opinionated and with support for monorepos sharing a single schema, without duplicated types! Provides a graphql-codegen preset for:","bugs":{"url":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client/issues"},"homepage":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-BbdKu3RTm6dNtY5lvFWwndfcJfCro0Y3WkWZdV2Stq+a7ni/wP4hNJkoWC370JLcYinfVBivserO4vI+/LOSIw==","shasum":"f0a3b4a9b476e9dc43f88c7199525e6a99b8abef","tarball":"https://registry.npmjs.org/@ambroos/graphql-codegen-preset-monorepo-client/-/graphql-codegen-preset-monorepo-client-1.1.0.tgz","fileCount":10,"unpackedSize":55905,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIDQ9wjaX3mfzQcuEENdsaPKKrN86Yb1GjaqcOj1ddB5MAiEA67bdW2FWCLpAylZMBID0il/fohlOq0vBhWEqDpVJHBI="}]},"_npmUser":{"name":"ambroos","email":"ambroosv@gmail.com"},"directories":{},"maintainers":[{"name":"ambroos","email":"ambroosv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-codegen-preset-monorepo-client_1.1.0_1697314776977_0.40670349891914825"},"_hasShrinkwrap":false,"deprecated":"versions before v1.1.1 had some minor issues making them less useful"},"1.1.1":{"name":"@ambroos/graphql-codegen-preset-monorepo-client","version":"1.1.1","repository":{"type":"git","url":"git+https://github.com/ambroos/graphql-codegen-preset-monorepo-client.git"},"license":"MIT","type":"module","exports":{".":{"import":{"types":"./dist/index.d.ts","default":"./dist/index.js"},"default":{"types":"./dist/index.d.ts","default":"./dist/index.js"}},"./package.json":"./package.json"},"main":"dist/index.js","module":"dist/index.js","typings":"dist/typings/index.d.ts","scripts":{"build":"tsc && vite build","format":"prettier --write ."},"dependencies":{"@graphql-codegen/add":"^5.0.0","@graphql-codegen/gql-tag-operations":"^4.0.1","@graphql-codegen/plugin-helpers":"^5.0.1","@graphql-codegen/typed-document-node":"^5.0.1","@graphql-codegen/typescript":"^4.0.1","@graphql-codegen/typescript-operations":"^4.0.1","@graphql-codegen/visitor-plugin-common":"^4.0.1","@graphql-tools/documents":"^1.0.0","@graphql-tools/utils":"^10.0.0","@graphql-typed-document-node/core":"3.2.0","tslib":"~2.6.0"},"devDependencies":{"@types/node":"^20.8.5","prettier":"^3.0.3","prettier-plugin-packagejson":"^2.4.6","typescript":"^5.0.2","vite":"^4.4.5","vite-plugin-dts":"^3.6.0","vite-plugin-externalize-deps":"^0.7.0"},"peerDependencies":{"graphql":"^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"},"_id":"@ambroos/graphql-codegen-preset-monorepo-client@1.1.1","gitHead":"3f593e42ef8821151dcfdfc7a563d1bc8278fffb","description":"Like client-preset, but more opinionated and with support for monorepos sharing a single schema, without duplicated types! Provides a graphql-codegen preset for:","bugs":{"url":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client/issues"},"homepage":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client#readme","_nodeVersion":"20.8.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-y7UbTl5osTx2ukeL6e052VWL7t6PVVD1XJ9yBnBgfxwKtK5YSGbkqih1gpr9+jr0of9g0JD1KKukaFei6iuddA==","shasum":"c50af4b0cc5b4668c027e26b3d3f98915a2c0b87","tarball":"https://registry.npmjs.org/@ambroos/graphql-codegen-preset-monorepo-client/-/graphql-codegen-preset-monorepo-client-1.1.1.tgz","fileCount":10,"unpackedSize":55905,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQC97Mu+vKu6aXslCrQxWrRZztLvOulNCX85NWkK7RiDhQIhALKa+pPYWCJYQ0rJoldeHkOUcQrOgy2jNlCXgACQm+1h"}]},"_npmUser":{"name":"ambroos","email":"ambroosv@gmail.com"},"directories":{},"maintainers":[{"name":"ambroos","email":"ambroosv@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/graphql-codegen-preset-monorepo-client_1.1.1_1697315289431_0.9593756455367903"},"_hasShrinkwrap":false}},"time":{"created":"2023-10-13T13:43:08.191Z","0.1.0-beta.1":"2023-10-13T13:43:08.488Z","modified":"2023-10-14T21:46:00.549Z","0.1.0":"2023-10-13T13:46:47.397Z","1.0.0":"2023-10-13T13:50:31.980Z","1.1.0":"2023-10-14T20:19:37.211Z","1.1.1":"2023-10-14T20:28:09.673Z"},"maintainers":[{"name":"ambroos","email":"ambroosv@gmail.com"}],"description":"Like client-preset, but more opinionated and with support for monorepos sharing a single schema, without duplicated types! Provides a graphql-codegen preset for:","readme":"# GraphQL codegen preset: Monorepo client\n\nLike client-preset, but more opinionated and with support for monorepos sharing a single schema, without duplicated types! Provides a graphql-codegen preset for:\n\n- schema packages: generates types for shared schema types only (enums, scalars and operation inputs)\n- feature packages: generates types for the queries and mutations from your feature package, and imports the schema types from the schema package\n\nThis is a variant of the [client preset package in the graphql-codegen repository](https://github.com/dotansimha/graphql-code-generator/tree/04d8781ff80b816a5735f86360559e1657108595/packages/presets/client) at the commit linked. fragment-masking-plugin.ts, persisted-documents.ts and process-sources.ts are practically unmodified from the original.\n\n**Sample repository using this preset in an Nx monorepo: [ambroos/sample-monorepo-graphql-codegen-project](https://github.com/ambroos/sample-monorepo-graphql-codegen-project)**\n\n## Installation\n\nAdjust for your favourite package manager.\n\n```bash\nnpm install --save-dev @ambroos/graphql-codegen-preset-monorepo-client @graphql-codegen/cli\nnpm install --save graphql\n```\n\n## Codegen setup\n\n### Schema package\n\nCreate a `codegen.ts` file in your schema package with the following content, adjust paths.\n\n```typescript\nimport { CodegenConfig } from \"@graphql-codegen/cli\";\nimport { schemaPreset } from \"@ambroos/graphql-codegen-preset-monorepo-client\";\n\nconst config: CodegenConfig = {\n  schema: \"./schema.graphql\",\n  generates: {\n    \"./src/gql/\": {\n      preset: schemaPreset,\n      // no presetConfig available for schemaPreset\n    },\n  },\n};\n\nexport default config;\n```\n\n### Feature package\n\nAnother `codegen.ts`, this time referencing where your schema package lives with `schemaTypesPath`. As long as what you put in `schemaTypesPath` works in this package in the sense of import \\* as types from '${schemaTypesPath}', you're good to go.\n\n```typescript\nimport { CodegenConfig } from \"@graphql-codegen/cli\";\nimport { packagePreset } from \"@ambroos/graphql-codegen-preset-monorepo-client\";\n\nconst config: CodegenConfig = {\n  schema: \"../graphql-schema/schema.graphql\", // adjust for your setup\n  documents: [\"src/**/*.tsx\"],\n  generates: {\n    \"./src/gql/\": {\n      preset: packagePreset,\n      presetConfig: {\n        // use this if your monorepo uses TypeScript paths (like Nx)\n        schemaTypesPath: \"@myorg/graphql-schema\",\n        // or, if your monorepo uses relative paths for imports from another package\n        schemaTypesPath: \"../graphql-schema/src/gql\",\n      },\n    },\n  },\n};\n\nexport default config;\n```\n\n### More configuration\n\nMany options from the standard @graphql-codegen/client-preset work for the feature preset from this package too. A few of them are set up by default:\n\n- schema: onlyOperationTypes is forced to true, since query/mutation types are generated for packages, full schema types are not needed. (If you need full schema types, just use `plugin: 'typescript'` to generate index.ts in your config instead of using schemaPreset - the package preset will still work.)\n- schema: enumsAsTypes and futureProofEnums are turned on by default, purely because I like them.\n- package: useTypeImports is forced on, there are no downsides AFAIK but please raise an issue if you disagree\n- package: immutableTypes is forced on, because you should not mutate your GraphQL data if you use fragments, since components downstream would also see the mutated data and not have any control about it\n- package: unmask function is renamed to `getFragmentData`\n\n## In code\n\n[Follow the \"Writing GraphQL Queries\" and \"Writing GraphQL Fragments\" guides from the GraphQL Codegen guide.](https://the-guild.dev/graphql/codegen/docs/guides/react-vue#writing-graphql-queries) **Note** that this preset uses `getFragmentData` instead of `useFragment` to get the data from a fragment.\n\n## Advanced topics\n\n### Optimizing bundles\n\nThe output is quite large because it includes strings for every GraphQL string twice, once in your source, once in generated code, along with an object representation of your query. To reduce this to only the object representation [you can use the Babel plugin or SWC plugin from the client preset](https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size).\n\nIf you get a build error when adding the SWC plugin, you likely are on a newer version of SWC than the plugin supports. [This fork of the SWC plugin is more up-to-date.](https://www.npmjs.com/package/@victorandree/graphql-codegen-client-preset-swc-plugin)\n\nExample Vite config:\n\n`npm install --save-dev @victorandree/graphql-codegen-client-preset-swc-plugin`\n\n```typescript\nimport react from '@vitejs/plugin-react-swc'\n\n// ... other things\nexport default defineConfig({\n  plugins: [\n    react({\n      plugins: [\n        [\n          '@victorandree/graphql-codegen-client-preset-swc-plugin',\n          { artifactDirectory: './src/gql', gqlTagName: 'graphql' },\n        ],\n      ],\n    }),\n//...\n```\n\n## Bonus: using with your Nx monorepo\n\nYou can use the codegen.ts configurations as shown above, with the following basic graphql-codegen executors. Update the paths to be relative to your repo root.\n\nAdd `graphql-codegen` to `cacheableOperations` in your `nx.json` to benefit from Nx caching when your schema/source hasn't changed.\n\n### Nx executors\n\nCreate a simple TS project in your workspace, and use the following executors:\n\n**In your schema package**\nI recommend using a script to pull your GraphQL schema from your server and plopping it in your schema package. After updating the schema, do a `nx run-many -t graphql-codegen` to rebuild the types for all your packages.\n\nYour schema package has a small `src/index.ts` that contains `export * from './gql'`\n\n```json\n{\n  \"targets\": {\n    \"graphql-codegen\": {\n      \"executor\": \"nx:run-commands\",\n      \"outputs\": [\"{projectRoot}/src/gql\"],\n      \"inputs\": [\"{projectRoot}/*.graphql\", \"{projectRoot}/codegen.ts\"],\n      \"options\": {\n        \"command\": \"npx graphql-codegen --config {projectRoot}/codegen.ts\"\n      }\n    }\n  }\n}\n```\n\n**In feature/other packages**\nAssuming your schema package lives in `libs/graphql-schema`:\n\nIf you use non-standard inputs or your schema lives in a different directory, you'll need to update the `inputs` and `outputs` fields. The setup provided here does the right caching for standard Nx monorepo setups.\n\n```json\n{\n  \"targets\": {\n    \"graphql-codegen\": {\n      \"executor\": \"nx:run-commands\",\n      \"outputs\": [\"{projectRoot}/src/gql\"],\n      \"inputs\": [\n        \"production\",\n        \"{projectRoot}/codegen.ts\",\n        \"{workspaceRoot}/libs/graphql-schema/*.graphql\"\n      ],\n      \"options\": {\n        \"command\": \"npx graphql-codegen --config {projectRoot}/codegen.ts\"\n      }\n    }\n  }\n}\n```\n\n### Nx generator to fetch a schema\n\nOnly needs `@nx/devkit` and `graphql` as dependencies. Add your own auth to the `getIntrospectionSchema` function.\n\n```typescript\nimport { Tree } from \"@nx/devkit\";\nimport { FetchGraphqlSchemaGeneratorSchema } from \"./schema\";\nimport { readFile } from \"fs/promises\";\nimport { buildClientSchema, getIntrospectionQuery, printSchema } from \"graphql\";\n\nasync function getIntrospectionSchema(token) {\n  return fetch(\"https://api.example.com/graphql\", {\n    method: \"POST\",\n    headers: {\n      Authorization: `Bearer ${token}`,\n      \"Content-Type\": \"application/json\",\n    },\n    body: JSON.stringify({ query: getIntrospectionQuery() }),\n  })\n    .then((res) => {\n      if (res.ok) {\n        return res;\n      }\n      throw new Error(`Failed to fetch schema: ${res.statusText}`);\n    })\n    .then((res) => res.json())\n    .then((res) => {\n      if (res.errors != null && res.errors.length > 0) {\n        throw new Error(\n          `Failed to fetch schema: ${res.errors\n            .map((e) => e.message)\n            .join(\", \")}`,\n        );\n      }\n      const schema = buildClientSchema(res.data);\n      return printSchema(schema);\n    });\n}\n\nexport async function fetchGraphqlSchemaGenerator(\n  tree: Tree,\n  options: FetchGraphqlSchemaGeneratorSchema,\n) {\n  const token = options.token;\n\n  if (token == null) {\n    console.error(\n      \"No token provided, please provide the right authentication to fetch your schema.\",\n    );\n    throw new Error();\n  }\n\n  const introspectionSchema = await getIntrospectionSchema(token);\n\n  tree.write(\"libs/graphql-schema/schema.graphql\", introspectionSchema);\n\n  console.log(\"✅ Schema is ready! You should now rerun your GraphQL codegen.\");\n}\n\nexport default fetchGraphqlSchemaGenerator;\n```\n","readmeFilename":"README.md","homepage":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client#readme","repository":{"type":"git","url":"git+https://github.com/ambroos/graphql-codegen-preset-monorepo-client.git"},"bugs":{"url":"https://github.com/ambroos/graphql-codegen-preset-monorepo-client/issues"},"license":"MIT"}