diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index db8c15f6cda..c9264b7cc37 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -2,4 +2,6 @@ blank_issues_enabled: false contact_links: - name: Have a question? url: https://github.com/dotansimha/graphql-code-generator/discussions/new - about: Not sure about something? need help from the community? have a question to our team? please ask and answer questions here. + about: + Not sure about something? need help from the community? have a question to our team? please + ask and answer questions here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index ce2206a3017..d258ab201d7 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -46,7 +46,9 @@ body: id: description attributes: label: Is your feature request related to a problem? Please describe. - description: "A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]" + description: + "A clear and concise description of what the problem is. Ex. I'm always frustrated when + [...]" validations: required: true - type: textarea @@ -60,7 +62,8 @@ body: id: alternatives attributes: label: Describe alternatives you've considered - description: "A clear and concise description of any alternative solutions or features you've considered." + description: + "A clear and concise description of any alternative solutions or features you've considered." validations: required: false - type: textarea diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 6e1585c7256..faed239ed87 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,10 +1,12 @@ 🚨 **IMPORTANT: Please do not create a Pull Request without creating an issue first.** -_Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of the pull request._ +_Any change needs to be discussed before proceeding. Failure to do so may result in the rejection of +the pull request._ ## Description -Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. +Please include a summary of the change and which issue is fixed. Please also include relevant +motivation and context. List any dependencies that are required for this change. Related # (issue) @@ -18,16 +20,19 @@ Please delete options that are not relevant. - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as + expected) - [ ] This change requires a documentation update ## Screenshots/Sandbox (if appropriate/relevant): -Adding links to sandbox or providing screenshots can help us understand more about this PR and take action on it as appropriate +Adding links to sandbox or providing screenshots can help us understand more about this PR and take +action on it as appropriate ## How Has This Been Tested? -Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration +Please describe the tests that you ran to verify your changes. Provide instructions so we can +reproduce. Please also list any relevant details for your test configuration - [ ] Test A - [ ] Test B @@ -40,7 +45,9 @@ Please describe the tests that you ran to verify your changes. Provide instructi ## Checklist: -- [ ] I have followed the [CONTRIBUTING](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md) doc and the style guidelines of this project +- [ ] I have followed the + [CONTRIBUTING](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md) doc and the + style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation @@ -51,4 +58,5 @@ Please describe the tests that you ran to verify your changes. Provide instructi ## Further comments -If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... +If this is a relatively large or complex change, kick off the discussion by explaining why you chose +the solution you did and what alternatives you considered, etc... diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index b57dd5d69a6..1cd9fd8859d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -105,7 +105,9 @@ jobs: - name: Test ESM & CJS integrity run: yarn bob check test: - name: Unit Test on Node ${{matrix.node_version}} (${{matrix.os}}) and GraphQL v${{matrix.graphql_version}} + name: + Unit Test on Node ${{matrix.node_version}} (${{matrix.os}}) and GraphQL + v${{matrix.graphql_version}} runs-on: ubuntu-latest needs: - lint diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index 18a1a4527d1..7d6d023903e 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -11,7 +11,9 @@ on: jobs: deployment: runs-on: ubuntu-latest - if: github.event.pull_request.head.repo.full_name == github.repository || github.event_name == 'push' + if: + github.event.pull_request.head.repo.full_name == github.repository || github.event_name == + 'push' steps: - name: checkout uses: actions/checkout@v4 @@ -28,7 +30,9 @@ jobs: name: build and deploy website env: NEXT_BASE_PATH: ${{ github.ref == 'refs/heads/master' && '/graphql/codegen' || '' }} - SITE_URL: ${{ github.ref == 'refs/heads/master' && 'https://the-guild.dev/graphql/codegen' || '' }} + SITE_URL: + ${{ github.ref == 'refs/heads/master' && 'https://the-guild.dev/graphql/codegen' || '' + }} with: cloudflareApiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} cloudflareAccountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} diff --git a/.prettierignore b/.prettierignore index e265857872d..8e22ce437af 100644 --- a/.prettierignore +++ b/.prettierignore @@ -30,3 +30,5 @@ website/src/components/live-demo/LiveDemo.tsx # This should be added bc our rust test setup for the SWC plugin does a string diff, and it fails # bc it compares imports with double quotes against the formatted perttier single quotes packages/presets/swc-plugin/tests/fixtures + +*.flow.js diff --git a/.vscode/launch.json b/.vscode/launch.json index a9d9cae09f0..89eef2be430 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -5,7 +5,12 @@ "name": "Run open test file", "type": "node", "request": "launch", - "runtimeArgs": ["--inspect-brk", "${workspaceRoot}/node_modules/.bin/jest", "--runInBand", "${relativeFile}"], + "runtimeArgs": [ + "--inspect-brk", + "${workspaceRoot}/node_modules/.bin/jest", + "--runInBand", + "${relativeFile}" + ], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen" } diff --git a/README.md b/README.md index 2537288cf37..17fefda88c3 100644 --- a/README.md +++ b/README.md @@ -11,19 +11,29 @@ [https://the-guild.dev/graphql/codegen](https://the-guild.dev/graphql/codegen) -GraphQL Code Generator is a tool that generates code out of your GraphQL schema. Whether you are developing a frontend or backend, you can utilize GraphQL Code Generator to generate output from your GraphQL Schema and GraphQL Documents (query/mutation/subscription/fragment). +GraphQL Code Generator is a tool that generates code out of your GraphQL schema. Whether you are +developing a frontend or backend, you can utilize GraphQL Code Generator to generate output from +your GraphQL Schema and GraphQL Documents (query/mutation/subscription/fragment). -By analyzing the schema and documents and parsing it, GraphQL Code Generator can output code at a wide variety of formats, based on pre-defined templates or based on custom user-defined ones. Regardless of the language that you're using, GraphQL Code Generator has you covered. +By analyzing the schema and documents and parsing it, GraphQL Code Generator can output code at a +wide variety of formats, based on pre-defined templates or based on custom user-defined ones. +Regardless of the language that you're using, GraphQL Code Generator has you covered. -GraphQL Code Generator lets you choose the output that you need, based on _plugins_, which are very flexible and customizable. You can also write your _plugins_ to generate custom outputs that match your needs. +GraphQL Code Generator lets you choose the output that you need, based on _plugins_, which are very +flexible and customizable. You can also write your _plugins_ to generate custom outputs that match +your needs. -You can try this tool live on your browser and see some useful examples. Check out [GraphQL Code Generator Live Examples](https://the-guild.dev/graphql/codegen/#live-demo). +You can try this tool live on your browser and see some useful examples. Check out +[GraphQL Code Generator Live Examples](https://the-guild.dev/graphql/codegen/#live-demo). -We currently support and maintain [these plugins](https://the-guild.dev/graphql/codegen/plugins) (TypeScript, Flow, React, Angular, MongoDB, Stencil, Reason, and some more), and there is an active community that writes and maintains custom plugins. +We currently support and maintain [these plugins](https://the-guild.dev/graphql/codegen/plugins) +(TypeScript, Flow, React, Angular, MongoDB, Stencil, Reason, and some more), and there is an active +community that writes and maintains custom plugins. ## Quick Start -> You can find the complete instructions in [GraphQL Code Generator website](https://the-guild.dev/graphql/codegen/docs/getting-started/installation). +> You can find the complete instructions in +> [GraphQL Code Generator website](https://the-guild.dev/graphql/codegen/docs/getting-started/installation). Start by installing the basic deps of GraphQL Codegen: @@ -38,27 +48,36 @@ GraphQL Code Generator lets you setup everything by simply running the following yarn graphql-codegen init ``` -Question by question, it will guide you through the whole process of setting up a schema, selecting plugins, picking a destination of a generated file, and a lot more. +Question by question, it will guide you through the whole process of setting up a schema, selecting +plugins, picking a destination of a generated file, and a lot more. -If you wish to [manually setup codegen, follow these instructions](https://the-guild.dev/graphql/codegen/docs/getting-started/installation). +If you wish to +[manually setup codegen, follow these instructions](https://the-guild.dev/graphql/codegen/docs/getting-started/installation). ## Links -Besides our [docs page](https://the-guild.dev/graphql/codegen/docs/getting-started), feel free to go through our published Medium articles to get a better grasp of what GraphQL Code Generator is all about: +Besides our [docs page](https://the-guild.dev/graphql/codegen/docs/getting-started), feel free to go +through our published Medium articles to get a better grasp of what GraphQL Code Generator is all +about: - [All available plugins & presets](https://the-guild.dev/graphql/codegen/plugins) ## Contributing -If this is your first time contributing to this project, please do read our [Contributor Workflow Guide](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md) before you get started off. +If this is your first time contributing to this project, please do read our +[Contributor Workflow Guide](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md) +before you get started off. Feel free to open issues and pull requests. We're always welcome support from the community. -For a contribution guide specific to this project, please refer to: http://the-guild.dev/graphql/codegen/docs/custom-codegen/contributing. +For a contribution guide specific to this project, please refer to: +http://the-guild.dev/graphql/codegen/docs/custom-codegen/contributing. ## Code of Conduct -Help us keep GraphQL Code Generator open and inclusive. Please read and follow our [Code of Conduct](https://github.com/the-guild-org/Stack/blob/master/CODE_OF_CONDUCT.md) as adopted from [Contributor Covenant](https://contributor-covenant.org) +Help us keep GraphQL Code Generator open and inclusive. Please read and follow our +[Code of Conduct](https://github.com/the-guild-org/Stack/blob/master/CODE_OF_CONDUCT.md) as adopted +from [Contributor Covenant](https://contributor-covenant.org) ## License diff --git a/dev-test/codegen.ts b/dev-test/codegen.ts index 7c0b9838288..d035b6bc289 100644 --- a/dev-test/codegen.ts +++ b/dev-test/codegen.ts @@ -43,7 +43,10 @@ const config: CodegenConfig = { 'typescript-operations', ], }, - './dev-test/test-schema/env.types.ts': { schema: process.env.SCHEMA_PATH, plugins: ['typescript'] }, + './dev-test/test-schema/env.types.ts': { + schema: process.env.SCHEMA_PATH, + plugins: ['typescript'], + }, './dev-test/test-schema/typings.immutableTypes.ts': { schema: './dev-test/test-schema/schema.json', config: { imutableTypes: true }, @@ -127,12 +130,18 @@ const config: CodegenConfig = { }, './dev-test/star-wars/types.excludeQueryAlpha.ts': { schema: './dev-test/star-wars/schema.json', - documents: ['./dev-test/star-wars/**/*.graphql', '!./dev-test/star-wars/**/ExcludeQueryAlpha.graphql'], + documents: [ + './dev-test/star-wars/**/*.graphql', + '!./dev-test/star-wars/**/ExcludeQueryAlpha.graphql', + ], plugins: ['typescript', 'typescript-operations'], }, './dev-test/star-wars/types.excludeQueryBeta.ts': { schema: './dev-test/star-wars/schema.json', - documents: ['./dev-test/star-wars/**/*.graphql', '!./dev-test/star-wars/**/ExcludeQueryBeta.graphql'], + documents: [ + './dev-test/star-wars/**/*.graphql', + '!./dev-test/star-wars/**/ExcludeQueryBeta.graphql', + ], plugins: ['typescript', 'typescript-operations'], }, './dev-test/star-wars/types.preResolveTypes.ts': { diff --git a/dev-test/gatsby/schema.graphql b/dev-test/gatsby/schema.graphql index 2d4a8f75c2a..374b52126b1 100644 --- a/dev-test/gatsby/schema.graphql +++ b/dev-test/gatsby/schema.graphql @@ -16,7 +16,12 @@ directive @childOf( """ Add date formatting options. """ -directive @dateformat(difference: String, formatString: String, fromNow: Boolean, locale: String) on FIELD_DEFINITION +directive @dateformat( + difference: String + formatString: String + fromNow: Boolean + locale: String +) on FIELD_DEFINITION """ Do not infer field types from field values. @@ -1665,9 +1670,19 @@ enum PotraceTurnPolicy { } type Query { - allDirectory(filter: DirectoryFilterInput, limit: Int, skip: Int, sort: DirectorySortInput): DirectoryConnection! + allDirectory( + filter: DirectoryFilterInput + limit: Int + skip: Int + sort: DirectorySortInput + ): DirectoryConnection! allFile(filter: FileFilterInput, limit: Int, skip: Int, sort: FileSortInput): FileConnection! - allImageSharp(filter: ImageSharpFilterInput, limit: Int, skip: Int, sort: ImageSharpSortInput): ImageSharpConnection! + allImageSharp( + filter: ImageSharpFilterInput + limit: Int + skip: Int + sort: ImageSharpSortInput + ): ImageSharpConnection! allInternalEvents( filter: internal__eventsFilterInput limit: Int @@ -1687,8 +1702,18 @@ type Query { skip: Int sort: SiteFunctionSortInput ): SiteFunctionConnection! - allSitePage(filter: SitePageFilterInput, limit: Int, skip: Int, sort: SitePageSortInput): SitePageConnection! - allSitePlugin(filter: SitePluginFilterInput, limit: Int, skip: Int, sort: SitePluginSortInput): SitePluginConnection! + allSitePage( + filter: SitePageFilterInput + limit: Int + skip: Int + sort: SitePageSortInput + ): SitePageConnection! + allSitePlugin( + filter: SitePluginFilterInput + limit: Int + skip: Int + sort: SitePluginSortInput + ): SitePluginConnection! allWp(filter: WpFilterInput, limit: Int, skip: Int, sort: WpSortInput): WpConnection! allWpBlockEditorContentNode( filter: WpBlockEditorContentNodeFilterInput @@ -1702,8 +1727,18 @@ type Query { skip: Int sort: WpBlockEditorPreviewSortInput ): WpBlockEditorPreviewConnection! - allWpCategory(filter: WpCategoryFilterInput, limit: Int, skip: Int, sort: WpCategorySortInput): WpCategoryConnection! - allWpComment(filter: WpCommentFilterInput, limit: Int, skip: Int, sort: WpCommentSortInput): WpCommentConnection! + allWpCategory( + filter: WpCategoryFilterInput + limit: Int + skip: Int + sort: WpCategorySortInput + ): WpCategoryConnection! + allWpComment( + filter: WpCommentFilterInput + limit: Int + skip: Int + sort: WpCommentSortInput + ): WpCommentConnection! allWpCommentAuthor( filter: WpCommentAuthorFilterInput limit: Int @@ -1728,10 +1763,30 @@ type Query { skip: Int sort: WpMediaItemSortInput ): WpMediaItemConnection! - allWpMenu(filter: WpMenuFilterInput, limit: Int, skip: Int, sort: WpMenuSortInput): WpMenuConnection! - allWpMenuItem(filter: WpMenuItemFilterInput, limit: Int, skip: Int, sort: WpMenuItemSortInput): WpMenuItemConnection! - allWpPage(filter: WpPageFilterInput, limit: Int, skip: Int, sort: WpPageSortInput): WpPageConnection! - allWpPost(filter: WpPostFilterInput, limit: Int, skip: Int, sort: WpPostSortInput): WpPostConnection! + allWpMenu( + filter: WpMenuFilterInput + limit: Int + skip: Int + sort: WpMenuSortInput + ): WpMenuConnection! + allWpMenuItem( + filter: WpMenuItemFilterInput + limit: Int + skip: Int + sort: WpMenuItemSortInput + ): WpMenuItemConnection! + allWpPage( + filter: WpPageFilterInput + limit: Int + skip: Int + sort: WpPageSortInput + ): WpPageConnection! + allWpPost( + filter: WpPostFilterInput + limit: Int + skip: Int + sort: WpPostSortInput + ): WpPostConnection! allWpPostFormat( filter: WpPostFormatFilterInput limit: Int @@ -1745,10 +1800,30 @@ type Query { sort: WpReusableBlockSortInput ): WpReusableBlockConnection! allWpTag(filter: WpTagFilterInput, limit: Int, skip: Int, sort: WpTagSortInput): WpTagConnection! - allWpTaxonomy(filter: WpTaxonomyFilterInput, limit: Int, skip: Int, sort: WpTaxonomySortInput): WpTaxonomyConnection! - allWpTermNode(filter: WpTermNodeFilterInput, limit: Int, skip: Int, sort: WpTermNodeSortInput): WpTermNodeConnection! - allWpUser(filter: WpUserFilterInput, limit: Int, skip: Int, sort: WpUserSortInput): WpUserConnection! - allWpUserRole(filter: WpUserRoleFilterInput, limit: Int, skip: Int, sort: WpUserRoleSortInput): WpUserRoleConnection! + allWpTaxonomy( + filter: WpTaxonomyFilterInput + limit: Int + skip: Int + sort: WpTaxonomySortInput + ): WpTaxonomyConnection! + allWpTermNode( + filter: WpTermNodeFilterInput + limit: Int + skip: Int + sort: WpTermNodeSortInput + ): WpTermNodeConnection! + allWpUser( + filter: WpUserFilterInput + limit: Int + skip: Int + sort: WpUserSortInput + ): WpUserConnection! + allWpUserRole( + filter: WpUserRoleFilterInput + limit: Int + skip: Int + sort: WpUserRoleSortInput + ): WpUserRoleConnection! directory( absolutePath: StringQueryOperatorInput accessTime: DateQueryOperatorInput @@ -2676,7 +2751,11 @@ type SiteBuildMetadata implements Node { type SiteBuildMetadataConnection { distinct(field: SiteBuildMetadataFieldsEnum!): [String!]! edges: [SiteBuildMetadataEdge!]! - group(field: SiteBuildMetadataFieldsEnum!, limit: Int, skip: Int): [SiteBuildMetadataGroupConnection!]! + group( + field: SiteBuildMetadataFieldsEnum! + limit: Int + skip: Int + ): [SiteBuildMetadataGroupConnection!]! max(field: SiteBuildMetadataFieldsEnum!): Float min(field: SiteBuildMetadataFieldsEnum!): Float nodes: [SiteBuildMetadata!]! @@ -2794,7 +2873,11 @@ type SiteBuildMetadataGroupConnection { edges: [SiteBuildMetadataEdge!]! field: String! fieldValue: String - group(field: SiteBuildMetadataFieldsEnum!, limit: Int, skip: Int): [SiteBuildMetadataGroupConnection!]! + group( + field: SiteBuildMetadataFieldsEnum! + limit: Int + skip: Int + ): [SiteBuildMetadataGroupConnection!]! max(field: SiteBuildMetadataFieldsEnum!): Float min(field: SiteBuildMetadataFieldsEnum!): Float nodes: [SiteBuildMetadata!]! @@ -3720,7 +3803,11 @@ interface WpBlockEditorContentNode implements Node { type WpBlockEditorContentNodeConnection { distinct(field: WpBlockEditorContentNodeFieldsEnum!): [String!]! edges: [WpBlockEditorContentNodeEdge!]! - group(field: WpBlockEditorContentNodeFieldsEnum!, limit: Int, skip: Int): [WpBlockEditorContentNodeGroupConnection!]! + group( + field: WpBlockEditorContentNodeFieldsEnum! + limit: Int + skip: Int + ): [WpBlockEditorContentNodeGroupConnection!]! max(field: WpBlockEditorContentNodeFieldsEnum!): Float min(field: WpBlockEditorContentNodeFieldsEnum!): Float nodes: [WpBlockEditorContentNode!]! @@ -3904,7 +3991,11 @@ type WpBlockEditorContentNodeGroupConnection { edges: [WpBlockEditorContentNodeEdge!]! field: String! fieldValue: String - group(field: WpBlockEditorContentNodeFieldsEnum!, limit: Int, skip: Int): [WpBlockEditorContentNodeGroupConnection!]! + group( + field: WpBlockEditorContentNodeFieldsEnum! + limit: Int + skip: Int + ): [WpBlockEditorContentNodeGroupConnection!]! max(field: WpBlockEditorContentNodeFieldsEnum!): Float min(field: WpBlockEditorContentNodeFieldsEnum!): Float nodes: [WpBlockEditorContentNode!]! @@ -4132,7 +4223,11 @@ type WpBlockEditorPreview implements Node & WpContentNode & WpDatabaseIdentifier type WpBlockEditorPreviewConnection { distinct(field: WpBlockEditorPreviewFieldsEnum!): [String!]! edges: [WpBlockEditorPreviewEdge!]! - group(field: WpBlockEditorPreviewFieldsEnum!, limit: Int, skip: Int): [WpBlockEditorPreviewGroupConnection!]! + group( + field: WpBlockEditorPreviewFieldsEnum! + limit: Int + skip: Int + ): [WpBlockEditorPreviewGroupConnection!]! max(field: WpBlockEditorPreviewFieldsEnum!): Float min(field: WpBlockEditorPreviewFieldsEnum!): Float nodes: [WpBlockEditorPreview!]! @@ -4586,7 +4681,11 @@ type WpBlockEditorPreviewGroupConnection { edges: [WpBlockEditorPreviewEdge!]! field: String! fieldValue: String - group(field: WpBlockEditorPreviewFieldsEnum!, limit: Int, skip: Int): [WpBlockEditorPreviewGroupConnection!]! + group( + field: WpBlockEditorPreviewFieldsEnum! + limit: Int + skip: Int + ): [WpBlockEditorPreviewGroupConnection!]! max(field: WpBlockEditorPreviewFieldsEnum!): Float min(field: WpBlockEditorPreviewFieldsEnum!): Float nodes: [WpBlockEditorPreview!]! @@ -5387,7 +5486,11 @@ type WpCommentAuthor implements Node & WpCommenter & WpNode { type WpCommentAuthorConnection { distinct(field: WpCommentAuthorFieldsEnum!): [String!]! edges: [WpCommentAuthorEdge!]! - group(field: WpCommentAuthorFieldsEnum!, limit: Int, skip: Int): [WpCommentAuthorGroupConnection!]! + group( + field: WpCommentAuthorFieldsEnum! + limit: Int + skip: Int + ): [WpCommentAuthorGroupConnection!]! max(field: WpCommentAuthorFieldsEnum!): Float min(field: WpCommentAuthorFieldsEnum!): Float nodes: [WpCommentAuthor!]! @@ -5524,7 +5627,11 @@ type WpCommentAuthorGroupConnection { edges: [WpCommentAuthorEdge!]! field: String! fieldValue: String - group(field: WpCommentAuthorFieldsEnum!, limit: Int, skip: Int): [WpCommentAuthorGroupConnection!]! + group( + field: WpCommentAuthorFieldsEnum! + limit: Int + skip: Int + ): [WpCommentAuthorGroupConnection!]! max(field: WpCommentAuthorFieldsEnum!): Float min(field: WpCommentAuthorFieldsEnum!): Float nodes: [WpCommentAuthor!]! @@ -7047,7 +7154,9 @@ type WpCoreAudioBlockAttributes { src: String } -union WpCoreAudioBlockAttributesUnion = WpCoreAudioBlockAttributes | WpCoreAudioBlockDeprecatedV1Attributes +union WpCoreAudioBlockAttributesUnion = + | WpCoreAudioBlockAttributes + | WpCoreAudioBlockDeprecatedV1Attributes type WpCoreAudioBlockDeprecatedV1Attributes { align: String @@ -7195,7 +7304,7 @@ type WpCoreButtonBlockAttributes { } union WpCoreButtonBlockAttributesUnion = - WpCoreButtonBlockAttributes + | WpCoreButtonBlockAttributes | WpCoreButtonBlockDeprecatedV1Attributes | WpCoreButtonBlockDeprecatedV2Attributes | WpCoreButtonBlockDeprecatedV3Attributes @@ -7470,7 +7579,7 @@ type WpCoreButtonsBlockAttributes { } union WpCoreButtonsBlockAttributesUnion = - WpCoreButtonsBlockAttributes + | WpCoreButtonsBlockAttributes | WpCoreButtonsBlockDeprecatedV1Attributes | WpCoreButtonsBlockDeprecatedV2Attributes @@ -7748,7 +7857,9 @@ type WpCoreColumnBlockAttributes { width: String } -union WpCoreColumnBlockAttributesUnion = WpCoreColumnBlockAttributes | WpCoreColumnBlockDeprecatedV1Attributes +union WpCoreColumnBlockAttributesUnion = + | WpCoreColumnBlockAttributes + | WpCoreColumnBlockDeprecatedV1Attributes type WpCoreColumnBlockDeprecatedV1Attributes { allowedBlocks: JSON @@ -7830,7 +7941,7 @@ type WpCoreColumnsBlockAttributes { } union WpCoreColumnsBlockAttributesUnion = - WpCoreColumnsBlockAttributes + | WpCoreColumnsBlockAttributes | WpCoreColumnsBlockDeprecatedV1Attributes | WpCoreColumnsBlockDeprecatedV2Attributes | WpCoreColumnsBlockDeprecatedV3Attributes @@ -7953,7 +8064,7 @@ type WpCoreCoverBlockAttributes { } union WpCoreCoverBlockAttributesUnion = - WpCoreCoverBlockAttributes + | WpCoreCoverBlockAttributes | WpCoreCoverBlockDeprecatedV1Attributes | WpCoreCoverBlockDeprecatedV2Attributes | WpCoreCoverBlockDeprecatedV3Attributes @@ -8203,7 +8314,9 @@ type WpCoreEmbedBlockAttributes { url: String } -union WpCoreEmbedBlockAttributesUnion = WpCoreEmbedBlockAttributes | WpCoreEmbedBlockDeprecatedV1Attributes +union WpCoreEmbedBlockAttributesUnion = + | WpCoreEmbedBlockAttributes + | WpCoreEmbedBlockDeprecatedV1Attributes type WpCoreEmbedBlockDeprecatedV1Attributes { align: String @@ -8288,7 +8401,9 @@ type WpCoreFileBlockAttributes { textLinkTarget: String } -union WpCoreFileBlockAttributesUnion = WpCoreFileBlockAttributes | WpCoreFileBlockDeprecatedV1Attributes +union WpCoreFileBlockAttributesUnion = + | WpCoreFileBlockAttributes + | WpCoreFileBlockDeprecatedV1Attributes type WpCoreFileBlockDeprecatedV1Attributes { align: String @@ -8446,7 +8561,7 @@ type WpCoreGalleryBlockAttributesImages { } union WpCoreGalleryBlockAttributesUnion = - WpCoreGalleryBlockAttributes + | WpCoreGalleryBlockAttributes | WpCoreGalleryBlockDeprecatedV1Attributes | WpCoreGalleryBlockDeprecatedV2Attributes | WpCoreGalleryBlockDeprecatedV3Attributes @@ -8684,7 +8799,7 @@ type WpCoreGroupBlockAttributes { } union WpCoreGroupBlockAttributesUnion = - WpCoreGroupBlockAttributes + | WpCoreGroupBlockAttributes | WpCoreGroupBlockDeprecatedV1Attributes | WpCoreGroupBlockDeprecatedV2Attributes | WpCoreGroupBlockDeprecatedV3Attributes @@ -8815,7 +8930,7 @@ type WpCoreHeadingBlockAttributes { } union WpCoreHeadingBlockAttributesUnion = - WpCoreHeadingBlockAttributes + | WpCoreHeadingBlockAttributes | WpCoreHeadingBlockDeprecatedV1Attributes | WpCoreHeadingBlockDeprecatedV2Attributes | WpCoreHeadingBlockDeprecatedV3Attributes @@ -9015,7 +9130,7 @@ type WpCoreImageBlockAttributes { } union WpCoreImageBlockAttributesUnion = - WpCoreImageBlockAttributes + | WpCoreImageBlockAttributes | WpCoreImageBlockDeprecatedV1Attributes | WpCoreImageBlockDeprecatedV2Attributes | WpCoreImageBlockDeprecatedV3Attributes @@ -9224,7 +9339,7 @@ type WpCoreLatestPostsBlockAttributes { } union WpCoreLatestPostsBlockAttributesUnion = - WpCoreLatestPostsBlockAttributes + | WpCoreLatestPostsBlockAttributes | WpCoreLatestPostsBlockDeprecatedV1Attributes type WpCoreLatestPostsBlockDeprecatedV1Attributes { @@ -9382,7 +9497,9 @@ type WpCoreListBlockAttributes { values: String! } -union WpCoreListBlockAttributesUnion = WpCoreListBlockAttributes | WpCoreListBlockDeprecatedV1Attributes +union WpCoreListBlockAttributesUnion = + | WpCoreListBlockAttributes + | WpCoreListBlockDeprecatedV1Attributes type WpCoreListBlockDeprecatedV1Attributes { anchor: String @@ -9544,7 +9661,7 @@ type WpCoreMediaTextBlockAttributes { } union WpCoreMediaTextBlockAttributesUnion = - WpCoreMediaTextBlockAttributes + | WpCoreMediaTextBlockAttributes | WpCoreMediaTextBlockDeprecatedV1Attributes | WpCoreMediaTextBlockDeprecatedV2Attributes | WpCoreMediaTextBlockDeprecatedV3Attributes @@ -9832,7 +9949,7 @@ type WpCoreNavigationBlockAttributes { } union WpCoreNavigationBlockAttributesUnion = - WpCoreNavigationBlockAttributes + | WpCoreNavigationBlockAttributes | WpCoreNavigationBlockDeprecatedV1Attributes | WpCoreNavigationBlockDeprecatedV2Attributes | WpCoreNavigationBlockDeprecatedV3Attributes @@ -10065,7 +10182,7 @@ type WpCoreNavigationLinkBlockAttributes { } union WpCoreNavigationLinkBlockAttributesUnion = - WpCoreNavigationLinkBlockAttributes + | WpCoreNavigationLinkBlockAttributes | WpCoreNavigationLinkBlockDeprecatedV1Attributes type WpCoreNavigationLinkBlockDeprecatedV1Attributes { @@ -10333,7 +10450,7 @@ type WpCoreParagraphBlockAttributes { } union WpCoreParagraphBlockAttributesUnion = - WpCoreParagraphBlockAttributes + | WpCoreParagraphBlockAttributes | WpCoreParagraphBlockDeprecatedV1Attributes | WpCoreParagraphBlockDeprecatedV2Attributes | WpCoreParagraphBlockDeprecatedV3Attributes @@ -10734,7 +10851,9 @@ type WpCorePostDateBlockAttributes { textColor: String } -union WpCorePostDateBlockAttributesUnion = WpCorePostDateBlockAttributes | WpCorePostDateBlockDeprecatedV1Attributes +union WpCorePostDateBlockAttributesUnion = + | WpCorePostDateBlockAttributes + | WpCorePostDateBlockDeprecatedV1Attributes type WpCorePostDateBlockDeprecatedV1Attributes { backgroundColor: String @@ -11141,7 +11260,9 @@ type WpCorePostTitleBlockAttributes { textColor: String } -union WpCorePostTitleBlockAttributesUnion = WpCorePostTitleBlockAttributes | WpCorePostTitleBlockDeprecatedV1Attributes +union WpCorePostTitleBlockAttributesUnion = + | WpCorePostTitleBlockAttributes + | WpCorePostTitleBlockDeprecatedV1Attributes type WpCorePostTitleBlockDeprecatedV1Attributes { align: String @@ -11295,7 +11416,7 @@ type WpCorePullquoteBlockAttributes { } union WpCorePullquoteBlockAttributesUnion = - WpCorePullquoteBlockAttributes + | WpCorePullquoteBlockAttributes | WpCorePullquoteBlockDeprecatedV1Attributes | WpCorePullquoteBlockDeprecatedV2Attributes | WpCorePullquoteBlockDeprecatedV3Attributes @@ -11450,7 +11571,9 @@ type WpCoreQueryBlockAttributes { textColor: String } -union WpCoreQueryBlockAttributesUnion = WpCoreQueryBlockAttributes | WpCoreQueryBlockDeprecatedV1Attributes +union WpCoreQueryBlockAttributesUnion = + | WpCoreQueryBlockAttributes + | WpCoreQueryBlockDeprecatedV1Attributes type WpCoreQueryBlockDeprecatedV1Attributes { align: String @@ -11533,7 +11656,7 @@ type WpCoreQueryPaginationBlockAttributes { } union WpCoreQueryPaginationBlockAttributesUnion = - WpCoreQueryPaginationBlockAttributes + | WpCoreQueryPaginationBlockAttributes | WpCoreQueryPaginationBlockDeprecatedV1Attributes type WpCoreQueryPaginationBlockDeprecatedV1Attributes { @@ -11803,7 +11926,7 @@ type WpCoreQueryTitleBlockAttributes { } union WpCoreQueryTitleBlockAttributesUnion = - WpCoreQueryTitleBlockAttributes + | WpCoreQueryTitleBlockAttributes | WpCoreQueryTitleBlockDeprecatedV1Attributes type WpCoreQueryTitleBlockDeprecatedV1Attributes { @@ -11886,7 +12009,7 @@ type WpCoreQuoteBlockAttributes { } union WpCoreQuoteBlockAttributesUnion = - WpCoreQuoteBlockAttributes + | WpCoreQuoteBlockAttributes | WpCoreQuoteBlockDeprecatedV1Attributes | WpCoreQuoteBlockDeprecatedV2Attributes | WpCoreQuoteBlockDeprecatedV3Attributes @@ -12314,7 +12437,7 @@ type WpCoreSiteTaglineBlockAttributes { } union WpCoreSiteTaglineBlockAttributesUnion = - WpCoreSiteTaglineBlockAttributes + | WpCoreSiteTaglineBlockAttributes | WpCoreSiteTaglineBlockDeprecatedV1Attributes type WpCoreSiteTaglineBlockDeprecatedV1Attributes { @@ -12399,7 +12522,9 @@ type WpCoreSiteTitleBlockAttributes { textColor: String } -union WpCoreSiteTitleBlockAttributesUnion = WpCoreSiteTitleBlockAttributes | WpCoreSiteTitleBlockDeprecatedV1Attributes +union WpCoreSiteTitleBlockAttributesUnion = + | WpCoreSiteTitleBlockAttributes + | WpCoreSiteTitleBlockDeprecatedV1Attributes type WpCoreSiteTitleBlockDeprecatedV1Attributes { align: String @@ -12549,7 +12674,7 @@ type WpCoreSocialLinksBlockAttributes { } union WpCoreSocialLinksBlockAttributesUnion = - WpCoreSocialLinksBlockAttributes + | WpCoreSocialLinksBlockAttributes | WpCoreSocialLinksBlockDeprecatedV1Attributes type WpCoreSocialLinksBlockDeprecatedV1Attributes { @@ -12630,7 +12755,9 @@ type WpCoreSpacerBlockAttributes { width: String } -union WpCoreSpacerBlockAttributesUnion = WpCoreSpacerBlockAttributes | WpCoreSpacerBlockDeprecatedV1Attributes +union WpCoreSpacerBlockAttributesUnion = + | WpCoreSpacerBlockAttributes + | WpCoreSpacerBlockDeprecatedV1Attributes type WpCoreSpacerBlockDeprecatedV1Attributes { anchor: String @@ -12745,7 +12872,7 @@ type WpCoreTableBlockAttributesHeadCells { } union WpCoreTableBlockAttributesUnion = - WpCoreTableBlockAttributes + | WpCoreTableBlockAttributes | WpCoreTableBlockDeprecatedV1Attributes | WpCoreTableBlockDeprecatedV2Attributes @@ -13173,7 +13300,7 @@ type WpCoreVerseBlockAttributes { } union WpCoreVerseBlockAttributesUnion = - WpCoreVerseBlockAttributes + | WpCoreVerseBlockAttributes | WpCoreVerseBlockDeprecatedV1Attributes | WpCoreVerseBlockDeprecatedV2Attributes @@ -19276,7 +19403,11 @@ type WpReusableBlock implements Node & WpBlockEditorContentNode & WpContentNode type WpReusableBlockConnection { distinct(field: WpReusableBlockFieldsEnum!): [String!]! edges: [WpReusableBlockEdge!]! - group(field: WpReusableBlockFieldsEnum!, limit: Int, skip: Int): [WpReusableBlockGroupConnection!]! + group( + field: WpReusableBlockFieldsEnum! + limit: Int + skip: Int + ): [WpReusableBlockGroupConnection!]! max(field: WpReusableBlockFieldsEnum!): Float min(field: WpReusableBlockFieldsEnum!): Float nodes: [WpReusableBlock!]! @@ -19619,7 +19750,11 @@ type WpReusableBlockGroupConnection { edges: [WpReusableBlockEdge!]! field: String! fieldValue: String - group(field: WpReusableBlockFieldsEnum!, limit: Int, skip: Int): [WpReusableBlockGroupConnection!]! + group( + field: WpReusableBlockFieldsEnum! + limit: Int + skip: Int + ): [WpReusableBlockGroupConnection!]! max(field: WpReusableBlockFieldsEnum!): Float min(field: WpReusableBlockFieldsEnum!): Float nodes: [WpReusableBlock!]! @@ -21780,7 +21915,11 @@ type internal__events implements Node { type internal__eventsConnection { distinct(field: internal__eventsFieldsEnum!): [String!]! edges: [internal__eventsEdge!]! - group(field: internal__eventsFieldsEnum!, limit: Int, skip: Int): [internal__eventsGroupConnection!]! + group( + field: internal__eventsFieldsEnum! + limit: Int + skip: Int + ): [internal__eventsGroupConnection!]! max(field: internal__eventsFieldsEnum!): Float min(field: internal__eventsFieldsEnum!): Float nodes: [internal__events!]! @@ -22562,7 +22701,11 @@ type internal__eventsGroupConnection { edges: [internal__eventsEdge!]! field: String! fieldValue: String - group(field: internal__eventsFieldsEnum!, limit: Int, skip: Int): [internal__eventsGroupConnection!]! + group( + field: internal__eventsFieldsEnum! + limit: Int + skip: Int + ): [internal__eventsGroupConnection!]! max(field: internal__eventsFieldsEnum!): Float min(field: internal__eventsFieldsEnum!): Float nodes: [internal__events!]! diff --git a/dev-test/githunt/typed-document-nodes.ts b/dev-test/githunt/typed-document-nodes.ts index 5d66b82c399..c9c007657a3 100644 --- a/dev-test/githunt/typed-document-nodes.ts +++ b/dev-test/githunt/typed-document-nodes.ts @@ -1,11 +1,16 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -330,7 +335,12 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote?: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; export const CommentsPageCommentFragmentDoc = { @@ -527,7 +537,10 @@ export const OnCommentAddedDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'repoFullName' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, + }, }, ], selectionSet: { @@ -579,7 +592,10 @@ export const CommentDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'repoFullName' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, + }, }, { kind: 'VariableDefinition', @@ -649,7 +665,12 @@ export const CommentDocument = { ], selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'CommentsPageComment' } }], + selections: [ + { + kind: 'FragmentSpread', + name: { kind: 'Name', value: 'CommentsPageComment' }, + }, + ], }, }, { kind: 'Field', name: { kind: 'Name', value: 'commentCount' } }, @@ -663,7 +684,10 @@ export const CommentDocument = { { kind: 'Field', name: { kind: 'Name', value: 'html_url' } }, { kind: 'InlineFragment', - typeCondition: { kind: 'NamedType', name: { kind: 'Name', value: 'Repository' } }, + typeCondition: { + kind: 'NamedType', + name: { kind: 'Name', value: 'Repository' }, + }, selectionSet: { kind: 'SelectionSet', selections: [ @@ -745,7 +769,10 @@ export const FeedDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'type' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'FeedType' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'FeedType' } }, + }, }, { kind: 'VariableDefinition', @@ -896,7 +923,10 @@ export const SubmitRepositoryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'repoFullName' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, + }, }, ], selectionSet: { @@ -933,12 +963,18 @@ export const SubmitCommentDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'repoFullName' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, + }, }, { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'commentContent' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, + }, }, ], selectionSet: { @@ -961,7 +997,9 @@ export const SubmitCommentDocument = { ], selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'CommentsPageComment' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'CommentsPageComment' } }, + ], }, }, ], @@ -1004,12 +1042,18 @@ export const VoteDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'repoFullName' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'String' } }, + }, }, { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'type' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'VoteType' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'VoteType' } }, + }, }, ], selectionSet: { diff --git a/dev-test/githunt/types.avoidOptionals.ts b/dev-test/githunt/types.avoidOptionals.ts index fae92412f8c..a4e3d208f51 100644 --- a/dev-test/githunt/types.avoidOptionals.ts +++ b/dev-test/githunt/types.avoidOptionals.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -329,5 +333,10 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; diff --git a/dev-test/githunt/types.d.ts b/dev-test/githunt/types.d.ts index a3214fa9248..ff7ed78627a 100644 --- a/dev-test/githunt/types.d.ts +++ b/dev-test/githunt/types.d.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -324,5 +328,10 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote?: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; diff --git a/dev-test/githunt/types.enumsAsTypes.ts b/dev-test/githunt/types.enumsAsTypes.ts index a3214fa9248..ff7ed78627a 100644 --- a/dev-test/githunt/types.enumsAsTypes.ts +++ b/dev-test/githunt/types.enumsAsTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -324,5 +328,10 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote?: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; diff --git a/dev-test/githunt/types.flatten.preResolveTypes.ts b/dev-test/githunt/types.flatten.preResolveTypes.ts index 6a71babaaf6..7e27c6e0c65 100644 --- a/dev-test/githunt/types.flatten.preResolveTypes.ts +++ b/dev-test/githunt/types.flatten.preResolveTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -284,5 +288,10 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote?: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; diff --git a/dev-test/githunt/types.immutableTypes.ts b/dev-test/githunt/types.immutableTypes.ts index df6b6d82851..37dedae5fc1 100644 --- a/dev-test/githunt/types.immutableTypes.ts +++ b/dev-test/githunt/types.immutableTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -179,7 +183,11 @@ export type OnCommentAddedSubscription = { readonly id: number; readonly createdAt: number; readonly content: string; - readonly postedBy: { readonly __typename?: 'User'; readonly login: string; readonly html_url: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly login: string; + readonly html_url: string; + }; } | null; }; @@ -191,19 +199,31 @@ export type CommentQueryVariables = Exact<{ export type CommentQuery = { readonly __typename?: 'Query'; - readonly currentUser?: { readonly __typename?: 'User'; readonly login: string; readonly html_url: string } | null; + readonly currentUser?: { + readonly __typename?: 'User'; + readonly login: string; + readonly html_url: string; + } | null; readonly entry?: { readonly __typename?: 'Entry'; readonly id: number; readonly createdAt: number; readonly commentCount: number; - readonly postedBy: { readonly __typename?: 'User'; readonly login: string; readonly html_url: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly login: string; + readonly html_url: string; + }; readonly comments: ReadonlyArray<{ readonly __typename?: 'Comment'; readonly id: number; readonly createdAt: number; readonly content: string; - readonly postedBy: { readonly __typename?: 'User'; readonly login: string; readonly html_url: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly login: string; + readonly html_url: string; + }; } | null>; readonly repository: { readonly __typename?: 'Repository'; @@ -221,14 +241,22 @@ export type CommentsPageCommentFragment = { readonly id: number; readonly createdAt: number; readonly content: string; - readonly postedBy: { readonly __typename?: 'User'; readonly login: string; readonly html_url: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly login: string; + readonly html_url: string; + }; }; export type CurrentUserForProfileQueryVariables = Exact<{ [key: string]: never }>; export type CurrentUserForProfileQuery = { readonly __typename?: 'Query'; - readonly currentUser?: { readonly __typename?: 'User'; readonly login: string; readonly avatar_url: string } | null; + readonly currentUser?: { + readonly __typename?: 'User'; + readonly login: string; + readonly avatar_url: string; + } | null; }; export type FeedEntryFragment = { @@ -247,7 +275,11 @@ export type FeedEntryFragment = { readonly owner?: { readonly __typename?: 'User'; readonly avatar_url: string } | null; }; readonly vote: { readonly __typename?: 'Vote'; readonly vote_value: number }; - readonly postedBy: { readonly __typename?: 'User'; readonly html_url: string; readonly login: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly html_url: string; + readonly login: string; + }; }; export type FeedQueryVariables = Exact<{ @@ -275,7 +307,11 @@ export type FeedQuery = { readonly owner?: { readonly __typename?: 'User'; readonly avatar_url: string } | null; }; readonly vote: { readonly __typename?: 'Vote'; readonly vote_value: number }; - readonly postedBy: { readonly __typename?: 'User'; readonly html_url: string; readonly login: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly html_url: string; + readonly login: string; + }; } | null> | null; }; @@ -297,7 +333,11 @@ export type RepoInfoFragment = { readonly stargazers_count: number; readonly open_issues_count?: number | null; }; - readonly postedBy: { readonly __typename?: 'User'; readonly html_url: string; readonly login: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly html_url: string; + readonly login: string; + }; }; export type SubmitCommentMutationVariables = Exact<{ @@ -312,7 +352,11 @@ export type SubmitCommentMutation = { readonly id: number; readonly createdAt: number; readonly content: string; - readonly postedBy: { readonly __typename?: 'User'; readonly login: string; readonly html_url: string }; + readonly postedBy: { + readonly __typename?: 'User'; + readonly login: string; + readonly html_url: string; + }; } | null; }; diff --git a/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts b/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts index cdda2177e51..fafa495e046 100644 --- a/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts +++ b/dev-test/githunt/types.preResolveTypes.onlyOperationTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -192,5 +196,10 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote?: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; diff --git a/dev-test/githunt/types.preResolveTypes.ts b/dev-test/githunt/types.preResolveTypes.ts index 91e23917b8c..057f9f78ccd 100644 --- a/dev-test/githunt/types.preResolveTypes.ts +++ b/dev-test/githunt/types.preResolveTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -329,5 +333,10 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote?: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; diff --git a/dev-test/githunt/types.ts b/dev-test/githunt/types.ts index 91e23917b8c..057f9f78ccd 100644 --- a/dev-test/githunt/types.ts +++ b/dev-test/githunt/types.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -329,5 +333,10 @@ export type VoteMutationVariables = Exact<{ export type VoteMutation = { __typename?: 'Mutation'; - vote?: { __typename?: 'Entry'; score: number; id: number; vote: { __typename?: 'Vote'; vote_value: number } } | null; + vote?: { + __typename?: 'Entry'; + score: number; + id: number; + vote: { __typename?: 'Vote'; vote_value: number }; + } | null; }; diff --git a/dev-test/gql-tag-operations-masking/gql/fragment-masking.ts b/dev-test/gql-tag-operations-masking/gql/fragment-masking.ts index a6b3407f590..749b250a4de 100644 --- a/dev-test/gql-tag-operations-masking/gql/fragment-masking.ts +++ b/dev-test/gql-tag-operations-masking/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql.js'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/dev-test/gql-tag-operations-masking/gql/gql.ts b/dev-test/gql-tag-operations-masking/gql/gql.ts index 43f84727300..415c9d72233 100644 --- a/dev-test/gql-tag-operations-masking/gql/gql.ts +++ b/dev-test/gql-tag-operations-masking/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql.js'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql.js'; /** * Map of all GraphQL operations in the project. @@ -41,34 +41,30 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment TweetFragment on Tweet {\n id\n body\n ...TweetAuthorFragment\n }\n' + source: '\n fragment TweetFragment on Tweet {\n id\n body\n ...TweetAuthorFragment\n }\n', ): (typeof documents)['\n fragment TweetFragment on Tweet {\n id\n body\n ...TweetAuthorFragment\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment TweetAuthorFragment on Tweet {\n id\n author {\n id\n username\n }\n }\n' + source: '\n fragment TweetAuthorFragment on Tweet {\n id\n author {\n id\n username\n }\n }\n', ): (typeof documents)['\n fragment TweetAuthorFragment on Tweet {\n id\n author {\n id\n username\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment TweetsFragment on Query {\n Tweets {\n id\n ...TweetFragment\n }\n }\n' + source: '\n fragment TweetsFragment on Query {\n Tweets {\n id\n ...TweetFragment\n }\n }\n', ): (typeof documents)['\n fragment TweetsFragment on Query {\n Tweets {\n id\n ...TweetFragment\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query TweetAppQuery {\n ...TweetsFragment\n }\n' + source: '\n query TweetAppQuery {\n ...TweetsFragment\n }\n', ): (typeof documents)['\n query TweetAppQuery {\n ...TweetsFragment\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/dev-test/gql-tag-operations-masking/gql/graphql.ts b/dev-test/gql-tag-operations-masking/gql/graphql.ts index 35f4d1f9485..0fbf3dc102c 100644 --- a/dev-test/gql-tag-operations-masking/gql/graphql.ts +++ b/dev-test/gql-tag-operations-masking/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -31,7 +36,9 @@ export type TweetAuthorFragmentFragment = { export type TweetsFragmentFragment = { __typename?: 'Query'; Tweets?: Array< - { __typename?: 'Tweet'; id: string } & { ' $fragmentRefs'?: { TweetFragmentFragment: TweetFragmentFragment } } + { __typename?: 'Tweet'; id: string } & { + ' $fragmentRefs'?: { TweetFragmentFragment: TweetFragmentFragment }; + } > | null; } & { ' $fragmentName'?: 'TweetsFragmentFragment' }; diff --git a/dev-test/gql-tag-operations-masking/src/index.tsx b/dev-test/gql-tag-operations-masking/src/index.tsx index 69f4c2499f7..0840526f665 100644 --- a/dev-test/gql-tag-operations-masking/src/index.tsx +++ b/dev-test/gql-tag-operations-masking/src/index.tsx @@ -1,7 +1,7 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import React from 'react'; -import { graphql, FragmentType, useFragment } from '../gql'; import { useQuery } from 'urql'; +import { FragmentType, graphql, useFragment } from '../gql'; const TweetFragment = graphql(/* GraphQL */ ` fragment TweetFragment on Tweet { diff --git a/dev-test/gql-tag-operations-urql/gql/fragment-masking.ts b/dev-test/gql-tag-operations-urql/gql/fragment-masking.ts index a6b3407f590..749b250a4de 100644 --- a/dev-test/gql-tag-operations-urql/gql/fragment-masking.ts +++ b/dev-test/gql-tag-operations-urql/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql.js'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/dev-test/gql-tag-operations-urql/gql/gql.d.ts b/dev-test/gql-tag-operations-urql/gql/gql.d.ts index 1e3e635d9a1..b74a83b2488 100644 --- a/dev-test/gql-tag-operations-urql/gql/gql.d.ts +++ b/dev-test/gql-tag-operations-urql/gql/gql.d.ts @@ -6,26 +6,22 @@ declare module '@urql/core' { * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function gql( - source: '\n query Foo {\n Tweets {\n id\n }\n }\n' + source: '\n query Foo {\n Tweets {\n id\n }\n }\n', ): typeof import('./graphql.js').FooDocument; /** * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function gql( - source: '\n fragment Lel on Tweet {\n id\n body\n }\n' + source: '\n fragment Lel on Tweet {\n id\n body\n }\n', ): typeof import('./graphql.js').LelFragmentDoc; /** * The gql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function gql( - source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n' + source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n', ): typeof import('./graphql.js').BarDocument; export function gql(source: string): unknown; - export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any - > - ? TType - : never; + export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; } diff --git a/dev-test/gql-tag-operations-urql/gql/gql.ts b/dev-test/gql-tag-operations-urql/gql/gql.ts index e6fd0f7db35..78730dcb79a 100644 --- a/dev-test/gql-tag-operations-urql/gql/gql.ts +++ b/dev-test/gql-tag-operations-urql/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql.js'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql.js'; /** * Map of all GraphQL operations in the project. @@ -37,28 +37,24 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query Foo {\n Tweets {\n id\n }\n }\n' + source: '\n query Foo {\n Tweets {\n id\n }\n }\n', ): (typeof documents)['\n query Foo {\n Tweets {\n id\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment Lel on Tweet {\n id\n body\n }\n' + source: '\n fragment Lel on Tweet {\n id\n body\n }\n', ): (typeof documents)['\n fragment Lel on Tweet {\n id\n body\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n' + source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n', ): (typeof documents)['\n query Bar {\n Tweets {\n ...Lel\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/dev-test/gql-tag-operations-urql/gql/graphql.ts b/dev-test/gql-tag-operations-urql/gql/graphql.ts index 57a9d9536d6..499a1634d76 100644 --- a/dev-test/gql-tag-operations-urql/gql/graphql.ts +++ b/dev-test/gql-tag-operations-urql/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -20,7 +25,10 @@ export type Scalars = { export type FooQueryVariables = Exact<{ [key: string]: never }>; -export type FooQuery = { __typename?: 'Query'; Tweets?: Array<{ __typename?: 'Tweet'; id: string } | null> | null }; +export type FooQuery = { + __typename?: 'Query'; + Tweets?: Array<{ __typename?: 'Tweet'; id: string } | null> | null; +}; export type LelFragment = { __typename?: 'Tweet'; id: string; body?: string | null } & { ' $fragmentName'?: 'LelFragment'; @@ -30,7 +38,9 @@ export type BarQueryVariables = Exact<{ [key: string]: never }>; export type BarQuery = { __typename?: 'Query'; - Tweets?: Array<({ __typename?: 'Tweet' } & { ' $fragmentRefs'?: { LelFragment: LelFragment } }) | null> | null; + Tweets?: Array< + ({ __typename?: 'Tweet' } & { ' $fragmentRefs'?: { LelFragment: LelFragment } }) | null + > | null; }; export const LelFragmentDoc = { diff --git a/dev-test/gql-tag-operations/gql/fragment-masking.ts b/dev-test/gql-tag-operations/gql/fragment-masking.ts index a6b3407f590..749b250a4de 100644 --- a/dev-test/gql-tag-operations/gql/fragment-masking.ts +++ b/dev-test/gql-tag-operations/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql.js'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/dev-test/gql-tag-operations/gql/gql.ts b/dev-test/gql-tag-operations/gql/gql.ts index e6fd0f7db35..78730dcb79a 100644 --- a/dev-test/gql-tag-operations/gql/gql.ts +++ b/dev-test/gql-tag-operations/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql.js'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql.js'; /** * Map of all GraphQL operations in the project. @@ -37,28 +37,24 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query Foo {\n Tweets {\n id\n }\n }\n' + source: '\n query Foo {\n Tweets {\n id\n }\n }\n', ): (typeof documents)['\n query Foo {\n Tweets {\n id\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment Lel on Tweet {\n id\n body\n }\n' + source: '\n fragment Lel on Tweet {\n id\n body\n }\n', ): (typeof documents)['\n fragment Lel on Tweet {\n id\n body\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n' + source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n', ): (typeof documents)['\n query Bar {\n Tweets {\n ...Lel\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/dev-test/gql-tag-operations/gql/graphql.ts b/dev-test/gql-tag-operations/gql/graphql.ts index 57a9d9536d6..499a1634d76 100644 --- a/dev-test/gql-tag-operations/gql/graphql.ts +++ b/dev-test/gql-tag-operations/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -20,7 +25,10 @@ export type Scalars = { export type FooQueryVariables = Exact<{ [key: string]: never }>; -export type FooQuery = { __typename?: 'Query'; Tweets?: Array<{ __typename?: 'Tweet'; id: string } | null> | null }; +export type FooQuery = { + __typename?: 'Query'; + Tweets?: Array<{ __typename?: 'Tweet'; id: string } | null> | null; +}; export type LelFragment = { __typename?: 'Tweet'; id: string; body?: string | null } & { ' $fragmentName'?: 'LelFragment'; @@ -30,7 +38,9 @@ export type BarQueryVariables = Exact<{ [key: string]: never }>; export type BarQuery = { __typename?: 'Query'; - Tweets?: Array<({ __typename?: 'Tweet' } & { ' $fragmentRefs'?: { LelFragment: LelFragment } }) | null> | null; + Tweets?: Array< + ({ __typename?: 'Tweet' } & { ' $fragmentRefs'?: { LelFragment: LelFragment } }) | null + > | null; }; export const LelFragmentDoc = { diff --git a/dev-test/gql-tag-operations/graphql/fragment-masking.ts b/dev-test/gql-tag-operations/graphql/fragment-masking.ts index a6b3407f590..749b250a4de 100644 --- a/dev-test/gql-tag-operations/graphql/fragment-masking.ts +++ b/dev-test/gql-tag-operations/graphql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql.js'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/dev-test/gql-tag-operations/graphql/gql.ts b/dev-test/gql-tag-operations/graphql/gql.ts index e6fd0f7db35..78730dcb79a 100644 --- a/dev-test/gql-tag-operations/graphql/gql.ts +++ b/dev-test/gql-tag-operations/graphql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql.js'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql.js'; /** * Map of all GraphQL operations in the project. @@ -37,28 +37,24 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query Foo {\n Tweets {\n id\n }\n }\n' + source: '\n query Foo {\n Tweets {\n id\n }\n }\n', ): (typeof documents)['\n query Foo {\n Tweets {\n id\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment Lel on Tweet {\n id\n body\n }\n' + source: '\n fragment Lel on Tweet {\n id\n body\n }\n', ): (typeof documents)['\n fragment Lel on Tweet {\n id\n body\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n' + source: '\n query Bar {\n Tweets {\n ...Lel\n }\n }\n', ): (typeof documents)['\n query Bar {\n Tweets {\n ...Lel\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/dev-test/gql-tag-operations/graphql/graphql.ts b/dev-test/gql-tag-operations/graphql/graphql.ts index 57a9d9536d6..499a1634d76 100644 --- a/dev-test/gql-tag-operations/graphql/graphql.ts +++ b/dev-test/gql-tag-operations/graphql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -20,7 +25,10 @@ export type Scalars = { export type FooQueryVariables = Exact<{ [key: string]: never }>; -export type FooQuery = { __typename?: 'Query'; Tweets?: Array<{ __typename?: 'Tweet'; id: string } | null> | null }; +export type FooQuery = { + __typename?: 'Query'; + Tweets?: Array<{ __typename?: 'Tweet'; id: string } | null> | null; +}; export type LelFragment = { __typename?: 'Tweet'; id: string; body?: string | null } & { ' $fragmentName'?: 'LelFragment'; @@ -30,7 +38,9 @@ export type BarQueryVariables = Exact<{ [key: string]: never }>; export type BarQuery = { __typename?: 'Query'; - Tweets?: Array<({ __typename?: 'Tweet' } & { ' $fragmentRefs'?: { LelFragment: LelFragment } }) | null> | null; + Tweets?: Array< + ({ __typename?: 'Tweet' } & { ' $fragmentRefs'?: { LelFragment: LelFragment } }) | null + > | null; }; export const LelFragmentDoc = { diff --git a/dev-test/gql-tag-operations/src/index.ts b/dev-test/gql-tag-operations/src/index.ts index e491e7984a2..884fce3543a 100644 --- a/dev-test/gql-tag-operations/src/index.ts +++ b/dev-test/gql-tag-operations/src/index.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ -import { graphql, DocumentType } from '../gql/gql.js'; +import { DocumentType, graphql } from '../gql/gql.js'; const FooQuery = graphql(/* GraphQL */ ` query Foo { diff --git a/dev-test/modules/blog/generated.ts b/dev-test/modules/blog/generated.ts index e07df5c87a3..7c66c31a4c7 100644 --- a/dev-test/modules/blog/generated.ts +++ b/dev-test/modules/blog/generated.ts @@ -1,5 +1,6 @@ -import * as Types from '../types'; import * as gm from 'graphql-modules'; +import * as Types from '../types'; + export namespace BlogModule { interface DefinedFields { Article: 'id' | 'title' | 'text' | 'author'; @@ -10,7 +11,10 @@ export namespace BlogModule { export type User = Types.User; export type Query = Pick; - export type ArticleResolvers = Pick; + export type ArticleResolvers = Pick< + Types.ArticleResolvers, + DefinedFields['Article'] | '__isTypeOf' + >; export type QueryResolvers = Pick; export interface Resolvers { diff --git a/dev-test/modules/common/generated.ts b/dev-test/modules/common/generated.ts index a752da79b8b..45be0d3bb96 100644 --- a/dev-test/modules/common/generated.ts +++ b/dev-test/modules/common/generated.ts @@ -1,5 +1,6 @@ -import * as Types from '../types'; import * as gm from 'graphql-modules'; +import * as Types from '../types'; + export namespace CommonModule { interface DefinedFields { Query: 'ping'; diff --git a/dev-test/modules/dotanions/generated.ts b/dev-test/modules/dotanions/generated.ts index 62fb37894f5..35bbd095982 100644 --- a/dev-test/modules/dotanions/generated.ts +++ b/dev-test/modules/dotanions/generated.ts @@ -1,5 +1,6 @@ -import * as Types from '../types'; import * as gm from 'graphql-modules'; +import * as Types from '../types'; + export namespace DotanionsModule { interface DefinedFields { Paypal: 'id' | 'url'; @@ -22,8 +23,14 @@ export namespace DotanionsModule { export type Mutation = Pick; export type PaypalResolvers = Pick; - export type CreditCardResolvers = Pick; - export type DonationResolvers = Pick; + export type CreditCardResolvers = Pick< + Types.CreditCardResolvers, + DefinedFields['CreditCard'] | '__isTypeOf' + >; + export type DonationResolvers = Pick< + Types.DonationResolvers, + DefinedFields['Donation'] | '__isTypeOf' + >; export type MutationResolvers = Pick; export type UserResolvers = Pick; diff --git a/dev-test/modules/types.ts b/dev-test/modules/types.ts index 4a4bf594d23..8d34a711496 100644 --- a/dev-test/modules/types.ts +++ b/dev-test/modules/types.ts @@ -1,11 +1,16 @@ import { GraphQLResolveInfo } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type Omit = Pick>; export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** All built-in and custom scalars, mapped to their actual values */ @@ -107,24 +112,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -138,20 +149,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -161,7 +178,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping of union types */ @@ -175,7 +192,10 @@ export type ResolversTypes = { Boolean: ResolverTypeWrapper; CreditCard: ResolverTypeWrapper; Donation: ResolverTypeWrapper< - Omit & { recipient: ResolversTypes['User']; sender: ResolversTypes['User'] } + Omit & { + recipient: ResolversTypes['User']; + sender: ResolversTypes['User']; + } >; DonationInput: DonationInput; Float: ResolverTypeWrapper; @@ -187,7 +207,9 @@ export type ResolversTypes = { Query: ResolverTypeWrapper<{}>; String: ResolverTypeWrapper; User: ResolverTypeWrapper< - Omit & { paymentOptions?: Maybe> } + Omit & { + paymentOptions?: Maybe>; + } >; }; @@ -209,12 +231,14 @@ export type ResolversParentTypes = { Paypal: Paypal; Query: {}; String: Scalars['String']['output']; - User: Omit & { paymentOptions?: Maybe> }; + User: Omit & { + paymentOptions?: Maybe>; + }; }; export type ArticleResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Article'] = ResolversParentTypes['Article'] + ParentType extends ResolversParentTypes['Article'] = ResolversParentTypes['Article'], > = { author?: Resolver; id?: Resolver; @@ -225,7 +249,7 @@ export type ArticleResolvers< export type CreditCardResolvers< ContextType = any, - ParentType extends ResolversParentTypes['CreditCard'] = ResolversParentTypes['CreditCard'] + ParentType extends ResolversParentTypes['CreditCard'] = ResolversParentTypes['CreditCard'], > = { cardNumber?: Resolver; cardOwner?: Resolver; @@ -235,7 +259,7 @@ export type CreditCardResolvers< export type DonationResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Donation'] = ResolversParentTypes['Donation'] + ParentType extends ResolversParentTypes['Donation'] = ResolversParentTypes['Donation'], > = { amount?: Resolver; id?: Resolver; @@ -246,22 +270,27 @@ export type DonationResolvers< export type MutationResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation'] + ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation'], > = { - donate?: Resolver, ParentType, ContextType, Partial>; + donate?: Resolver< + Maybe, + ParentType, + ContextType, + Partial + >; pong?: Resolver, ParentType, ContextType>; }; export type PaymentOptionResolvers< ContextType = any, - ParentType extends ResolversParentTypes['PaymentOption'] = ResolversParentTypes['PaymentOption'] + ParentType extends ResolversParentTypes['PaymentOption'] = ResolversParentTypes['PaymentOption'], > = { __resolveType: TypeResolveFn<'CreditCard' | 'Paypal', ParentType, ContextType>; }; export type PaypalResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Paypal'] = ResolversParentTypes['Paypal'] + ParentType extends ResolversParentTypes['Paypal'] = ResolversParentTypes['Paypal'], > = { id?: Resolver; url?: Resolver; @@ -270,7 +299,7 @@ export type PaypalResolvers< export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { articleById?: Resolver< Maybe, @@ -286,13 +315,18 @@ export type QueryResolvers< RequireFields >; ping?: Resolver, ParentType, ContextType>; - userById?: Resolver, ParentType, ContextType, RequireFields>; + userById?: Resolver< + Maybe, + ParentType, + ContextType, + RequireFields + >; users?: Resolver>, ParentType, ContextType>; }; export type UserResolvers< ContextType = any, - ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] + ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'], > = { firstName?: Resolver; id?: Resolver; diff --git a/dev-test/modules/users/generated.ts b/dev-test/modules/users/generated.ts index 61891947659..b94f3bedf04 100644 --- a/dev-test/modules/users/generated.ts +++ b/dev-test/modules/users/generated.ts @@ -1,5 +1,6 @@ -import * as Types from '../types'; import * as gm from 'graphql-modules'; +import * as Types from '../types'; + export namespace UsersModule { interface DefinedFields { User: 'id' | 'firstName' | 'lastName'; diff --git a/dev-test/star-wars/types.avoidOptionals.ts b/dev-test/star-wars/types.avoidOptionals.ts index 02b567a168e..9f902a4cf66 100644 --- a/dev-test/star-wars/types.avoidOptionals.ts +++ b/dev-test/star-wars/types.avoidOptionals.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -278,12 +282,16 @@ export type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -310,7 +318,11 @@ export type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height: number | null; name: string }; @@ -368,14 +380,18 @@ export type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height: number | null; name: string } + | null > | null; } | null; @@ -387,7 +403,10 @@ export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ export type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero: { __typename?: 'Droid'; property: string | null } | { __typename?: 'Human'; property: string | null } | null; + hero: + | { __typename?: 'Droid'; property: string | null } + | { __typename?: 'Human'; property: string | null } + | null; }; export type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass: number | null }; diff --git a/dev-test/star-wars/types.d.ts b/dev-test/star-wars/types.d.ts index 74b3623a681..3cf2a972200 100644 --- a/dev-test/star-wars/types.d.ts +++ b/dev-test/star-wars/types.d.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/dev-test/star-wars/types.excludeQueryAlpha.ts b/dev-test/star-wars/types.excludeQueryAlpha.ts index c74b2d6c85e..58688ef48c7 100644 --- a/dev-test/star-wars/types.excludeQueryAlpha.ts +++ b/dev-test/star-wars/types.excludeQueryAlpha.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -269,12 +273,16 @@ export type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -301,7 +309,11 @@ export type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction?: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction?: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height?: number | null; name: string }; @@ -359,14 +371,18 @@ export type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | null; @@ -378,7 +394,10 @@ export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ export type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero?: { __typename?: 'Droid'; property?: string | null } | { __typename?: 'Human'; property?: string | null } | null; + hero?: + | { __typename?: 'Droid'; property?: string | null } + | { __typename?: 'Human'; property?: string | null } + | null; }; export type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass?: number | null }; diff --git a/dev-test/star-wars/types.excludeQueryBeta.ts b/dev-test/star-wars/types.excludeQueryBeta.ts index 4a8b70efeaa..43677ef773d 100644 --- a/dev-test/star-wars/types.excludeQueryBeta.ts +++ b/dev-test/star-wars/types.excludeQueryBeta.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -269,12 +273,16 @@ export type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -301,7 +309,11 @@ export type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction?: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction?: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height?: number | null; name: string }; @@ -359,14 +371,18 @@ export type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | null; @@ -378,7 +394,10 @@ export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ export type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero?: { __typename?: 'Droid'; property?: string | null } | { __typename?: 'Human'; property?: string | null } | null; + hero?: + | { __typename?: 'Droid'; property?: string | null } + | { __typename?: 'Human'; property?: string | null } + | null; }; export type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass?: number | null }; diff --git a/dev-test/star-wars/types.globallyAvailable.d.ts b/dev-test/star-wars/types.globallyAvailable.d.ts index 4a40839de60..4bc089978b1 100644 --- a/dev-test/star-wars/types.globallyAvailable.d.ts +++ b/dev-test/star-wars/types.globallyAvailable.d.ts @@ -4,7 +4,9 @@ type Exact = { [K in keyof T]: T[K] }; type MakeOptional = Omit & { [SubKey in K]?: Maybe }; type MakeMaybe = Omit & { [SubKey in K]: Maybe }; type MakeEmpty = { [_ in K]?: never }; -type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ type Scalars = { ID: { input: string; output: string }; @@ -276,12 +278,16 @@ type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -308,7 +314,11 @@ type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction?: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction?: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height?: number | null; name: string }; @@ -366,14 +376,18 @@ type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | null; @@ -385,7 +399,10 @@ type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero?: { __typename?: 'Droid'; property?: string | null } | { __typename?: 'Human'; property?: string | null } | null; + hero?: + | { __typename?: 'Droid'; property?: string | null } + | { __typename?: 'Human'; property?: string | null } + | null; }; type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass?: number | null }; diff --git a/dev-test/star-wars/types.immutableTypes.ts b/dev-test/star-wars/types.immutableTypes.ts index b058821dbb1..eb4f1283e16 100644 --- a/dev-test/star-wars/types.immutableTypes.ts +++ b/dev-test/star-wars/types.immutableTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -311,8 +315,16 @@ export type HeroAppearsInQueryVariables = Exact<{ [key: string]: never }>; export type HeroAppearsInQuery = { readonly __typename?: 'Query'; readonly hero?: - | { readonly __typename?: 'Droid'; readonly name: string; readonly appearsIn: ReadonlyArray } - | { readonly __typename?: 'Human'; readonly name: string; readonly appearsIn: ReadonlyArray } + | { + readonly __typename?: 'Droid'; + readonly name: string; + readonly appearsIn: ReadonlyArray; + } + | { + readonly __typename?: 'Human'; + readonly name: string; + readonly appearsIn: ReadonlyArray; + } | null; }; @@ -323,7 +335,11 @@ export type HeroDetailsQueryVariables = Exact<{ export type HeroDetailsQuery = { readonly __typename?: 'Query'; readonly hero?: - | { readonly __typename?: 'Droid'; readonly primaryFunction?: string | null; readonly name: string } + | { + readonly __typename?: 'Droid'; + readonly primaryFunction?: string | null; + readonly name: string; + } | { readonly __typename?: 'Human'; readonly height?: number | null; readonly name: string } | null; }; @@ -349,7 +365,11 @@ export type HeroDetailsWithFragmentQueryVariables = Exact<{ export type HeroDetailsWithFragmentQuery = { readonly __typename?: 'Query'; readonly hero?: - | { readonly __typename?: 'Droid'; readonly primaryFunction?: string | null; readonly name: string } + | { + readonly __typename?: 'Droid'; + readonly primaryFunction?: string | null; + readonly name: string; + } | { readonly __typename?: 'Human'; readonly height?: number | null; readonly name: string } | null; }; @@ -404,7 +424,11 @@ export type HeroParentTypeDependentFieldQuery = { readonly name: string; readonly friends?: ReadonlyArray< | { readonly __typename?: 'Droid'; readonly name: string } - | { readonly __typename?: 'Human'; readonly height?: number | null; readonly name: string } + | { + readonly __typename?: 'Human'; + readonly height?: number | null; + readonly name: string; + } | null > | null; } @@ -413,7 +437,11 @@ export type HeroParentTypeDependentFieldQuery = { readonly name: string; readonly friends?: ReadonlyArray< | { readonly __typename?: 'Droid'; readonly name: string } - | { readonly __typename?: 'Human'; readonly height?: number | null; readonly name: string } + | { + readonly __typename?: 'Human'; + readonly height?: number | null; + readonly name: string; + } | null > | null; } @@ -442,7 +470,11 @@ export type HumanWithNullHeightQueryVariables = Exact<{ [key: string]: never }>; export type HumanWithNullHeightQuery = { readonly __typename?: 'Query'; - readonly human?: { readonly __typename?: 'Human'; readonly name: string; readonly mass?: number | null } | null; + readonly human?: { + readonly __typename?: 'Human'; + readonly name: string; + readonly mass?: number | null; + } | null; }; export type TwoHeroesQueryVariables = Exact<{ [key: string]: never }>; diff --git a/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts b/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts index 7ec1e20377e..8a7dfa7c6ae 100644 --- a/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts +++ b/dev-test/star-wars/types.preResolveTypes.onlyOperationTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -87,12 +91,16 @@ export type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -119,7 +127,11 @@ export type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction?: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction?: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height?: number | null; name: string }; @@ -177,14 +189,18 @@ export type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | null; @@ -196,7 +212,10 @@ export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ export type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero?: { __typename?: 'Droid'; property?: string | null } | { __typename?: 'Human'; property?: string | null } | null; + hero?: + | { __typename?: 'Droid'; property?: string | null } + | { __typename?: 'Human'; property?: string | null } + | null; }; export type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass?: number | null }; diff --git a/dev-test/star-wars/types.preResolveTypes.ts b/dev-test/star-wars/types.preResolveTypes.ts index d580beb2eb5..48c07f03464 100644 --- a/dev-test/star-wars/types.preResolveTypes.ts +++ b/dev-test/star-wars/types.preResolveTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -278,12 +282,16 @@ export type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -310,7 +318,11 @@ export type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction?: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction?: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height?: number | null; name: string }; @@ -368,14 +380,18 @@ export type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | null; @@ -387,7 +403,10 @@ export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ export type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero?: { __typename?: 'Droid'; property?: string | null } | { __typename?: 'Human'; property?: string | null } | null; + hero?: + | { __typename?: 'Droid'; property?: string | null } + | { __typename?: 'Human'; property?: string | null } + | null; }; export type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass?: number | null }; diff --git a/dev-test/star-wars/types.skipSchema.ts b/dev-test/star-wars/types.skipSchema.ts index d580beb2eb5..48c07f03464 100644 --- a/dev-test/star-wars/types.skipSchema.ts +++ b/dev-test/star-wars/types.skipSchema.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -278,12 +282,16 @@ export type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -310,7 +318,11 @@ export type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction?: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction?: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height?: number | null; name: string }; @@ -368,14 +380,18 @@ export type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | null; @@ -387,7 +403,10 @@ export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ export type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero?: { __typename?: 'Droid'; property?: string | null } | { __typename?: 'Human'; property?: string | null } | null; + hero?: + | { __typename?: 'Droid'; property?: string | null } + | { __typename?: 'Human'; property?: string | null } + | null; }; export type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass?: number | null }; diff --git a/dev-test/star-wars/types.ts b/dev-test/star-wars/types.ts index d580beb2eb5..48c07f03464 100644 --- a/dev-test/star-wars/types.ts +++ b/dev-test/star-wars/types.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -278,12 +282,16 @@ export type HeroAndFriendsNamesQuery = { | { __typename?: 'Droid'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | { __typename?: 'Human'; name: string; - friends?: Array<{ __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null> | null; + friends?: Array< + { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; name: string } | null + > | null; } | null; }; @@ -310,7 +318,11 @@ export type HeroDetailsQuery = { | null; }; -type HeroDetails_Droid_Fragment = { __typename?: 'Droid'; primaryFunction?: string | null; name: string }; +type HeroDetails_Droid_Fragment = { + __typename?: 'Droid'; + primaryFunction?: string | null; + name: string; +}; type HeroDetails_Human_Fragment = { __typename?: 'Human'; height?: number | null; name: string }; @@ -368,14 +380,18 @@ export type HeroParentTypeDependentFieldQuery = { __typename?: 'Droid'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | { __typename?: 'Human'; name: string; friends?: Array< - { __typename?: 'Droid'; name: string } | { __typename?: 'Human'; height?: number | null; name: string } | null + | { __typename?: 'Droid'; name: string } + | { __typename?: 'Human'; height?: number | null; name: string } + | null > | null; } | null; @@ -387,7 +403,10 @@ export type HeroTypeDependentAliasedFieldQueryVariables = Exact<{ export type HeroTypeDependentAliasedFieldQuery = { __typename?: 'Query'; - hero?: { __typename?: 'Droid'; property?: string | null } | { __typename?: 'Human'; property?: string | null } | null; + hero?: + | { __typename?: 'Droid'; property?: string | null } + | { __typename?: 'Human'; property?: string | null } + | null; }; export type HumanFieldsFragment = { __typename?: 'Human'; name: string; mass?: number | null }; diff --git a/dev-test/subpath-import/result.d.ts b/dev-test/subpath-import/result.d.ts index f066002aea9..21caa10bd36 100644 --- a/dev-test/subpath-import/result.d.ts +++ b/dev-test/subpath-import/result.d.ts @@ -1,14 +1,19 @@ import { RoleStatus } from '#changeName/server/drizzle/schema'; -import { GraphQLResolveInfo } from 'graphql'; import { TestContext } from '#test-null-value/context'; import { FiedContextType } from '#test/root'; +import { GraphQLResolveInfo } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type EnumResolverSignature = { [key in keyof T]?: AllowedValues }; export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** All built-in and custom scalars, mapped to their actual values */ @@ -56,24 +61,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -87,20 +98,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -110,7 +127,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -132,11 +149,14 @@ export type ResolversParentTypes = { mutation: Mutation; }; -export type RoleStatusResolvers = EnumResolverSignature<{ ADMIN?: any; USER?: any }, ResolversTypes['RoleStatus']>; +export type RoleStatusResolvers = EnumResolverSignature< + { ADMIN?: any; USER?: any }, + ResolversTypes['RoleStatus'] +>; export type UserResolvers< ContextType = TestContext, - ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] + ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'], > = { createdAt?: Resolver; email?: Resolver; @@ -149,7 +169,7 @@ export type UserResolvers< export type MutationResolvers< ContextType = TestContext, - ParentType extends ResolversParentTypes['mutation'] = ResolversParentTypes['mutation'] + ParentType extends ResolversParentTypes['mutation'] = ResolversParentTypes['mutation'], > = { createUser?: Resolver< ResolversTypes['User'], diff --git a/dev-test/test-null-value/result.d.ts b/dev-test/test-null-value/result.d.ts index 9e88d265c27..8b97092ed9b 100644 --- a/dev-test/test-null-value/result.d.ts +++ b/dev-test/test-null-value/result.d.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -47,4 +51,6 @@ export type CartLineFragment = { id: string; quantity: number }; export type TestQueryVariables = Exact<{ [key: string]: never }>; -export type TestQuery = { cart?: { lines: { nodes: Array<{ id: string; quantity: number }> } } | null }; +export type TestQuery = { + cart?: { lines: { nodes: Array<{ id: string; quantity: number }> } } | null; +}; diff --git a/dev-test/test-schema/env.types.ts b/dev-test/test-schema/env.types.ts index a21f1f2cd58..16b18213fcd 100644 --- a/dev-test/test-schema/env.types.ts +++ b/dev-test/test-schema/env.types.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/dev-test/test-schema/resolvers-federation.ts b/dev-test/test-schema/resolvers-federation.ts index d2c05ac9d13..bcb97564ead 100644 --- a/dev-test/test-schema/resolvers-federation.ts +++ b/dev-test/test-schema/resolvers-federation.ts @@ -1,11 +1,16 @@ import { GraphQLResolveInfo } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -52,11 +57,12 @@ export type ResolverTypeWrapper = Promise | T; export type ReferenceResolver = ( reference: TReference, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; type ScalarCheck = S extends true ? T : NullableCheck; -type NullableCheck = Maybe extends T ? Maybe, S>> : ListCheck; +type NullableCheck = + Maybe extends T ? Maybe, S>> : ListCheck; type ListCheck = T extends (infer U)[] ? NullableCheck[] : GraphQLRecursivePick; export type GraphQLRecursivePick = { [K in keyof T & keyof S]: ScalarCheck }; @@ -71,24 +77,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -102,20 +114,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -125,7 +143,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -156,7 +174,7 @@ export type ResolversParentTypes = { export type AddressResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Address'] = ResolversParentTypes['Address'] + ParentType extends ResolversParentTypes['Address'] = ResolversParentTypes['Address'], > = { city?: Resolver, ParentType, ContextType>; lines?: Resolver; @@ -166,7 +184,7 @@ export type AddressResolvers< export type BookResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Book'] = ResolversParentTypes['Book'] + ParentType extends ResolversParentTypes['Book'] = ResolversParentTypes['Book'], > = { id?: Resolver; __isTypeOf?: IsTypeOfResolverFn; @@ -174,7 +192,7 @@ export type BookResolvers< export type LinesResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Lines'] = ResolversParentTypes['Lines'] + ParentType extends ResolversParentTypes['Lines'] = ResolversParentTypes['Lines'], > = { line1?: Resolver; line2?: Resolver, ParentType, ContextType>; @@ -183,14 +201,14 @@ export type LinesResolvers< export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { users?: Resolver>>, ParentType, ContextType>; }; export type UserResolvers< ContextType = any, - ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] + ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'], > = { __resolveReference?: ReferenceResolver< Maybe, diff --git a/dev-test/test-schema/resolvers-root.ts b/dev-test/test-schema/resolvers-root.ts index ca4941f0f61..886601b7cb9 100644 --- a/dev-test/test-schema/resolvers-root.ts +++ b/dev-test/test-schema/resolvers-root.ts @@ -1,11 +1,16 @@ import { GraphQLResolveInfo } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { @@ -57,24 +62,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -88,20 +99,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -111,7 +128,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -138,7 +155,7 @@ export type ResolversParentTypes = { export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { someDummyField?: Resolver; __isTypeOf?: IsTypeOfResolverFn; @@ -146,7 +163,7 @@ export type QueryResolvers< export type QueryRootResolvers< ContextType = any, - ParentType extends ResolversParentTypes['QueryRoot'] = ResolversParentTypes['QueryRoot'] + ParentType extends ResolversParentTypes['QueryRoot'] = ResolversParentTypes['QueryRoot'], > = { allUsers?: Resolver>, ParentType, ContextType>; answer?: Resolver, ParentType, ContextType>; @@ -160,14 +177,15 @@ export type QueryRootResolvers< export type SubscriptionRootResolvers< ContextType = any, - ParentType extends ResolversParentTypes['SubscriptionRoot'] = ResolversParentTypes['SubscriptionRoot'] + ParentType extends + ResolversParentTypes['SubscriptionRoot'] = ResolversParentTypes['SubscriptionRoot'], > = { newUser?: SubscriptionResolver, 'newUser', ParentType, ContextType>; }; export type UserResolvers< ContextType = any, - ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] + ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'], > = { email?: Resolver; id?: Resolver; diff --git a/dev-test/test-schema/resolvers-stitching.ts b/dev-test/test-schema/resolvers-stitching.ts index 8954a721b9a..1610ba182b5 100644 --- a/dev-test/test-schema/resolvers-stitching.ts +++ b/dev-test/test-schema/resolvers-stitching.ts @@ -1,11 +1,16 @@ -import { GraphQLResolveInfo, SelectionSetNode, FieldNode } from 'graphql'; +import { FieldNode, GraphQLResolveInfo, SelectionSetNode } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { @@ -68,24 +73,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -99,20 +110,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -122,7 +139,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -145,19 +162,24 @@ export type ResolversParentTypes = { export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { allUsers?: Resolver>, ParentType, ContextType>; answer?: Resolver, ParentType, ContextType>; testArr1?: Resolver>>, ParentType, ContextType>; testArr2?: Resolver>, ParentType, ContextType>; testArr3?: Resolver, ParentType, ContextType>; - userById?: Resolver, ParentType, ContextType, RequireFields>; + userById?: Resolver< + Maybe, + ParentType, + ContextType, + RequireFields + >; }; export type UserResolvers< ContextType = any, - ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] + ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'], > = { email?: Resolver; id?: Resolver; diff --git a/dev-test/test-schema/resolvers-types.ts b/dev-test/test-schema/resolvers-types.ts index 6bb026ac0c8..f43f8955efe 100644 --- a/dev-test/test-schema/resolvers-types.ts +++ b/dev-test/test-schema/resolvers-types.ts @@ -1,11 +1,16 @@ import { GraphQLResolveInfo } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { @@ -54,24 +59,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -85,20 +96,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -108,7 +125,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -131,19 +148,24 @@ export type ResolversParentTypes = { export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { allUsers?: Resolver>, ParentType, ContextType>; answer?: Resolver, ParentType, ContextType>; testArr1?: Resolver>>, ParentType, ContextType>; testArr2?: Resolver>, ParentType, ContextType>; testArr3?: Resolver, ParentType, ContextType>; - userById?: Resolver, ParentType, ContextType, RequireFields>; + userById?: Resolver< + Maybe, + ParentType, + ContextType, + RequireFields + >; }; export type UserResolvers< ContextType = any, - ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] + ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'], > = { email?: Resolver; id?: Resolver; diff --git a/dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts b/dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts index 8c580b61f78..dff81900611 100644 --- a/dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts +++ b/dev-test/test-schema/types.preResolveTypes.onlyOperationTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/dev-test/test-schema/types.preResolveTypes.ts b/dev-test/test-schema/types.preResolveTypes.ts index 472613688cf..4d0ee75aa17 100644 --- a/dev-test/test-schema/types.preResolveTypes.ts +++ b/dev-test/test-schema/types.preResolveTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/dev-test/test-schema/typings.avoidOptionals.ts b/dev-test/test-schema/typings.avoidOptionals.ts index 43e966058f7..855268c0ff4 100644 --- a/dev-test/test-schema/typings.avoidOptionals.ts +++ b/dev-test/test-schema/typings.avoidOptionals.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/dev-test/test-schema/typings.enum.ts b/dev-test/test-schema/typings.enum.ts index 491b66ac691..7fe50ed4a55 100644 --- a/dev-test/test-schema/typings.enum.ts +++ b/dev-test/test-schema/typings.enum.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/dev-test/test-schema/typings.immutableTypes.ts b/dev-test/test-schema/typings.immutableTypes.ts index c8a55b067b5..24c3af3f281 100644 --- a/dev-test/test-schema/typings.immutableTypes.ts +++ b/dev-test/test-schema/typings.immutableTypes.ts @@ -3,8 +3,12 @@ export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/dev-test/test-schema/typings.ts b/dev-test/test-schema/typings.ts index 707d55a9502..cd76066a3b1 100644 --- a/dev-test/test-schema/typings.ts +++ b/dev-test/test-schema/typings.ts @@ -1,11 +1,16 @@ import { GraphQLResolveInfo } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { @@ -46,24 +51,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -77,20 +88,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -100,7 +117,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -123,15 +140,20 @@ export type ResolversParentTypes = { export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { allUsers?: Resolver>, ParentType, ContextType>; - userById?: Resolver, ParentType, ContextType, RequireFields>; + userById?: Resolver< + Maybe, + ParentType, + ContextType, + RequireFields + >; }; export type UserResolvers< ContextType = any, - ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] + ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'], > = { email?: Resolver; id?: Resolver; diff --git a/dev-test/test-schema/typings.wrapped.ts b/dev-test/test-schema/typings.wrapped.ts index a17ae3d1de2..bdacb9bc37b 100644 --- a/dev-test/test-schema/typings.wrapped.ts +++ b/dev-test/test-schema/typings.wrapped.ts @@ -2,10 +2,16 @@ declare namespace GraphQL { export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; - export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; + export type MakeOptional = Omit & { + [SubKey in K]?: Maybe; + }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; - export type MakeEmpty = { [_ in K]?: never }; - export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; + export type MakeEmpty = { + [_ in K]?: never; + }; + export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; diff --git a/examples/persisted-documents-string-mode/README.md b/examples/persisted-documents-string-mode/README.md index a0aab1c6bdd..04b4d7d7eee 100644 --- a/examples/persisted-documents-string-mode/README.md +++ b/examples/persisted-documents-string-mode/README.md @@ -1,6 +1,7 @@ # Yoga Persisted Documents Example -Example for showing how to use GraphQL Code Generator for only allowing the execution of persisted operations. +Example for showing how to use GraphQL Code Generator for only allowing the execution of persisted +operations. [Learn more about Yoga Persisted Operations](https://the-guild.dev/graphql/yoga-server/docs/features/persisted-operations) diff --git a/examples/persisted-documents-string-mode/package.json b/examples/persisted-documents-string-mode/package.json index 83ffa42f522..71f18ba8cca 100644 --- a/examples/persisted-documents-string-mode/package.json +++ b/examples/persisted-documents-string-mode/package.json @@ -2,24 +2,24 @@ "name": "example-persisted-documents-string-mode", "version": "0.0.0", "private": true, + "scripts": { + "build": "tsc", + "codegen": "graphql-codegen --config codegen.ts", + "test": "jest", + "test:end2end": "yarn test" + }, "dependencies": { - "graphql-yoga": "5.7.0", - "@graphql-yoga/plugin-persisted-operations": "3.7.0" + "@graphql-yoga/plugin-persisted-operations": "3.7.0", + "graphql-yoga": "5.7.0" }, "devDependencies": { - "@graphql-typed-document-node/core": "3.2.0", - "jest": "28.1.3", - "babel-jest": "29.7.0", - "@graphql-codegen/cli": "5.0.2", "@babel/core": "7.25.2", "@babel/preset-env": "7.25.3", - "@babel/preset-typescript": "7.24.7" - }, - "scripts": { - "test": "jest", - "codegen": "graphql-codegen --config codegen.ts", - "build": "tsc", - "test:end2end": "yarn test" + "@babel/preset-typescript": "7.24.7", + "@graphql-codegen/cli": "5.0.2", + "@graphql-typed-document-node/core": "3.2.0", + "babel-jest": "29.7.0", + "jest": "28.1.3" }, "bob": false } diff --git a/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts b/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts index dedac7e7f7e..1056e81bdf3 100644 --- a/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts +++ b/examples/persisted-documents-string-mode/src/gql/fragment-masking.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; +import { DocumentTypeDecoration, ResultOf } from '@graphql-typed-document-node/core'; import { Incremental, TypedDocumentString } from './graphql'; export type FragmentType> = @@ -14,42 +14,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -58,21 +58,21 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: TypedDocumentString, fragmentNode: TypedDocumentString, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { const deferredFields = queryNode.__meta__?.deferredFields as Record; const fragName = fragmentNode.__meta__?.fragmentName as string | undefined; diff --git a/examples/persisted-documents-string-mode/src/gql/gql.ts b/examples/persisted-documents-string-mode/src/gql/gql.ts index 8ac07c4313e..5f5de5047fd 100644 --- a/examples/persisted-documents-string-mode/src/gql/gql.ts +++ b/examples/persisted-documents-string-mode/src/gql/gql.ts @@ -20,7 +20,7 @@ const documents = { * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query HelloQuery {\n hello\n }\n' + source: '\n query HelloQuery {\n hello\n }\n', ): typeof import('./graphql').HelloQueryDocument; export function graphql(source: string) { diff --git a/examples/persisted-documents-string-mode/src/gql/graphql.ts b/examples/persisted-documents-string-mode/src/gql/graphql.ts index d1189107be8..ac3ccecebd2 100644 --- a/examples/persisted-documents-string-mode/src/gql/graphql.ts +++ b/examples/persisted-documents-string-mode/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -26,7 +31,10 @@ export class TypedDocumentString { __apiType?: DocumentTypeDecoration['__apiType']; - constructor(private value: string, public __meta__?: Record) { + constructor( + private value: string, + public __meta__?: Record, + ) { super(value); } @@ -41,5 +49,5 @@ export const HelloQueryDocument = new TypedDocumentString( hello } `, - { hash: '86f01e23de1c770cabbc35b2d87f2e5fd7557b6f' } + { hash: '86f01e23de1c770cabbc35b2d87f2e5fd7557b6f' }, ) as unknown as TypedDocumentString; diff --git a/examples/persisted-documents-string-mode/src/main.ts b/examples/persisted-documents-string-mode/src/main.ts index 3e0cd27da5f..0213db933f1 100644 --- a/examples/persisted-documents-string-mode/src/main.ts +++ b/examples/persisted-documents-string-mode/src/main.ts @@ -1,7 +1,6 @@ import { createServer } from 'http'; -import { makeYoga } from './yoga.js'; - import persistedDocumentsDictionary from './gql/persisted-documents.json'; +import { makeYoga } from './yoga.js'; const persistedDocuments = new Map(Object.entries(persistedDocumentsDictionary)); diff --git a/examples/persisted-documents-string-mode/src/yoga.spec.ts b/examples/persisted-documents-string-mode/src/yoga.spec.ts index 78b71fa7806..cb25ee01568 100644 --- a/examples/persisted-documents-string-mode/src/yoga.spec.ts +++ b/examples/persisted-documents-string-mode/src/yoga.spec.ts @@ -1,6 +1,6 @@ import { graphql } from './gql/index'; -import { makeYoga } from './yoga'; import persistedDocumentsDictionary from './gql/persisted-documents.json'; +import { makeYoga } from './yoga'; const persistedDocuments = new Map(Object.entries(persistedDocumentsDictionary)); diff --git a/examples/persisted-documents-string-mode/src/yoga.ts b/examples/persisted-documents-string-mode/src/yoga.ts index f0c1494be03..3d182a18a25 100644 --- a/examples/persisted-documents-string-mode/src/yoga.ts +++ b/examples/persisted-documents-string-mode/src/yoga.ts @@ -28,7 +28,7 @@ export function makeYoga(args: { persistedDocuments: null | Map plugins.push( usePersistedOperations({ getPersistedOperation: hash => persistedDocuments.get(hash), - }) + }), ); } return createYoga({ diff --git a/examples/persisted-documents/README.md b/examples/persisted-documents/README.md index a0aab1c6bdd..04b4d7d7eee 100644 --- a/examples/persisted-documents/README.md +++ b/examples/persisted-documents/README.md @@ -1,6 +1,7 @@ # Yoga Persisted Documents Example -Example for showing how to use GraphQL Code Generator for only allowing the execution of persisted operations. +Example for showing how to use GraphQL Code Generator for only allowing the execution of persisted +operations. [Learn more about Yoga Persisted Operations](https://the-guild.dev/graphql/yoga-server/docs/features/persisted-operations) diff --git a/examples/persisted-documents/package.json b/examples/persisted-documents/package.json index ed302a5be43..d04e2657f66 100644 --- a/examples/persisted-documents/package.json +++ b/examples/persisted-documents/package.json @@ -2,24 +2,24 @@ "name": "example-persisted-documents", "version": "0.0.0", "private": true, + "scripts": { + "build": "tsc", + "codegen": "graphql-codegen --config codegen.ts", + "test": "jest", + "test:end2end": "yarn test" + }, "dependencies": { - "graphql-yoga": "5.7.0", - "@graphql-yoga/plugin-persisted-operations": "3.7.0" + "@graphql-yoga/plugin-persisted-operations": "3.7.0", + "graphql-yoga": "5.7.0" }, "devDependencies": { - "@graphql-typed-document-node/core": "3.2.0", - "jest": "28.1.3", - "babel-jest": "29.7.0", - "@graphql-codegen/cli": "5.0.2", "@babel/core": "7.25.2", "@babel/preset-env": "7.25.3", - "@babel/preset-typescript": "7.24.7" - }, - "scripts": { - "test": "jest", - "codegen": "graphql-codegen --config codegen.ts", - "build": "tsc", - "test:end2end": "yarn test" + "@babel/preset-typescript": "7.24.7", + "@graphql-codegen/cli": "5.0.2", + "@graphql-typed-document-node/core": "3.2.0", + "babel-jest": "29.7.0", + "jest": "28.1.3" }, "bob": false } diff --git a/examples/persisted-documents/src/gql/fragment-masking.ts b/examples/persisted-documents/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/persisted-documents/src/gql/fragment-masking.ts +++ b/examples/persisted-documents/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/persisted-documents/src/gql/gql.ts b/examples/persisted-documents/src/gql/gql.ts index 8b95587e506..4fd0446c733 100644 --- a/examples/persisted-documents/src/gql/gql.ts +++ b/examples/persisted-documents/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -35,16 +35,12 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query HelloQuery {\n hello\n }\n' + source: '\n query HelloQuery {\n hello\n }\n', ): (typeof documents)['\n query HelloQuery {\n hello\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/persisted-documents/src/gql/graphql.ts b/examples/persisted-documents/src/gql/graphql.ts index 8c3a2fb892d..187df8fd6ea 100644 --- a/examples/persisted-documents/src/gql/graphql.ts +++ b/examples/persisted-documents/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -28,7 +33,10 @@ export const HelloQueryDocument = { kind: 'OperationDefinition', operation: 'query', name: { kind: 'Name', value: 'HelloQuery' }, - selectionSet: { kind: 'SelectionSet', selections: [{ kind: 'Field', name: { kind: 'Name', value: 'hello' } }] }, + selectionSet: { + kind: 'SelectionSet', + selections: [{ kind: 'Field', name: { kind: 'Name', value: 'hello' } }], + }, }, ], } as unknown as DocumentNode; diff --git a/examples/persisted-documents/src/main.ts b/examples/persisted-documents/src/main.ts index 3e0cd27da5f..0213db933f1 100644 --- a/examples/persisted-documents/src/main.ts +++ b/examples/persisted-documents/src/main.ts @@ -1,7 +1,6 @@ import { createServer } from 'http'; -import { makeYoga } from './yoga.js'; - import persistedDocumentsDictionary from './gql/persisted-documents.json'; +import { makeYoga } from './yoga.js'; const persistedDocuments = new Map(Object.entries(persistedDocumentsDictionary)); diff --git a/examples/persisted-documents/src/yoga.spec.ts b/examples/persisted-documents/src/yoga.spec.ts index 37eb89dc4b3..e1aa5d82e04 100644 --- a/examples/persisted-documents/src/yoga.spec.ts +++ b/examples/persisted-documents/src/yoga.spec.ts @@ -1,7 +1,7 @@ +import { print } from 'graphql'; import { graphql } from './gql/index'; -import { makeYoga } from './yoga'; import persistedDocumentsDictionary from './gql/persisted-documents.json'; -import { print } from 'graphql'; +import { makeYoga } from './yoga'; const persistedDocuments = new Map(Object.entries(persistedDocumentsDictionary)); diff --git a/examples/persisted-documents/src/yoga.ts b/examples/persisted-documents/src/yoga.ts index f0c1494be03..3d182a18a25 100644 --- a/examples/persisted-documents/src/yoga.ts +++ b/examples/persisted-documents/src/yoga.ts @@ -28,7 +28,7 @@ export function makeYoga(args: { persistedDocuments: null | Map plugins.push( usePersistedOperations({ getPersistedOperation: hash => persistedDocuments.get(hash), - }) + }), ); } return createYoga({ diff --git a/examples/programmatic-typescript/package.json b/examples/programmatic-typescript/package.json index 13888f1411a..a4d8685ecdd 100644 --- a/examples/programmatic-typescript/package.json +++ b/examples/programmatic-typescript/package.json @@ -3,10 +3,10 @@ "version": "0.0.1", "private": true, "scripts": { + "build": "yarn start:cjs && yarn start:mjs", + "codegen": "exit 0", "start:cjs": "tsup --onSuccess \"node dist/index.js\"", "start:mjs": "tsup --onSuccess \"node dist/index.mjs\"", - "codegen": "exit 0", - "build": "yarn start:cjs && yarn start:mjs", "test:end2end": "exit 0" }, "dependencies": { diff --git a/examples/programmatic-typescript/src/gql.generated.ts b/examples/programmatic-typescript/src/gql.generated.ts index d9bcbb38a64..412fcb7de0a 100644 --- a/examples/programmatic-typescript/src/gql.generated.ts +++ b/examples/programmatic-typescript/src/gql.generated.ts @@ -1,12 +1,17 @@ import type { GraphQLResolveInfo } from 'graphql'; import type { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -34,24 +39,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -65,20 +76,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -88,7 +105,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -107,7 +124,7 @@ export type ResolversParentTypes = { export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { hello?: Resolver; }; @@ -127,7 +144,10 @@ export const HelloDocument = { kind: 'OperationDefinition', operation: 'query', name: { kind: 'Name', value: 'hello' }, - selectionSet: { kind: 'SelectionSet', selections: [{ kind: 'Field', name: { kind: 'Name', value: 'hello' } }] }, + selectionSet: { + kind: 'SelectionSet', + selections: [{ kind: 'Field', name: { kind: 'Name', value: 'hello' } }], + }, }, ], } as unknown as DocumentNode; diff --git a/examples/programmatic-typescript/src/index.ts b/examples/programmatic-typescript/src/index.ts index b9ffcdf97dc..4fdc060477d 100644 --- a/examples/programmatic-typescript/src/index.ts +++ b/examples/programmatic-typescript/src/index.ts @@ -1,5 +1,7 @@ /* eslint-disable no-console */ import { promises } from 'node:fs'; +import gql from 'graphql-tag'; +import prettier from 'prettier'; import { codegen } from '@graphql-codegen/core'; import { getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers'; import * as typedDocumentNode from '@graphql-codegen/typed-document-node'; @@ -9,8 +11,6 @@ import * as typescriptResolvers from '@graphql-codegen/typescript-resolvers'; import { GraphQLFileLoader } from '@graphql-tools/graphql-file-loader'; import { loadDocuments } from '@graphql-tools/load'; import { makeExecutableSchema } from '@graphql-tools/schema'; -import gql from 'graphql-tag'; -import prettier from 'prettier'; import type { Resolvers } from './gql.generated.js'; const schema = makeExecutableSchema({ @@ -76,7 +76,7 @@ const schema = makeExecutableSchema({ ...(await prettier.resolveConfig(process.cwd())), parser: 'typescript', }), - 'utf8' + 'utf8', ); console.log('done generating.'); })().catch(err => { diff --git a/examples/react/apollo-client-defer/README.md b/examples/react/apollo-client-defer/README.md index e808d30aa8a..55618005b13 100644 --- a/examples/react/apollo-client-defer/README.md +++ b/examples/react/apollo-client-defer/README.md @@ -1,10 +1,12 @@ # Using GraphQL Code Generator with Apollo Client and React -This example illustrates how to use GraphQL Code Generator in a React application using the Apollo React GraphQL Client. +This example illustrates how to use GraphQL Code Generator in a React application using the Apollo +React GraphQL Client. You will find the TypeScript-based codegen configuration in [`codegen.ts`](./codegen.ts). -This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️ +This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder +that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️
@@ -14,4 +16,5 @@ https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular -- -Please note that the `client` preset used in this example is compatible with `@apollo/client` (since `3.2.0`, not when using React Components (``)). +Please note that the `client` preset used in this example is compatible with `@apollo/client` (since +`3.2.0`, not when using React Components (``)). diff --git a/examples/react/apollo-client-defer/index.html b/examples/react/apollo-client-defer/index.html index ab66da90506..edb6fd979e3 100644 --- a/examples/react/apollo-client-defer/index.html +++ b/examples/react/apollo-client-defer/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/apollo-client-defer/package.json b/examples/react/apollo-client-defer/package.json index 6bdff976e1f..7f26d36d699 100644 --- a/examples/react/apollo-client-defer/package.json +++ b/examples/react/apollo-client-defer/package.json @@ -2,13 +2,22 @@ "name": "example-react-apollo-client-defer", "version": "0.1.0", "private": true, + "scripts": { + "build": "vite build", + "codegen": "graphql-codegen --config codegen.ts", + "dev": "vite", + "start": "yarn start:yoga & serve -s dist", + "start:yoga": "node src/yoga.mjs", + "test": "cypress run", + "test:end2end": "start-server-and-test start http://localhost:3000 test" + }, "dependencies": { "@apollo/client": "^3.7.10", "@graphql-yoga/plugin-defer-stream": "^3.0.0", "graphql": "^16.6.0", + "graphql-yoga": "5.7.0", "react": "^18.2.0", - "react-dom": "^18.2.0", - "graphql-yoga": "5.7.0" + "react-dom": "^18.2.0" }, "devDependencies": { "@graphql-codegen/cli": "^5.0.2", @@ -22,14 +31,5 @@ "start-server-and-test": "2.0.5", "typescript": "5.5.4", "vite": "^5.0.0" - }, - "scripts": { - "dev": "vite", - "build": "vite build", - "start:yoga": "node src/yoga.mjs", - "start": "yarn start:yoga & serve -s dist", - "test": "cypress run", - "test:end2end": "start-server-and-test start http://localhost:3000 test", - "codegen": "graphql-codegen --config codegen.ts" } } diff --git a/examples/react/apollo-client-defer/src/App.tsx b/examples/react/apollo-client-defer/src/App.tsx index e836b55fa9a..3084386bb4e 100644 --- a/examples/react/apollo-client-defer/src/App.tsx +++ b/examples/react/apollo-client-defer/src/App.tsx @@ -1,6 +1,5 @@ import { useQuery } from '@apollo/client'; - -import { useFragment, graphql, FragmentType, isFragmentReady, DocumentType } from './gql'; +import { DocumentType, FragmentType, graphql, isFragmentReady, useFragment } from './gql'; export const slowFieldFragment = graphql(/* GraphQL */ ` fragment SlowFieldFragment on Query { diff --git a/examples/react/apollo-client-defer/src/gql/fragment-masking.ts b/examples/react/apollo-client-defer/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/react/apollo-client-defer/src/gql/fragment-masking.ts +++ b/examples/react/apollo-client-defer/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/react/apollo-client-defer/src/gql/gql.ts b/examples/react/apollo-client-defer/src/gql/gql.ts index 6618d429c55..46e68d38971 100644 --- a/examples/react/apollo-client-defer/src/gql/gql.ts +++ b/examples/react/apollo-client-defer/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -14,7 +14,8 @@ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/ * Learn more about it here: https://the-guild.dev/graphql/codegen/plugins/presets/preset-client#reducing-bundle-size */ const documents = { - '\n fragment SlowFieldFragment on Query {\n slowField(waitFor: 5000)\n }\n': types.SlowFieldFragmentFragmentDoc, + '\n fragment SlowFieldFragment on Query {\n slowField(waitFor: 5000)\n }\n': + types.SlowFieldFragmentFragmentDoc, '\n query SlowAndFastFieldWithDefer {\n fastField\n ...SlowFieldFragment @defer\n\n ... @defer {\n inlinedSlowField: slowField(waitFor: 5000)\n }\n }\n': types.SlowAndFastFieldWithDeferDocument, }; @@ -37,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment SlowFieldFragment on Query {\n slowField(waitFor: 5000)\n }\n' + source: '\n fragment SlowFieldFragment on Query {\n slowField(waitFor: 5000)\n }\n', ): (typeof documents)['\n fragment SlowFieldFragment on Query {\n slowField(waitFor: 5000)\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query SlowAndFastFieldWithDefer {\n fastField\n ...SlowFieldFragment @defer\n\n ... @defer {\n inlinedSlowField: slowField(waitFor: 5000)\n }\n }\n' + source: '\n query SlowAndFastFieldWithDefer {\n fastField\n ...SlowFieldFragment @defer\n\n ... @defer {\n inlinedSlowField: slowField(waitFor: 5000)\n }\n }\n', ): (typeof documents)['\n query SlowAndFastFieldWithDefer {\n fastField\n ...SlowFieldFragment @defer\n\n ... @defer {\n inlinedSlowField: slowField(waitFor: 5000)\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/react/apollo-client-defer/src/gql/graphql.ts b/examples/react/apollo-client-defer/src/gql/graphql.ts index d37b8ab60be..3a116d5215e 100644 --- a/examples/react/apollo-client-defer/src/gql/graphql.ts +++ b/examples/react/apollo-client-defer/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -119,4 +124,7 @@ export const SlowAndFastFieldWithDeferDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + SlowAndFastFieldWithDeferQuery, + SlowAndFastFieldWithDeferQueryVariables +>; diff --git a/examples/react/apollo-client-defer/src/main.tsx b/examples/react/apollo-client-defer/src/main.tsx index 21031c42f1c..470ef7b8464 100644 --- a/examples/react/apollo-client-defer/src/main.tsx +++ b/examples/react/apollo-client-defer/src/main.tsx @@ -1,7 +1,7 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; +import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client'; import App from './App'; -import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client'; const client = new ApolloClient({ uri: 'http://localhost:4000/graphql', @@ -14,5 +14,5 @@ root.render( - + , ); diff --git a/examples/react/apollo-client-defer/src/yoga.mjs b/examples/react/apollo-client-defer/src/yoga.mjs index ce0a710ca02..0b87f2aac15 100644 --- a/examples/react/apollo-client-defer/src/yoga.mjs +++ b/examples/react/apollo-client-defer/src/yoga.mjs @@ -1,6 +1,6 @@ +import { createServer } from 'node:http'; import { createSchema, createYoga } from 'graphql-yoga'; import { useDeferStream } from '@graphql-yoga/plugin-defer-stream'; -import { createServer } from 'node:http'; const typeDefs = /* GraphQL */ ` type Query { diff --git a/examples/react/apollo-client-swc-plugin/index.html b/examples/react/apollo-client-swc-plugin/index.html index ab66da90506..edb6fd979e3 100644 --- a/examples/react/apollo-client-swc-plugin/index.html +++ b/examples/react/apollo-client-swc-plugin/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/apollo-client-swc-plugin/package.json b/examples/react/apollo-client-swc-plugin/package.json index 791322cf974..b715967e54e 100644 --- a/examples/react/apollo-client-swc-plugin/package.json +++ b/examples/react/apollo-client-swc-plugin/package.json @@ -2,25 +2,25 @@ "name": "example-apollo-client-swc-plugin", "version": "0.1.0", "private": true, + "scripts": { + "build": "vite build", + "codegen": "graphql-codegen --config codegen.ts", + "dev": "vite", + "test": "node scripts/test.js", + "test:end2end": "exit 0" + }, "dependencies": { "@apollo/client": "^3.7.10", "react": "18.3.1", "react-dom": "18.3.1" }, "devDependencies": { - "@graphql-codegen/client-preset-swc-plugin": "0.2.0", "@graphql-codegen/cli": "^5.0.2", - "@vitejs/plugin-react-swc": "^3.3.0", + "@graphql-codegen/client-preset-swc-plugin": "0.2.0", "@types/react": "18.3.3", "@types/react-dom": "18.3.0", + "@vitejs/plugin-react-swc": "^3.3.0", "typescript": "5.5.4", "vite": "^5.0.0" - }, - "scripts": { - "dev": "vite", - "build": "vite build", - "test": "node scripts/test.js", - "test:end2end": "exit 0", - "codegen": "graphql-codegen --config codegen.ts" } } diff --git a/examples/react/apollo-client-swc-plugin/public/vite.svg b/examples/react/apollo-client-swc-plugin/public/vite.svg index e7b8dfb1b2a..c42ec851f89 100644 --- a/examples/react/apollo-client-swc-plugin/public/vite.svg +++ b/examples/react/apollo-client-swc-plugin/public/vite.svg @@ -1 +1,43 @@ - \ No newline at end of file + diff --git a/examples/react/apollo-client-swc-plugin/src/App.tsx b/examples/react/apollo-client-swc-plugin/src/App.tsx index 718dec43656..cff76dc33a8 100644 --- a/examples/react/apollo-client-swc-plugin/src/App.tsx +++ b/examples/react/apollo-client-swc-plugin/src/App.tsx @@ -1,5 +1,4 @@ import { useQuery } from '@apollo/client'; - import './App.css'; import Film from './Film'; import { graphql } from './gql'; @@ -20,7 +19,13 @@ function App() { const { data } = useQuery(allFilmsWithVariablesQueryDocument, { variables: { first: 10 } }); return (
- {data &&
    {data.allFilms?.edges?.map((e, i) => e?.node && )}
} + {data && ( +
    + {data.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
+ )}
); } diff --git a/examples/react/apollo-client-swc-plugin/src/Film.tsx b/examples/react/apollo-client-swc-plugin/src/Film.tsx index a2290bfdca1..494afdd3ac9 100644 --- a/examples/react/apollo-client-swc-plugin/src/Film.tsx +++ b/examples/react/apollo-client-swc-plugin/src/Film.tsx @@ -1,5 +1,5 @@ -import { FragmentType, useFragment } from './gql/fragment-masking'; import { graphql } from './gql'; +import { FragmentType, useFragment } from './gql/fragment-masking'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/react/apollo-client-swc-plugin/src/gql/fragment-masking.ts b/examples/react/apollo-client-swc-plugin/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/react/apollo-client-swc-plugin/src/gql/fragment-masking.ts +++ b/examples/react/apollo-client-swc-plugin/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/react/apollo-client-swc-plugin/src/gql/gql.ts b/examples/react/apollo-client-swc-plugin/src/gql/gql.ts index 5816ba72a45..df8678d8785 100644 --- a/examples/react/apollo-client-swc-plugin/src/gql/gql.ts +++ b/examples/react/apollo-client-swc-plugin/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): (typeof documents)['\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): (typeof documents)['\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/react/apollo-client-swc-plugin/src/gql/graphql.ts b/examples/react/apollo-client-swc-plugin/src/gql/graphql.ts index e1ec3945bdd..4b60e4d8661 100644 --- a/examples/react/apollo-client-swc-plugin/src/gql/graphql.ts +++ b/examples/react/apollo-client-swc-plugin/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -26,7 +31,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -69,7 +76,10 @@ export const AllFilmsWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -99,7 +109,9 @@ export const AllFilmsWithVariablesQueryDocument = { name: { kind: 'Name', value: 'node' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }, + ], }, }, ], @@ -126,4 +138,7 @@ export const AllFilmsWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/react/apollo-client-swc-plugin/src/logo.svg b/examples/react/apollo-client-swc-plugin/src/logo.svg index 9dfc1c058ce..02c651a6f61 100644 --- a/examples/react/apollo-client-swc-plugin/src/logo.svg +++ b/examples/react/apollo-client-swc-plugin/src/logo.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + + + diff --git a/examples/react/apollo-client-swc-plugin/src/main.css b/examples/react/apollo-client-swc-plugin/src/main.css index 7323ae85c54..89e57c7ccfe 100644 --- a/examples/react/apollo-client-swc-plugin/src/main.css +++ b/examples/react/apollo-client-swc-plugin/src/main.css @@ -1,7 +1,7 @@ body { margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', - 'Droid Sans', 'Helvetica Neue', sans-serif; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', + 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } diff --git a/examples/react/apollo-client-swc-plugin/src/main.tsx b/examples/react/apollo-client-swc-plugin/src/main.tsx index 38a4b988a06..1ef77a02b31 100644 --- a/examples/react/apollo-client-swc-plugin/src/main.tsx +++ b/examples/react/apollo-client-swc-plugin/src/main.tsx @@ -1,8 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import './main.css'; +import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client'; import App from './App'; -import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client'; const client = new ApolloClient({ uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index', @@ -15,5 +15,5 @@ root.render( - + , ); diff --git a/examples/react/apollo-client-swc-plugin/vite.config.ts b/examples/react/apollo-client-swc-plugin/vite.config.ts index 1297583ee87..e589ac3aa80 100644 --- a/examples/react/apollo-client-swc-plugin/vite.config.ts +++ b/examples/react/apollo-client-swc-plugin/vite.config.ts @@ -7,7 +7,10 @@ export default defineConfig({ plugins: [ react({ plugins: [ - ['@graphql-codegen/client-preset-swc-plugin', { artifactDirectory: './src/gql', gqlTagName: 'graphql' }], + [ + '@graphql-codegen/client-preset-swc-plugin', + { artifactDirectory: './src/gql', gqlTagName: 'graphql' }, + ], ], }), ], diff --git a/examples/react/apollo-client/README.md b/examples/react/apollo-client/README.md index e808d30aa8a..55618005b13 100644 --- a/examples/react/apollo-client/README.md +++ b/examples/react/apollo-client/README.md @@ -1,10 +1,12 @@ # Using GraphQL Code Generator with Apollo Client and React -This example illustrates how to use GraphQL Code Generator in a React application using the Apollo React GraphQL Client. +This example illustrates how to use GraphQL Code Generator in a React application using the Apollo +React GraphQL Client. You will find the TypeScript-based codegen configuration in [`codegen.ts`](./codegen.ts). -This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️ +This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder +that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️
@@ -14,4 +16,5 @@ https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular -- -Please note that the `client` preset used in this example is compatible with `@apollo/client` (since `3.2.0`, not when using React Components (``)). +Please note that the `client` preset used in this example is compatible with `@apollo/client` (since +`3.2.0`, not when using React Components (``)). diff --git a/examples/react/apollo-client/index.html b/examples/react/apollo-client/index.html index ab66da90506..edb6fd979e3 100644 --- a/examples/react/apollo-client/index.html +++ b/examples/react/apollo-client/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/apollo-client/package.json b/examples/react/apollo-client/package.json index 52f1f95d2ec..a1f4f981f34 100644 --- a/examples/react/apollo-client/package.json +++ b/examples/react/apollo-client/package.json @@ -2,6 +2,14 @@ "name": "example-react-apollo-client", "version": "0.1.0", "private": true, + "scripts": { + "build": "vite build", + "codegen": "graphql-codegen --config codegen.ts", + "dev": "vite", + "start": "serve -s dist", + "test": "cypress run", + "test:end2end": "start-server-and-test start http://localhost:3000 test" + }, "dependencies": { "@apollo/client": "^3.7.10", "graphql": "^16.6.0", @@ -10,23 +18,15 @@ }, "devDependencies": { "@graphql-codegen/cli": "^5.0.2", - "@vitejs/plugin-react": "^4.0.0", "@types/jest": "^27.5.2", "@types/node": "^20.0.0", "@types/react": "^18.0.15", "@types/react-dom": "^18.0.10", - "typescript": "5.5.4", - "serve": "14.2.3", + "@vitejs/plugin-react": "^4.0.0", "cypress": "13.13.3", + "serve": "14.2.3", "start-server-and-test": "2.0.5", + "typescript": "5.5.4", "vite": "^5.0.0" - }, - "scripts": { - "dev": "vite", - "build": "vite build", - "start": "serve -s dist", - "test": "cypress run", - "test:end2end": "start-server-and-test start http://localhost:3000 test", - "codegen": "graphql-codegen --config codegen.ts" } } diff --git a/examples/react/apollo-client/public/vite.svg b/examples/react/apollo-client/public/vite.svg index e7b8dfb1b2a..c42ec851f89 100644 --- a/examples/react/apollo-client/public/vite.svg +++ b/examples/react/apollo-client/public/vite.svg @@ -1 +1,43 @@ - \ No newline at end of file + diff --git a/examples/react/apollo-client/src/App.tsx b/examples/react/apollo-client/src/App.tsx index 42276d6f671..1c318fa8f7b 100644 --- a/examples/react/apollo-client/src/App.tsx +++ b/examples/react/apollo-client/src/App.tsx @@ -1,6 +1,5 @@ import React from 'react'; import { useQuery } from '@apollo/client'; - import './App.css'; import Film from './Film'; import { graphql } from './gql/gql'; @@ -21,7 +20,13 @@ function App() { const { data } = useQuery(allFilmsWithVariablesQueryDocument, { variables: { first: 10 } }); return (
- {data &&
    {data.allFilms?.edges?.map((e, i) => e?.node && )}
} + {data && ( +
    + {data.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
+ )}
); } diff --git a/examples/react/apollo-client/src/Film.tsx b/examples/react/apollo-client/src/Film.tsx index f7fe1f4d6ec..c95c3f19b2c 100644 --- a/examples/react/apollo-client/src/Film.tsx +++ b/examples/react/apollo-client/src/Film.tsx @@ -1,4 +1,4 @@ -import { graphql, FragmentType, useFragment } from './gql'; +import { FragmentType, graphql, useFragment } from './gql'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/react/apollo-client/src/gql/fragment-masking.ts b/examples/react/apollo-client/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/react/apollo-client/src/gql/fragment-masking.ts +++ b/examples/react/apollo-client/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/react/apollo-client/src/gql/gql.ts b/examples/react/apollo-client/src/gql/gql.ts index 5816ba72a45..df8678d8785 100644 --- a/examples/react/apollo-client/src/gql/gql.ts +++ b/examples/react/apollo-client/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): (typeof documents)['\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): (typeof documents)['\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/react/apollo-client/src/gql/graphql.ts b/examples/react/apollo-client/src/gql/graphql.ts index e1ec3945bdd..4b60e4d8661 100644 --- a/examples/react/apollo-client/src/gql/graphql.ts +++ b/examples/react/apollo-client/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -26,7 +31,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -69,7 +76,10 @@ export const AllFilmsWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -99,7 +109,9 @@ export const AllFilmsWithVariablesQueryDocument = { name: { kind: 'Name', value: 'node' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }, + ], }, }, ], @@ -126,4 +138,7 @@ export const AllFilmsWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/react/apollo-client/src/main.css b/examples/react/apollo-client/src/main.css index 7323ae85c54..89e57c7ccfe 100644 --- a/examples/react/apollo-client/src/main.css +++ b/examples/react/apollo-client/src/main.css @@ -1,7 +1,7 @@ body { margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', - 'Droid Sans', 'Helvetica Neue', sans-serif; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', + 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } diff --git a/examples/react/apollo-client/src/main.tsx b/examples/react/apollo-client/src/main.tsx index 38a4b988a06..1ef77a02b31 100644 --- a/examples/react/apollo-client/src/main.tsx +++ b/examples/react/apollo-client/src/main.tsx @@ -1,8 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import './main.css'; +import { ApolloClient, ApolloProvider, InMemoryCache } from '@apollo/client'; import App from './App'; -import { ApolloClient, InMemoryCache, ApolloProvider } from '@apollo/client'; const client = new ApolloClient({ uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index', @@ -15,5 +15,5 @@ root.render( - + , ); diff --git a/examples/react/http-executor/README.md b/examples/react/http-executor/README.md index d4902498871..c6311c26103 100644 --- a/examples/react/http-executor/README.md +++ b/examples/react/http-executor/README.md @@ -1,10 +1,12 @@ # Using GraphQL Code Generator with `graphql-request` and React -This example illustrates how to use GraphQL Code Generator in a React application using the `graphql-request` GraphQL Client. +This example illustrates how to use GraphQL Code Generator in a React application using the +`graphql-request` GraphQL Client. You will find the TypeScript-based codegen configuration in [`codegen.ts`](./codegen.ts). -This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️ +This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder +that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️
@@ -14,4 +16,5 @@ https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular -- -Please note that the `client` preset used in this example is compatible with `graphql-request` from `5.0`. +Please note that the `client` preset used in this example is compatible with `graphql-request` from +`5.0`. diff --git a/examples/react/http-executor/index.html b/examples/react/http-executor/index.html index ab66da90506..edb6fd979e3 100644 --- a/examples/react/http-executor/index.html +++ b/examples/react/http-executor/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/http-executor/package.json b/examples/react/http-executor/package.json index 2589e96a715..fcb227bc3fd 100644 --- a/examples/react/http-executor/package.json +++ b/examples/react/http-executor/package.json @@ -2,6 +2,14 @@ "name": "example-react-graphql-request", "version": "0.1.0", "private": true, + "scripts": { + "build": "vite build", + "codegen": "graphql-codegen --config codegen.ts", + "dev": "vite", + "start": "serve -s dist", + "test": "cypress run", + "test:end2end": "start-server-and-test start http://localhost:3000 test" + }, "dependencies": { "@graphql-tools/executor-http": "^1.0.0", "react": "^18.2.0", @@ -9,23 +17,15 @@ }, "devDependencies": { "@graphql-codegen/cli": "^5.0.2", - "@vitejs/plugin-react": "^4.0.0", "@types/jest": "^27.5.2", "@types/node": "^20.0.0", "@types/react": "^18.0.17", "@types/react-dom": "^18.0.10", - "typescript": "5.5.4", - "serve": "14.2.3", + "@vitejs/plugin-react": "^4.0.0", "cypress": "13.13.3", + "serve": "14.2.3", "start-server-and-test": "2.0.5", + "typescript": "5.5.4", "vite": "^5.0.0" - }, - "scripts": { - "dev": "vite", - "build": "vite build", - "start": "serve -s dist", - "test": "cypress run", - "test:end2end": "start-server-and-test start http://localhost:3000 test", - "codegen": "graphql-codegen --config codegen.ts" } } diff --git a/examples/react/http-executor/public/vite.svg b/examples/react/http-executor/public/vite.svg index e7b8dfb1b2a..c42ec851f89 100644 --- a/examples/react/http-executor/public/vite.svg +++ b/examples/react/http-executor/public/vite.svg @@ -1 +1,43 @@ - \ No newline at end of file + diff --git a/examples/react/http-executor/src/App.tsx b/examples/react/http-executor/src/App.tsx index 4c4e4050432..9fa9b82a91a 100644 --- a/examples/react/http-executor/src/App.tsx +++ b/examples/react/http-executor/src/App.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'; import { buildHTTPExecutor } from '@graphql-tools/executor-http'; import './App.css'; import Film from './Film'; -import { graphql, DocumentType } from './gql'; +import { DocumentType, graphql } from './gql'; const executor = buildHTTPExecutor({ endpoint: 'https://swapi-graphql.netlify.app/.netlify/functions/index', @@ -43,7 +43,13 @@ function App() { return (
- {data &&
    {data.allFilms?.edges?.map((e, i) => e?.node && )}
} + {data && ( +
    + {data.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
+ )}
); } diff --git a/examples/react/http-executor/src/Film.tsx b/examples/react/http-executor/src/Film.tsx index a4ca29554fd..4c19efafd44 100644 --- a/examples/react/http-executor/src/Film.tsx +++ b/examples/react/http-executor/src/Film.tsx @@ -1,4 +1,4 @@ -import { FragmentType, useFragment, graphql } from './gql'; +import { FragmentType, graphql, useFragment } from './gql'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/react/http-executor/src/gql/fragment-masking.ts b/examples/react/http-executor/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/react/http-executor/src/gql/fragment-masking.ts +++ b/examples/react/http-executor/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/react/http-executor/src/gql/gql.ts b/examples/react/http-executor/src/gql/gql.ts index 5816ba72a45..df8678d8785 100644 --- a/examples/react/http-executor/src/gql/gql.ts +++ b/examples/react/http-executor/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): (typeof documents)['\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): (typeof documents)['\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/react/http-executor/src/gql/graphql.ts b/examples/react/http-executor/src/gql/graphql.ts index e1ec3945bdd..4b60e4d8661 100644 --- a/examples/react/http-executor/src/gql/graphql.ts +++ b/examples/react/http-executor/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -26,7 +31,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -69,7 +76,10 @@ export const AllFilmsWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -99,7 +109,9 @@ export const AllFilmsWithVariablesQueryDocument = { name: { kind: 'Name', value: 'node' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }, + ], }, }, ], @@ -126,4 +138,7 @@ export const AllFilmsWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/react/http-executor/src/logo.svg b/examples/react/http-executor/src/logo.svg index 9dfc1c058ce..02c651a6f61 100644 --- a/examples/react/http-executor/src/logo.svg +++ b/examples/react/http-executor/src/logo.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + + + diff --git a/examples/react/http-executor/src/main.css b/examples/react/http-executor/src/main.css index 7323ae85c54..89e57c7ccfe 100644 --- a/examples/react/http-executor/src/main.css +++ b/examples/react/http-executor/src/main.css @@ -1,7 +1,7 @@ body { margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', - 'Droid Sans', 'Helvetica Neue', sans-serif; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', + 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } diff --git a/examples/react/http-executor/src/main.tsx b/examples/react/http-executor/src/main.tsx index ac53dd10760..31b727eb523 100644 --- a/examples/react/http-executor/src/main.tsx +++ b/examples/react/http-executor/src/main.tsx @@ -7,5 +7,5 @@ const root = ReactDOM.createRoot(document.getElementById('app') as HTMLElement); root.render( - + , ); diff --git a/examples/react/nextjs-swr/README.md b/examples/react/nextjs-swr/README.md index d3805086974..3cc5a168ede 100644 --- a/examples/react/nextjs-swr/README.md +++ b/examples/react/nextjs-swr/README.md @@ -1,10 +1,12 @@ # Using GraphQL Code Generator with SWR and React -This example illustrates using GraphQL Code Generator in a React application using SWR with `graphql-request` as a GraphQL Client. +This example illustrates using GraphQL Code Generator in a React application using SWR with +`graphql-request` as a GraphQL Client. You will find the TypeScript-based codegen configuration in [`codegen.ts`](./codegen.ts). -This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️ +This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder +that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️
@@ -14,6 +16,8 @@ https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular -- -Please note that the `client` preset used in this example is compatible with `graphql-request` from `5.0` as SWR fetcher. +Please note that the `client` preset used in this example is compatible with `graphql-request` from +`5.0` as SWR fetcher. -For indications in writing your fetcher, [please refer to our documentation](https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular#appendix-i-react-query-with-a-custom-fetcher-setup). +For indications in writing your fetcher, +[please refer to our documentation](https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular#appendix-i-react-query-with-a-custom-fetcher-setup). diff --git a/examples/react/nextjs-swr/gql/fragment-masking.ts b/examples/react/nextjs-swr/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/react/nextjs-swr/gql/fragment-masking.ts +++ b/examples/react/nextjs-swr/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/react/nextjs-swr/gql/gql.ts b/examples/react/nextjs-swr/gql/gql.ts index d1ba5f9aba1..99310a9d1b0 100644 --- a/examples/react/nextjs-swr/gql/gql.ts +++ b/examples/react/nextjs-swr/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): (typeof documents)['\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): (typeof documents)['\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/react/nextjs-swr/gql/graphql.ts b/examples/react/nextjs-swr/gql/graphql.ts index 79331d3022d..3afa88fcc45 100644 --- a/examples/react/nextjs-swr/gql/graphql.ts +++ b/examples/react/nextjs-swr/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -34,7 +39,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -69,7 +76,10 @@ export const AllFilmsWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -99,7 +109,9 @@ export const AllFilmsWithVariablesQueryDocument = { name: { kind: 'Name', value: 'node' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }, + ], }, }, ], @@ -126,4 +138,7 @@ export const AllFilmsWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/react/nextjs-swr/hooks/use-query.ts b/examples/react/nextjs-swr/hooks/use-query.ts index 4098644c9d9..3c147228f90 100644 --- a/examples/react/nextjs-swr/hooks/use-query.ts +++ b/examples/react/nextjs-swr/hooks/use-query.ts @@ -1,14 +1,15 @@ /* eslint-disable import/no-extraneous-dependencies */ -import { buildHTTPExecutor } from '@graphql-tools/executor-http'; -import { TypedDocumentNode } from '@graphql-typed-document-node/core'; import { ASTNode, ExecutionResult, Kind, OperationDefinitionNode } from 'graphql'; import useSWR from 'swr'; +import { buildHTTPExecutor } from '@graphql-tools/executor-http'; +import { TypedDocumentNode } from '@graphql-typed-document-node/core'; const executor = buildHTTPExecutor({ endpoint: 'https://swapi-graphql.netlify.app/.netlify/functions/index', }); -const isOperationDefinition = (def: ASTNode): def is OperationDefinitionNode => def.kind === Kind.OPERATION_DEFINITION; +const isOperationDefinition = (def: ASTNode): def is OperationDefinitionNode => + def.kind === Kind.OPERATION_DEFINITION; export function useGraphQL( document: TypedDocumentNode, @@ -24,6 +25,6 @@ export function useGraphQL( executor({ document, variables, - }) as Promise> + }) as Promise>, ); } diff --git a/examples/react/nextjs-swr/next.config.js b/examples/react/nextjs-swr/next.config.js index 9b99dda0b05..cb0e7b73991 100644 --- a/examples/react/nextjs-swr/next.config.js +++ b/examples/react/nextjs-swr/next.config.js @@ -3,7 +3,12 @@ const nextConfig = { reactStrictMode: true, swcMinify: true, experimental: { - swcPlugins: [['@graphql-codegen/client-preset-swc-plugin', { artifactDirectory: './gql', gqlTagName: 'graphql' }]], + swcPlugins: [ + [ + '@graphql-codegen/client-preset-swc-plugin', + { artifactDirectory: './gql', gqlTagName: 'graphql' }, + ], + ], }, }; diff --git a/examples/react/nextjs-swr/package.json b/examples/react/nextjs-swr/package.json index 80073a33ed4..86c9b24af41 100644 --- a/examples/react/nextjs-swr/package.json +++ b/examples/react/nextjs-swr/package.json @@ -3,11 +3,11 @@ "version": "0.1.0", "private": true, "scripts": { - "dev": "next dev", "build": "next build", - "start": "next start", - "lint": "next lint", "codegen": "graphql-codegen --config codegen.ts", + "dev": "next dev", + "lint": "next lint", + "start": "next start", "test": "cypress run", "test:end2end": "start-server-and-test start http://127.0.0.1:3000 test" }, @@ -20,8 +20,8 @@ }, "devDependencies": { "@graphql-codegen/cli": "^5.0.2", - "@graphql-codegen/schema-ast": "4.1.0", "@graphql-codegen/client-preset-swc-plugin": "0.2.0", + "@graphql-codegen/schema-ast": "4.1.0", "@types/node": "^20.0.0", "@types/react": "^18.0.17", "@types/react-dom": "^18.0.10", diff --git a/examples/react/nextjs-swr/pages/index.tsx b/examples/react/nextjs-swr/pages/index.tsx index 7392babe850..8b44292b733 100644 --- a/examples/react/nextjs-swr/pages/index.tsx +++ b/examples/react/nextjs-swr/pages/index.tsx @@ -1,10 +1,8 @@ import type { NextPage } from 'next'; - -import { graphql } from '../gql'; - -import styles from '../styles/Home.module.css'; import Film from '../components/Film'; +import { graphql } from '../gql'; import { useGraphQL } from '../hooks/use-query'; +import styles from '../styles/Home.module.css'; const AllFilmsWithVariablesQuery = graphql(/* GraphQL */ ` query allFilmsWithVariablesQuery($first: Int!) { @@ -24,7 +22,11 @@ const Home: NextPage = () => {
{data && ( -
    {data.data?.allFilms?.edges?.map((e, i) => e?.node && )}
+
    + {data.data?.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
)}
diff --git a/examples/react/nextjs-swr/public/vercel.svg b/examples/react/nextjs-swr/public/vercel.svg index fbf0e25a651..cfdff9806fb 100644 --- a/examples/react/nextjs-swr/public/vercel.svg +++ b/examples/react/nextjs-swr/public/vercel.svg @@ -1,4 +1,6 @@ - - - \ No newline at end of file + + + diff --git a/examples/react/nextjs-swr/styles/Home.module.css b/examples/react/nextjs-swr/styles/Home.module.css index 83c0edbe20b..90817bd3910 100644 --- a/examples/react/nextjs-swr/styles/Home.module.css +++ b/examples/react/nextjs-swr/styles/Home.module.css @@ -61,7 +61,14 @@ border-radius: 5px; padding: 0.75rem; font-size: 1.1rem; - font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, Bitstream Vera Sans Mono, Courier New, + font-family: + Menlo, + Monaco, + Lucida Console, + Liberation Mono, + DejaVu Sans Mono, + Bitstream Vera Sans Mono, + Courier New, monospace; } @@ -81,7 +88,9 @@ text-decoration: none; border: 1px solid #eaeaea; border-radius: 10px; - transition: color 0.15s ease, border-color 0.15s ease; + transition: + color 0.15s ease, + border-color 0.15s ease; max-width: 300px; } diff --git a/examples/react/nextjs-swr/styles/globals.css b/examples/react/nextjs-swr/styles/globals.css index aa3b7f2a5b3..f7efe20c367 100644 --- a/examples/react/nextjs-swr/styles/globals.css +++ b/examples/react/nextjs-swr/styles/globals.css @@ -2,8 +2,18 @@ html, body { padding: 0; margin: 0; - font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, - Helvetica Neue, sans-serif; + font-family: + -apple-system, + BlinkMacSystemFont, + Segoe UI, + Roboto, + Oxygen, + Ubuntu, + Cantarell, + Fira Sans, + Droid Sans, + Helvetica Neue, + sans-serif; } a { diff --git a/examples/react/tanstack-react-query/README.md b/examples/react/tanstack-react-query/README.md index 649a99be02e..7b23b41931c 100644 --- a/examples/react/tanstack-react-query/README.md +++ b/examples/react/tanstack-react-query/README.md @@ -1,10 +1,12 @@ # Using GraphQL Code Generator with React Query and React -This example illustrates using GraphQL Code Generator in a React application using React Query with `graphql-request` as a GraphQL Client. +This example illustrates using GraphQL Code Generator in a React application using React Query with +`graphql-request` as a GraphQL Client. You will find the TypeScript-based codegen configuration in [`codegen.ts`](./codegen.ts). -This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️ +This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder +that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️
@@ -14,6 +16,8 @@ https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular -- -Please note that the `client` preset used in this example is compatible with `graphql-request` from `5.0` as React Query fetcher. +Please note that the `client` preset used in this example is compatible with `graphql-request` from +`5.0` as React Query fetcher. -For indications in writing your fetcher, [please refer to our documentation](https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular#appendix-i-react-query-with-a-custom-fetcher-setup). +For indications in writing your fetcher, +[please refer to our documentation](https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular#appendix-i-react-query-with-a-custom-fetcher-setup). diff --git a/examples/react/tanstack-react-query/index.html b/examples/react/tanstack-react-query/index.html index ab66da90506..edb6fd979e3 100644 --- a/examples/react/tanstack-react-query/index.html +++ b/examples/react/tanstack-react-query/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/tanstack-react-query/package.json b/examples/react/tanstack-react-query/package.json index f9d67616151..b022a0fe4e5 100644 --- a/examples/react/tanstack-react-query/package.json +++ b/examples/react/tanstack-react-query/package.json @@ -2,6 +2,14 @@ "name": "example-react-tanstack-react-query", "version": "0.1.0", "private": true, + "scripts": { + "build": "vite build", + "codegen": "graphql-codegen --config codegen.ts", + "dev": "vite", + "start": "serve -s dist", + "test": "cypress run", + "test:end2end": "start-server-and-test start http://localhost:3000 test" + }, "dependencies": { "@tanstack/react-query": "4.36.1", "react": "^18.2.0", @@ -9,23 +17,15 @@ }, "devDependencies": { "@graphql-codegen/cli": "^5.0.2", - "@vitejs/plugin-react": "^4.0.0", "@types/jest": "^27.5.2", "@types/node": "^20.0.0", "@types/react": "^18.0.17", "@types/react-dom": "^18.0.10", - "typescript": "5.5.4", - "serve": "14.2.3", + "@vitejs/plugin-react": "^4.0.0", "cypress": "13.13.3", + "serve": "14.2.3", "start-server-and-test": "2.0.5", + "typescript": "5.5.4", "vite": "^5.0.0" - }, - "scripts": { - "dev": "vite", - "build": "vite build", - "start": "serve -s dist", - "test": "cypress run", - "test:end2end": "start-server-and-test start http://localhost:3000 test", - "codegen": "graphql-codegen --config codegen.ts" } } diff --git a/examples/react/tanstack-react-query/public/vite.svg b/examples/react/tanstack-react-query/public/vite.svg index e7b8dfb1b2a..c42ec851f89 100644 --- a/examples/react/tanstack-react-query/public/vite.svg +++ b/examples/react/tanstack-react-query/public/vite.svg @@ -1 +1,43 @@ - \ No newline at end of file + diff --git a/examples/react/tanstack-react-query/src/App.tsx b/examples/react/tanstack-react-query/src/App.tsx index 602dea2b052..f457c515baa 100644 --- a/examples/react/tanstack-react-query/src/App.tsx +++ b/examples/react/tanstack-react-query/src/App.tsx @@ -21,7 +21,11 @@ function App() { return (
{data && ( -
    {data.data?.allFilms?.edges?.map((e, i) => e?.node && )}
+
    + {data.data?.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
)}
); diff --git a/examples/react/tanstack-react-query/src/Film.tsx b/examples/react/tanstack-react-query/src/Film.tsx index a2caa582cc9..4c19efafd44 100644 --- a/examples/react/tanstack-react-query/src/Film.tsx +++ b/examples/react/tanstack-react-query/src/Film.tsx @@ -1,4 +1,4 @@ -import { graphql, FragmentType, useFragment } from './gql'; +import { FragmentType, graphql, useFragment } from './gql'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/react/tanstack-react-query/src/gql/fragment-masking.ts b/examples/react/tanstack-react-query/src/gql/fragment-masking.ts index dedac7e7f7e..1056e81bdf3 100644 --- a/examples/react/tanstack-react-query/src/gql/fragment-masking.ts +++ b/examples/react/tanstack-react-query/src/gql/fragment-masking.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; +import { DocumentTypeDecoration, ResultOf } from '@graphql-typed-document-node/core'; import { Incremental, TypedDocumentString } from './graphql'; export type FragmentType> = @@ -14,42 +14,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -58,21 +58,21 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: TypedDocumentString, fragmentNode: TypedDocumentString, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { const deferredFields = queryNode.__meta__?.deferredFields as Record; const fragName = fragmentNode.__meta__?.fragmentName as string | undefined; diff --git a/examples/react/tanstack-react-query/src/gql/gql.ts b/examples/react/tanstack-react-query/src/gql/gql.ts index af93f5ad198..ea6269be49b 100644 --- a/examples/react/tanstack-react-query/src/gql/gql.ts +++ b/examples/react/tanstack-react-query/src/gql/gql.ts @@ -23,13 +23,13 @@ const documents = { * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): typeof import('./graphql').AllFilmsWithVariablesQueryDocument; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): typeof import('./graphql').FilmItemFragmentDoc; export function graphql(source: string) { diff --git a/examples/react/tanstack-react-query/src/gql/graphql.ts b/examples/react/tanstack-react-query/src/gql/graphql.ts index 35ca605106b..e8762fa2fcd 100644 --- a/examples/react/tanstack-react-query/src/gql/graphql.ts +++ b/examples/react/tanstack-react-query/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -26,7 +31,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -45,7 +52,10 @@ export class TypedDocumentString { __apiType?: DocumentTypeDecoration['__apiType']; - constructor(private value: string, public __meta__?: Record) { + constructor( + private value: string, + public __meta__?: Record, + ) { super(value); } @@ -62,7 +72,7 @@ export const FilmItemFragmentDoc = new TypedDocumentString( producers } `, - { fragmentName: 'FilmItem' } + { fragmentName: 'FilmItem' }, ) as unknown as TypedDocumentString; export const AllFilmsWithVariablesQueryDocument = new TypedDocumentString(` query allFilmsWithVariablesQuery($first: Int!) { @@ -79,4 +89,7 @@ export const AllFilmsWithVariablesQueryDocument = new TypedDocumentString(` title releaseDate producers -}`) as unknown as TypedDocumentString; +}`) as unknown as TypedDocumentString< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/react/tanstack-react-query/src/logo.svg b/examples/react/tanstack-react-query/src/logo.svg index 9dfc1c058ce..02c651a6f61 100644 --- a/examples/react/tanstack-react-query/src/logo.svg +++ b/examples/react/tanstack-react-query/src/logo.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + + + diff --git a/examples/react/tanstack-react-query/src/main.css b/examples/react/tanstack-react-query/src/main.css index 7323ae85c54..89e57c7ccfe 100644 --- a/examples/react/tanstack-react-query/src/main.css +++ b/examples/react/tanstack-react-query/src/main.css @@ -1,7 +1,7 @@ body { margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', - 'Droid Sans', 'Helvetica Neue', sans-serif; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', + 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } diff --git a/examples/react/tanstack-react-query/src/main.tsx b/examples/react/tanstack-react-query/src/main.tsx index b309d8eba66..82260dbfee3 100644 --- a/examples/react/tanstack-react-query/src/main.tsx +++ b/examples/react/tanstack-react-query/src/main.tsx @@ -1,8 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import './main.css'; -import App from './App'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; +import App from './App'; const queryClient = new QueryClient(); @@ -12,5 +12,5 @@ root.render( - + , ); diff --git a/examples/react/tanstack-react-query/src/use-graphql.ts b/examples/react/tanstack-react-query/src/use-graphql.ts index 97131041e0d..673c31e2182 100644 --- a/examples/react/tanstack-react-query/src/use-graphql.ts +++ b/examples/react/tanstack-react-query/src/use-graphql.ts @@ -24,6 +24,6 @@ export function useGraphQL( variables: queryKey[1], }), }).then(response => response.json()) as Promise>; - } + }, ); } diff --git a/examples/react/urql/README.md b/examples/react/urql/README.md index 229c82db86a..b975e7a614e 100644 --- a/examples/react/urql/README.md +++ b/examples/react/urql/README.md @@ -1,10 +1,12 @@ # Using GraphQL Code Generator with URQL and React -This example illustrates using GraphQL Code Generator in a React application using the URQL GraphQL Client. +This example illustrates using GraphQL Code Generator in a React application using the URQL GraphQL +Client. You will find the TypeScript-based codegen configuration in [`codegen.ts`](./codegen.ts). -This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️ +This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder +that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️
@@ -14,4 +16,5 @@ https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular -- -Please note that the `client` preset used in this example is compatible with `@urql/core` (since `1.15.0`), `@urql/preact` (since `1.4.0`) and `urql` (since `1.11.0`). +Please note that the `client` preset used in this example is compatible with `@urql/core` (since +`1.15.0`), `@urql/preact` (since `1.4.0`) and `urql` (since `1.11.0`). diff --git a/examples/react/urql/index.html b/examples/react/urql/index.html index ab66da90506..edb6fd979e3 100644 --- a/examples/react/urql/index.html +++ b/examples/react/urql/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/urql/package.json b/examples/react/urql/package.json index ad70d154884..70310ab91ec 100644 --- a/examples/react/urql/package.json +++ b/examples/react/urql/package.json @@ -2,28 +2,28 @@ "name": "example-react-urql", "version": "0.1.0", "private": true, + "scripts": { + "build": "vite build", + "codegen": "graphql-codegen --config codegen.ts", + "dev": "vite", + "start": "serve -s dist", + "test": "cypress run", + "test:end2end": "start-server-and-test start http://localhost:3000 test" + }, "dependencies": { "react": "^18.2.0", "react-dom": "^18.2.0", "urql": "^3.0.0" }, "devDependencies": { + "@graphql-codegen/cli": "^5.0.2", "@types/react": "^18.0.17", "@types/react-dom": "^18.0.10", - "@graphql-codegen/cli": "^5.0.2", "@vitejs/plugin-react": "^4.0.0", - "typescript": "5.5.4", - "serve": "14.2.3", "cypress": "13.13.3", + "serve": "14.2.3", "start-server-and-test": "2.0.5", + "typescript": "5.5.4", "vite": "^5.0.0" - }, - "scripts": { - "dev": "vite", - "build": "vite build", - "start": "serve -s dist", - "test": "cypress run", - "test:end2end": "start-server-and-test start http://localhost:3000 test", - "codegen": "graphql-codegen --config codegen.ts" } } diff --git a/examples/react/urql/public/vite.svg b/examples/react/urql/public/vite.svg index ee9fadaf9c4..c42ec851f89 100644 --- a/examples/react/urql/public/vite.svg +++ b/examples/react/urql/public/vite.svg @@ -1 +1,43 @@ - + diff --git a/examples/react/urql/src/App.tsx b/examples/react/urql/src/App.tsx index 883c007bf7d..e13749e18f9 100644 --- a/examples/react/urql/src/App.tsx +++ b/examples/react/urql/src/App.tsx @@ -1,6 +1,6 @@ -import { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; -import { AnyVariables, OperationContext, RequestPolicy, useQuery, UseQueryResponse } from 'urql'; import type { DocumentNode } from 'graphql'; +import { AnyVariables, OperationContext, RequestPolicy, useQuery, UseQueryResponse } from 'urql'; +import { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; import './App.css'; import Film from './Film'; import { graphql } from './gql'; @@ -29,17 +29,17 @@ declare module 'urql' { variables?: Variables; } : Variables extends { - [P in keyof Variables]: Variables[P] | null; - } - ? { - variables?: Variables; - } - : { - variables: Variables; - }); + [P in keyof Variables]: Variables[P] | null; + } + ? { + variables?: Variables; + } + : { + variables: Variables; + }); export function useQuery( - args: UseQueryArgs + args: UseQueryArgs, ): UseQueryResponse; } @@ -53,7 +53,13 @@ function App() { return (
- {data &&
    {data.allFilms?.edges?.map((e, i) => e?.node && )}
} + {data && ( +
    + {data.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
+ )}
); } diff --git a/examples/react/urql/src/Film.tsx b/examples/react/urql/src/Film.tsx index 0681a716142..01833d97ef4 100644 --- a/examples/react/urql/src/Film.tsx +++ b/examples/react/urql/src/Film.tsx @@ -1,5 +1,5 @@ -import { FragmentType, useFragment } from './gql/fragment-masking'; import { graphql } from './gql'; +import { FragmentType, useFragment } from './gql/fragment-masking'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/react/urql/src/gql/fragment-masking.ts b/examples/react/urql/src/gql/fragment-masking.ts index dedac7e7f7e..1056e81bdf3 100644 --- a/examples/react/urql/src/gql/fragment-masking.ts +++ b/examples/react/urql/src/gql/fragment-masking.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; +import { DocumentTypeDecoration, ResultOf } from '@graphql-typed-document-node/core'; import { Incremental, TypedDocumentString } from './graphql'; export type FragmentType> = @@ -14,42 +14,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -58,21 +58,21 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: TypedDocumentString, fragmentNode: TypedDocumentString, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { const deferredFields = queryNode.__meta__?.deferredFields as Record; const fragName = fragmentNode.__meta__?.fragmentName as string | undefined; diff --git a/examples/react/urql/src/gql/gql.ts b/examples/react/urql/src/gql/gql.ts index b95f07e64fb..d5366b2dce2 100644 --- a/examples/react/urql/src/gql/gql.ts +++ b/examples/react/urql/src/gql/gql.ts @@ -23,13 +23,13 @@ const documents = { * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery199($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery199($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): typeof import('./graphql').AllFilmsWithVariablesQuery199Document; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): typeof import('./graphql').FilmItemFragmentDoc; export function graphql(source: string) { diff --git a/examples/react/urql/src/gql/graphql.ts b/examples/react/urql/src/gql/graphql.ts index 50a238bc455..f3504e4d322 100644 --- a/examples/react/urql/src/gql/graphql.ts +++ b/examples/react/urql/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -26,7 +31,9 @@ export type AllFilmsWithVariablesQuery199Query = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -45,7 +52,10 @@ export class TypedDocumentString { __apiType?: DocumentTypeDecoration['__apiType']; - constructor(private value: string, public __meta__?: Record) { + constructor( + private value: string, + public __meta__?: Record, + ) { super(value); } @@ -62,7 +72,7 @@ export const FilmItemFragmentDoc = new TypedDocumentString( producers } `, - { fragmentName: 'FilmItem' } + { fragmentName: 'FilmItem' }, ) as unknown as TypedDocumentString; export const AllFilmsWithVariablesQuery199Document = new TypedDocumentString(` query allFilmsWithVariablesQuery199($first: Int!) { @@ -79,4 +89,7 @@ export const AllFilmsWithVariablesQuery199Document = new TypedDocumentString(` title releaseDate producers -}`) as unknown as TypedDocumentString; +}`) as unknown as TypedDocumentString< + AllFilmsWithVariablesQuery199Query, + AllFilmsWithVariablesQuery199QueryVariables +>; diff --git a/examples/react/urql/src/logo.svg b/examples/react/urql/src/logo.svg index 9dfc1c058ce..02c651a6f61 100644 --- a/examples/react/urql/src/logo.svg +++ b/examples/react/urql/src/logo.svg @@ -1 +1,9 @@ - \ No newline at end of file + + + + + + + diff --git a/examples/react/urql/src/main.css b/examples/react/urql/src/main.css index 7323ae85c54..89e57c7ccfe 100644 --- a/examples/react/urql/src/main.css +++ b/examples/react/urql/src/main.css @@ -1,7 +1,7 @@ body { margin: 0; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', 'Fira Sans', - 'Droid Sans', 'Helvetica Neue', sans-serif; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', + 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; } diff --git a/examples/react/urql/src/main.tsx b/examples/react/urql/src/main.tsx index 09887543cb6..3c5ec664b76 100644 --- a/examples/react/urql/src/main.tsx +++ b/examples/react/urql/src/main.tsx @@ -1,7 +1,6 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; import { createClient, Provider } from 'urql'; - import './main.css'; import App from './App'; @@ -15,5 +14,5 @@ root.render( - + , ); diff --git a/examples/typescript-esm/README.md b/examples/typescript-esm/README.md index 41eadc5178f..2e78e1a4748 100644 --- a/examples/typescript-esm/README.md +++ b/examples/typescript-esm/README.md @@ -13,11 +13,14 @@ yarn start ## Explanation -In ESM the file extension `.js` must be appended to named imports. -This can be achieved by setting the codegen config `emitLegacyCommonJSImports` to `false` (see `codegen.yml`). +In ESM the file extension `.js` must be appended to named imports. This can be achieved by setting +the codegen config `emitLegacyCommonJSImports` to `false` (see `codegen.yml`). -TypeScript introduced a new module resolution algorithm for ESM in version 4.7. We set the `moduleResolution` to `node16` and the (output) module type to `node16` (see `tsconfig.json`). -Additionally, within the `package.json` we specify the `type` property with the value `module` in order to instruct Node.js, bundlers and other tools that all `.js` files within this folder should be treated as ESM modules. +TypeScript introduced a new module resolution algorithm for ESM in version 4.7. We set the +`moduleResolution` to `node16` and the (output) module type to `node16` (see `tsconfig.json`). +Additionally, within the `package.json` we specify the `type` property with the value `module` in +order to instruct Node.js, bundlers and other tools that all `.js` files within this folder should +be treated as ESM modules. ## Useful resources diff --git a/examples/typescript-esm/package.json b/examples/typescript-esm/package.json index a585f8dbbf2..95c1f890d64 100644 --- a/examples/typescript-esm/package.json +++ b/examples/typescript-esm/package.json @@ -1,20 +1,20 @@ { "name": "example-typescript-esm", "version": "0.0.0", + "type": "module", "private": true, - "devDependencies": { - "@graphql-codegen/cli": "5.0.2" + "scripts": { + "build": "tsc", + "codegen": "graphql-codegen-esm --config codegen.cjs", + "start": "node dist/main.js", + "test:end2end": "yarn start" }, "dependencies": { "@graphql-typed-document-node/core": "3.2.0", "graphql": "16.9.0" }, - "scripts": { - "codegen": "graphql-codegen-esm --config codegen.cjs", - "build": "tsc", - "start": "node dist/main.js", - "test:end2end": "yarn start" + "devDependencies": { + "@graphql-codegen/cli": "5.0.2" }, - "type": "module", "bob": false } diff --git a/examples/typescript-esm/src/executeOperation.ts b/examples/typescript-esm/src/executeOperation.ts index 6ee88075a09..868c4db58d1 100644 --- a/examples/typescript-esm/src/executeOperation.ts +++ b/examples/typescript-esm/src/executeOperation.ts @@ -1,7 +1,7 @@ import * as https from 'node:https'; -import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; import type { ExecutionResult } from 'graphql'; import { print } from 'graphql'; +import type { TypedDocumentNode } from '@graphql-typed-document-node/core'; export function executeOperation( url: string, @@ -21,13 +21,13 @@ export function executeOperation( resolve(JSON.parse(data)); }); response.on('error', reject); - } + }, ); request.write( JSON.stringify({ query: print(operation), variables: variables == null ? undefined : variables, - }) + }), ); request.end(); }); diff --git a/examples/typescript-esm/src/gql/fragment-masking.ts b/examples/typescript-esm/src/gql/fragment-masking.ts index a6b3407f590..749b250a4de 100644 --- a/examples/typescript-esm/src/gql/fragment-masking.ts +++ b/examples/typescript-esm/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql.js'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/typescript-esm/src/gql/gql.ts b/examples/typescript-esm/src/gql/gql.ts index 82048718302..04d4b4b97b8 100644 --- a/examples/typescript-esm/src/gql/gql.ts +++ b/examples/typescript-esm/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql.js'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql.js'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n' + source: '\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n', ): (typeof documents)['\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query AllPeopleWithVariablesQuery($first: Int!) {\n allPeople(first: $first) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n' + source: '\n query AllPeopleWithVariablesQuery($first: Int!) {\n allPeople(first: $first) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n', ): (typeof documents)['\n query AllPeopleWithVariablesQuery($first: Int!) {\n allPeople(first: $first) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/typescript-esm/src/gql/graphql.ts b/examples/typescript-esm/src/gql/graphql.ts index 963a3da971c..b881160570d 100644 --- a/examples/typescript-esm/src/gql/graphql.ts +++ b/examples/typescript-esm/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -66,7 +71,11 @@ export const AllPeopleQueryDocument = { kind: 'Field', name: { kind: 'Name', value: 'allPeople' }, arguments: [ - { kind: 'Argument', name: { kind: 'Name', value: 'first' }, value: { kind: 'IntValue', value: '5' } }, + { + kind: 'Argument', + name: { kind: 'Name', value: 'first' }, + value: { kind: 'IntValue', value: '5' }, + }, ], selectionSet: { kind: 'SelectionSet', @@ -89,7 +98,9 @@ export const AllPeopleQueryDocument = { name: { kind: 'Name', value: 'homeworld' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'Field', name: { kind: 'Name', value: 'name' } }], + selections: [ + { kind: 'Field', name: { kind: 'Name', value: 'name' } }, + ], }, }, ], @@ -117,7 +128,10 @@ export const AllPeopleWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -154,7 +168,9 @@ export const AllPeopleWithVariablesQueryDocument = { name: { kind: 'Name', value: 'homeworld' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'Field', name: { kind: 'Name', value: 'name' } }], + selections: [ + { kind: 'Field', name: { kind: 'Name', value: 'name' } }, + ], }, }, ], @@ -170,4 +186,7 @@ export const AllPeopleWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllPeopleWithVariablesQueryQuery, + AllPeopleWithVariablesQueryQueryVariables +>; diff --git a/examples/typescript-graphql-request/README.md b/examples/typescript-graphql-request/README.md index 40fdfaa703d..a18a7f6129d 100644 --- a/examples/typescript-graphql-request/README.md +++ b/examples/typescript-graphql-request/README.md @@ -1,6 +1,7 @@ # GraphQL Request Example -This example showcases how to use GraphQL Code Generator for building a type-safe GraphQL schema utilizing the schema definition language first workflow. +This example showcases how to use GraphQL Code Generator for building a type-safe GraphQL schema +utilizing the schema definition language first workflow. ## Usage diff --git a/examples/typescript-graphql-request/package.json b/examples/typescript-graphql-request/package.json index 1be429ee121..69ecc230ea3 100644 --- a/examples/typescript-graphql-request/package.json +++ b/examples/typescript-graphql-request/package.json @@ -1,23 +1,23 @@ { "name": "example-typescript-graphql-request", "version": "0.0.0", + "type": "commonjs", "private": true, - "devDependencies": { - "@graphql-codegen/cli": "5.0.2", - "babel-jest": "29.7.0", - "jest": "28.1.3" - }, - "dependencies": { - "graphql": "16.9.0", - "graphql-yoga": "5.7.0", - "graphql-request": "5.2.0" - }, "scripts": { - "codegen": "graphql-codegen --config codegen.ts", "build": "tsc", + "codegen": "graphql-codegen --config codegen.ts", "dev": "ts-node src/main.ts", "test:end2end": "yarn jest" }, - "type": "commonjs", + "dependencies": { + "graphql": "16.9.0", + "graphql-request": "5.2.0", + "graphql-yoga": "5.7.0" + }, + "devDependencies": { + "@graphql-codegen/cli": "5.0.2", + "babel-jest": "29.7.0", + "jest": "28.1.3" + }, "bob": false } diff --git a/examples/typescript-graphql-request/src/gql/fragment-masking.ts b/examples/typescript-graphql-request/src/gql/fragment-masking.ts index dedac7e7f7e..1056e81bdf3 100644 --- a/examples/typescript-graphql-request/src/gql/fragment-masking.ts +++ b/examples/typescript-graphql-request/src/gql/fragment-masking.ts @@ -1,5 +1,5 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; +import { DocumentTypeDecoration, ResultOf } from '@graphql-typed-document-node/core'; import { Incremental, TypedDocumentString } from './graphql'; export type FragmentType> = @@ -14,42 +14,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -58,21 +58,21 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: TypedDocumentString, fragmentNode: TypedDocumentString, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { const deferredFields = queryNode.__meta__?.deferredFields as Record; const fragName = fragmentNode.__meta__?.fragmentName as string | undefined; diff --git a/examples/typescript-graphql-request/src/gql/gql.ts b/examples/typescript-graphql-request/src/gql/gql.ts index 6c24a315626..5a27dfbfa9e 100644 --- a/examples/typescript-graphql-request/src/gql/gql.ts +++ b/examples/typescript-graphql-request/src/gql/gql.ts @@ -23,13 +23,13 @@ const documents = { * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n' + source: '\n query AllPeopleQuery {\n allPeople(first: 5) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n', ): typeof import('./graphql').AllPeopleQueryDocument; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query AllPeopleWithVariablesQuery($first: Int!) {\n allPeople(first: $first) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n' + source: '\n query AllPeopleWithVariablesQuery($first: Int!) {\n allPeople(first: $first) {\n edges {\n node {\n name\n homeworld {\n name\n }\n }\n }\n }\n }\n', ): typeof import('./graphql').AllPeopleWithVariablesQueryDocument; export function graphql(source: string) { diff --git a/examples/typescript-graphql-request/src/gql/graphql.ts b/examples/typescript-graphql-request/src/gql/graphql.ts index 9d63662879b..fb784b97d04 100644 --- a/examples/typescript-graphql-request/src/gql/graphql.ts +++ b/examples/typescript-graphql-request/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { DocumentTypeDecoration } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -58,7 +63,10 @@ export class TypedDocumentString { __apiType?: DocumentTypeDecoration['__apiType']; - constructor(private value: string, public __meta__?: Record) { + constructor( + private value: string, + public __meta__?: Record, + ) { super(value); } @@ -94,4 +102,7 @@ export const AllPeopleWithVariablesQueryDocument = new TypedDocumentString(` } } } - `) as unknown as TypedDocumentString; + `) as unknown as TypedDocumentString< + AllPeopleWithVariablesQueryQuery, + AllPeopleWithVariablesQueryQueryVariables +>; diff --git a/examples/typescript-resolvers/README.md b/examples/typescript-resolvers/README.md index b0109e6bd5b..2c9786dd27d 100644 --- a/examples/typescript-resolvers/README.md +++ b/examples/typescript-resolvers/README.md @@ -1,6 +1,7 @@ # Typescript Resolvers Example -This example showcases how to use GraphQL Code Generator for building a type-safe GraphQL schema utilizing the schema definition language first workflow. +This example showcases how to use GraphQL Code Generator for building a type-safe GraphQL schema +utilizing the schema definition language first workflow. ## Usage diff --git a/examples/typescript-resolvers/package.json b/examples/typescript-resolvers/package.json index 15f6099b378..d1e350bf107 100644 --- a/examples/typescript-resolvers/package.json +++ b/examples/typescript-resolvers/package.json @@ -1,23 +1,23 @@ { "name": "example-typescript-resolvers", "version": "0.0.0", + "type": "commonjs", "private": true, - "devDependencies": { - "@graphql-codegen/cli": "5.0.2", - "@graphql-codegen/typescript": "4.0.9", - "@graphql-codegen/typescript-resolvers": "4.2.1" - }, - "dependencies": { - "graphql": "16.9.0", - "graphql-yoga": "5.7.0" - }, "scripts": { - "codegen": "graphql-codegen --config codegen.ts", "build": "tsc", + "codegen": "graphql-codegen --config codegen.ts", "dev": "ts-node src/main.ts", "test": "exit 0", "test:end2end": "exit 0" }, - "type": "commonjs", + "dependencies": { + "graphql": "16.9.0", + "graphql-yoga": "5.7.0" + }, + "devDependencies": { + "@graphql-codegen/cli": "5.0.2", + "@graphql-codegen/typescript": "4.0.9", + "@graphql-codegen/typescript-resolvers": "4.2.1" + }, "bob": false } diff --git a/examples/typescript-resolvers/src/main.ts b/examples/typescript-resolvers/src/main.ts index e347751902d..d86c84e1692 100644 --- a/examples/typescript-resolvers/src/main.ts +++ b/examples/typescript-resolvers/src/main.ts @@ -1,5 +1,5 @@ -import { createYoga, createSchema } from 'graphql-yoga'; import { createServer } from 'http'; +import { createSchema, createYoga } from 'graphql-yoga'; import type { Resolvers } from './type-defs.d'; const typeDefs = /* GraphQL */ ` diff --git a/examples/typescript-resolvers/src/type-defs.d.ts b/examples/typescript-resolvers/src/type-defs.d.ts index 7ac21289be1..a097e9f0946 100644 --- a/examples/typescript-resolvers/src/type-defs.d.ts +++ b/examples/typescript-resolvers/src/type-defs.d.ts @@ -1,11 +1,16 @@ import { GraphQLResolveInfo } from 'graphql'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { @@ -53,24 +58,30 @@ export type ResolverFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Promise | TResult; export type SubscriptionSubscribeFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => AsyncIterable | Promise>; export type SubscriptionResolveFn = ( parent: TParent, args: TArgs, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => TResult | Promise; -export interface SubscriptionSubscriberObject { +export interface SubscriptionSubscriberObject< + TResult, + TKey extends string, + TParent, + TContext, + TArgs, +> { subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>; resolve?: SubscriptionResolveFn; } @@ -84,20 +95,26 @@ export type SubscriptionObject | SubscriptionResolverObject; -export type SubscriptionResolver = +export type SubscriptionResolver< + TResult, + TKey extends string, + TParent = {}, + TContext = {}, + TArgs = {}, +> = | ((...args: any[]) => SubscriptionObject) | SubscriptionObject; export type TypeResolveFn = ( parent: TParent, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => Maybe | Promise>; export type IsTypeOfResolverFn = ( obj: T, context: TContext, - info: GraphQLResolveInfo + info: GraphQLResolveInfo, ) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -107,7 +124,7 @@ export type DirectiveResolverFn TResult | Promise; /** Mapping between all available schema types and the resolvers types */ @@ -132,7 +149,7 @@ export type ResolversParentTypes = { export type MutationResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation'] + ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation'], > = { calculateSum?: Resolver< ResolversTypes['Float'], @@ -150,7 +167,7 @@ export type MutationResolvers< export type QueryResolvers< ContextType = any, - ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] + ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'], > = { hello?: Resolver; }; diff --git a/examples/vite/vite-react-cts/index.html b/examples/vite/vite-react-cts/index.html index e0d1c840806..e4b78eae123 100644 --- a/examples/vite/vite-react-cts/index.html +++ b/examples/vite/vite-react-cts/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vite/vite-react-cts/package.json b/examples/vite/vite-react-cts/package.json index 1cfad4a396f..f55ccb67677 100644 --- a/examples/vite/vite-react-cts/package.json +++ b/examples/vite/vite-react-cts/package.json @@ -1,13 +1,13 @@ { "name": "example-vite-react-cts", - "private": true, "version": "0.0.0", "type": "module", + "private": true, "scripts": { - "dev": "vite", "build": "tsc && vite build", - "start": "vite preview --port 3000", "codegen": "graphql-codegen --config codegen.cts", + "dev": "vite", + "start": "vite preview --port 3000", "test": "cypress run", "test:end2end": "start-server-and-test start http://localhost:3000 test" }, diff --git a/examples/vite/vite-react-cts/src/Film.tsx b/examples/vite/vite-react-cts/src/Film.tsx index 0681a716142..01833d97ef4 100644 --- a/examples/vite/vite-react-cts/src/Film.tsx +++ b/examples/vite/vite-react-cts/src/Film.tsx @@ -1,5 +1,5 @@ -import { FragmentType, useFragment } from './gql/fragment-masking'; import { graphql } from './gql'; +import { FragmentType, useFragment } from './gql/fragment-masking'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/vite/vite-react-cts/src/gql/fragment-masking.ts b/examples/vite/vite-react-cts/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/vite/vite-react-cts/src/gql/fragment-masking.ts +++ b/examples/vite/vite-react-cts/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/vite/vite-react-cts/src/gql/gql.ts b/examples/vite/vite-react-cts/src/gql/gql.ts index d1ba5f9aba1..99310a9d1b0 100644 --- a/examples/vite/vite-react-cts/src/gql/gql.ts +++ b/examples/vite/vite-react-cts/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): (typeof documents)['\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): (typeof documents)['\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/vite/vite-react-cts/src/gql/graphql.ts b/examples/vite/vite-react-cts/src/gql/graphql.ts index 79331d3022d..3afa88fcc45 100644 --- a/examples/vite/vite-react-cts/src/gql/graphql.ts +++ b/examples/vite/vite-react-cts/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -34,7 +39,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -69,7 +76,10 @@ export const AllFilmsWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -99,7 +109,9 @@ export const AllFilmsWithVariablesQueryDocument = { name: { kind: 'Name', value: 'node' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }, + ], }, }, ], @@ -126,4 +138,7 @@ export const AllFilmsWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/vite/vite-react-cts/src/main.tsx b/examples/vite/vite-react-cts/src/main.tsx index a7ae3a62dc5..b8c8af05c8c 100644 --- a/examples/vite/vite-react-cts/src/main.tsx +++ b/examples/vite/vite-react-cts/src/main.tsx @@ -1,8 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; +import { ApolloClient, ApolloProvider, InMemoryCache, useQuery } from '@apollo/client'; import Film from './Film'; import { graphql } from './gql'; -import { ApolloClient, InMemoryCache, ApolloProvider, useQuery } from '@apollo/client'; const client = new ApolloClient({ uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index', @@ -25,7 +25,13 @@ function App() { const { data } = useQuery(allFilmsWithVariablesQueryDocument, { variables: { first: 10 } }); return (
- {data &&
    {data.allFilms?.edges?.map((e, i) => e?.node && )}
} + {data && ( +
    + {data.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
+ )}
); } @@ -35,5 +41,5 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( - + , ); diff --git a/examples/vite/vite-react-mts/index.html b/examples/vite/vite-react-mts/index.html index e0d1c840806..e4b78eae123 100644 --- a/examples/vite/vite-react-mts/index.html +++ b/examples/vite/vite-react-mts/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vite/vite-react-mts/package.json b/examples/vite/vite-react-mts/package.json index 339989e7ed6..2a785b50b56 100644 --- a/examples/vite/vite-react-mts/package.json +++ b/examples/vite/vite-react-mts/package.json @@ -1,13 +1,13 @@ { "name": "example-vite-react-mts", - "private": true, "version": "0.0.0", "type": "module", + "private": true, "scripts": { - "dev": "vite", "build": "tsc && vite build", - "start": "vite preview --port 3000", "codegen": "graphql-codegen --config codegen.mts", + "dev": "vite", + "start": "vite preview --port 3000", "test": "cypress run", "test:end2end": "start-server-and-test start http://localhost:3000 test" }, diff --git a/examples/vite/vite-react-mts/src/Film.tsx b/examples/vite/vite-react-mts/src/Film.tsx index 0681a716142..01833d97ef4 100644 --- a/examples/vite/vite-react-mts/src/Film.tsx +++ b/examples/vite/vite-react-mts/src/Film.tsx @@ -1,5 +1,5 @@ -import { FragmentType, useFragment } from './gql/fragment-masking'; import { graphql } from './gql'; +import { FragmentType, useFragment } from './gql/fragment-masking'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/vite/vite-react-mts/src/gql/fragment-masking.ts b/examples/vite/vite-react-mts/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/vite/vite-react-mts/src/gql/fragment-masking.ts +++ b/examples/vite/vite-react-mts/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/vite/vite-react-mts/src/gql/gql.ts b/examples/vite/vite-react-mts/src/gql/gql.ts index d1ba5f9aba1..99310a9d1b0 100644 --- a/examples/vite/vite-react-mts/src/gql/gql.ts +++ b/examples/vite/vite-react-mts/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): (typeof documents)['\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): (typeof documents)['\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/vite/vite-react-mts/src/gql/graphql.ts b/examples/vite/vite-react-mts/src/gql/graphql.ts index 79331d3022d..3afa88fcc45 100644 --- a/examples/vite/vite-react-mts/src/gql/graphql.ts +++ b/examples/vite/vite-react-mts/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -34,7 +39,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -69,7 +76,10 @@ export const AllFilmsWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -99,7 +109,9 @@ export const AllFilmsWithVariablesQueryDocument = { name: { kind: 'Name', value: 'node' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }, + ], }, }, ], @@ -126,4 +138,7 @@ export const AllFilmsWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/vite/vite-react-mts/src/main.tsx b/examples/vite/vite-react-mts/src/main.tsx index a7ae3a62dc5..b8c8af05c8c 100644 --- a/examples/vite/vite-react-mts/src/main.tsx +++ b/examples/vite/vite-react-mts/src/main.tsx @@ -1,8 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; +import { ApolloClient, ApolloProvider, InMemoryCache, useQuery } from '@apollo/client'; import Film from './Film'; import { graphql } from './gql'; -import { ApolloClient, InMemoryCache, ApolloProvider, useQuery } from '@apollo/client'; const client = new ApolloClient({ uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index', @@ -25,7 +25,13 @@ function App() { const { data } = useQuery(allFilmsWithVariablesQueryDocument, { variables: { first: 10 } }); return (
- {data &&
    {data.allFilms?.edges?.map((e, i) => e?.node && )}
} + {data && ( +
    + {data.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
+ )}
); } @@ -35,5 +41,5 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( - + , ); diff --git a/examples/vite/vite-react-ts/index.html b/examples/vite/vite-react-ts/index.html index e0d1c840806..e4b78eae123 100644 --- a/examples/vite/vite-react-ts/index.html +++ b/examples/vite/vite-react-ts/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vite/vite-react-ts/package.json b/examples/vite/vite-react-ts/package.json index bc6b32bfb0a..a984725337f 100644 --- a/examples/vite/vite-react-ts/package.json +++ b/examples/vite/vite-react-ts/package.json @@ -1,13 +1,13 @@ { "name": "example-vite-react-ts", - "private": true, "version": "0.0.0", "type": "module", + "private": true, "scripts": { - "dev": "vite", "build": "tsc && vite build", - "start": "vite preview --port 3000", "codegen": "graphql-codegen --config codegen.ts", + "dev": "vite", + "start": "vite preview --port 3000", "test": "cypress run", "test:end2end": "start-server-and-test start http://localhost:3000 test" }, diff --git a/examples/vite/vite-react-ts/src/Film.tsx b/examples/vite/vite-react-ts/src/Film.tsx index 0681a716142..01833d97ef4 100644 --- a/examples/vite/vite-react-ts/src/Film.tsx +++ b/examples/vite/vite-react-ts/src/Film.tsx @@ -1,5 +1,5 @@ -import { FragmentType, useFragment } from './gql/fragment-masking'; import { graphql } from './gql'; +import { FragmentType, useFragment } from './gql/fragment-masking'; export const FilmFragment = graphql(/* GraphQL */ ` fragment FilmItem on Film { diff --git a/examples/vite/vite-react-ts/src/gql/fragment-masking.ts b/examples/vite/vite-react-ts/src/gql/fragment-masking.ts index c469b9c617c..60a650c2641 100644 --- a/examples/vite/vite-react-ts/src/gql/fragment-masking.ts +++ b/examples/vite/vite-react-ts/src/gql/fragment-masking.ts @@ -1,6 +1,10 @@ /* eslint-disable */ -import { ResultOf, DocumentTypeDecoration, TypedDocumentNode } from '@graphql-typed-document-node/core'; import { FragmentDefinitionNode } from 'graphql'; +import { + DocumentTypeDecoration, + ResultOf, + TypedDocumentNode, +} from '@graphql-typed-document-node/core'; import { Incremental } from './graphql'; export type FragmentType> = @@ -15,42 +19,42 @@ export type FragmentType> // return non-nullable if `fragmentType` is non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> + fragmentType: FragmentType>, ): TType; // return nullable if `fragmentType` is undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | undefined + fragmentType: FragmentType> | undefined, ): TType | undefined; // return nullable if `fragmentType` is nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null + fragmentType: FragmentType> | null, ): TType | null; // return nullable if `fragmentType` is nullable or undefined export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: FragmentType> | null | undefined + fragmentType: FragmentType> | null | undefined, ): TType | null | undefined; // return array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> + fragmentType: Array>>, ): Array; // return array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: Array>> | null | undefined + fragmentType: Array>> | null | undefined, ): Array | null | undefined; // return readonly array of non-nullable if `fragmentType` is array of non-nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> + fragmentType: ReadonlyArray>>, ): ReadonlyArray; // return readonly array of nullable if `fragmentType` is array of nullable export function useFragment( _documentNode: DocumentTypeDecoration, - fragmentType: ReadonlyArray>> | null | undefined + fragmentType: ReadonlyArray>> | null | undefined, ): ReadonlyArray | null | undefined; export function useFragment( _documentNode: DocumentTypeDecoration, @@ -59,24 +63,25 @@ export function useFragment( | Array>> | ReadonlyArray>> | null - | undefined + | undefined, ): TType | Array | ReadonlyArray | null | undefined { return fragmentType as any; } -export function makeFragmentData, FT extends ResultOf>( - data: FT, - _fragment: F -): FragmentType { +export function makeFragmentData< + F extends DocumentTypeDecoration, + FT extends ResultOf, +>(data: FT, _fragment: F): FragmentType { return data as FragmentType; } export function isFragmentReady( queryNode: DocumentTypeDecoration, fragmentNode: TypedDocumentNode, - data: FragmentType, any>> | null | undefined + data: FragmentType, any>> | null | undefined, ): data is FragmentType { - const deferredFields = (queryNode as { __meta__?: { deferredFields: Record } }).__meta__ - ?.deferredFields; + const deferredFields = ( + queryNode as { __meta__?: { deferredFields: Record } } + ).__meta__?.deferredFields; if (!deferredFields) return true; diff --git a/examples/vite/vite-react-ts/src/gql/gql.ts b/examples/vite/vite-react-ts/src/gql/gql.ts index d1ba5f9aba1..99310a9d1b0 100644 --- a/examples/vite/vite-react-ts/src/gql/gql.ts +++ b/examples/vite/vite-react-ts/src/gql/gql.ts @@ -1,6 +1,6 @@ /* eslint-disable */ -import * as types from './graphql'; import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; +import * as types from './graphql'; /** * Map of all GraphQL operations in the project. @@ -38,22 +38,18 @@ export function graphql(source: string): unknown; * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n' + source: '\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n', ): (typeof documents)['\n fragment FilmItem on Film {\n id\n title\n releaseDate\n producers\n }\n']; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ export function graphql( - source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n' + source: '\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n', ): (typeof documents)['\n query allFilmsWithVariablesQuery($first: Int!) {\n allFilms(first: $first) {\n edges {\n node {\n ...FilmItem\n }\n }\n }\n }\n']; export function graphql(source: string) { return (documents as any)[source] ?? {}; } -export type DocumentType> = TDocumentNode extends DocumentNode< - infer TType, - any -> - ? TType - : never; +export type DocumentType> = + TDocumentNode extends DocumentNode ? TType : never; diff --git a/examples/vite/vite-react-ts/src/gql/graphql.ts b/examples/vite/vite-react-ts/src/gql/graphql.ts index 79331d3022d..3afa88fcc45 100644 --- a/examples/vite/vite-react-ts/src/gql/graphql.ts +++ b/examples/vite/vite-react-ts/src/gql/graphql.ts @@ -1,12 +1,17 @@ /* eslint-disable */ import { TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; + export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; export type MakeOptional = Omit & { [SubKey in K]?: Maybe }; export type MakeMaybe = Omit & { [SubKey in K]: Maybe }; -export type MakeEmpty = { [_ in K]?: never }; -export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; +export type MakeEmpty = { + [_ in K]?: never; +}; +export type Incremental = + | T + | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never }; /** All built-in and custom scalars, mapped to their actual values */ export type Scalars = { ID: { input: string; output: string }; @@ -34,7 +39,9 @@ export type AllFilmsWithVariablesQueryQuery = { __typename?: 'FilmsConnection'; edges?: Array<{ __typename?: 'FilmsEdge'; - node?: ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) | null; + node?: + | ({ __typename?: 'Film' } & { ' $fragmentRefs'?: { FilmItemFragment: FilmItemFragment } }) + | null; } | null> | null; } | null; }; @@ -69,7 +76,10 @@ export const AllFilmsWithVariablesQueryDocument = { { kind: 'VariableDefinition', variable: { kind: 'Variable', name: { kind: 'Name', value: 'first' } }, - type: { kind: 'NonNullType', type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } } }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, }, ], selectionSet: { @@ -99,7 +109,9 @@ export const AllFilmsWithVariablesQueryDocument = { name: { kind: 'Name', value: 'node' }, selectionSet: { kind: 'SelectionSet', - selections: [{ kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }], + selections: [ + { kind: 'FragmentSpread', name: { kind: 'Name', value: 'FilmItem' } }, + ], }, }, ], @@ -126,4 +138,7 @@ export const AllFilmsWithVariablesQueryDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode< + AllFilmsWithVariablesQueryQuery, + AllFilmsWithVariablesQueryQueryVariables +>; diff --git a/examples/vite/vite-react-ts/src/main.tsx b/examples/vite/vite-react-ts/src/main.tsx index a7ae3a62dc5..b8c8af05c8c 100644 --- a/examples/vite/vite-react-ts/src/main.tsx +++ b/examples/vite/vite-react-ts/src/main.tsx @@ -1,8 +1,8 @@ import React from 'react'; import ReactDOM from 'react-dom/client'; +import { ApolloClient, ApolloProvider, InMemoryCache, useQuery } from '@apollo/client'; import Film from './Film'; import { graphql } from './gql'; -import { ApolloClient, InMemoryCache, ApolloProvider, useQuery } from '@apollo/client'; const client = new ApolloClient({ uri: 'https://swapi-graphql.netlify.app/.netlify/functions/index', @@ -25,7 +25,13 @@ function App() { const { data } = useQuery(allFilmsWithVariablesQueryDocument, { variables: { first: 10 } }); return (
- {data &&
    {data.allFilms?.edges?.map((e, i) => e?.node && )}
} + {data && ( +
    + {data.allFilms?.edges?.map( + (e, i) => e?.node && , + )} +
+ )}
); } @@ -35,5 +41,5 @@ ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render( - + , ); diff --git a/examples/vue/apollo-composable/README.md b/examples/vue/apollo-composable/README.md index 2578dc83530..e12c99b4526 100644 --- a/examples/vue/apollo-composable/README.md +++ b/examples/vue/apollo-composable/README.md @@ -1,10 +1,12 @@ # Using GraphQL Code Generator with Apollo Composable and Vue 3 -This example illustrates using GraphQL Code Generator in a Vue 3 application using the Apollo Composable GraphQL Client. +This example illustrates using GraphQL Code Generator in a Vue 3 application using the Apollo +Composable GraphQL Client. You will find the TypeScript-based codegen configuration in [`codegen.ts`](./codegen.ts). -This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️ +This simple codegen configuration generates types and helpers in the [`src/gql`](./src/gql/) folder +that help you to get typed GraphQL Queries and Mutations seamlessly ⚡️
@@ -14,4 +16,5 @@ https://www.the-guild.dev/graphql/codegen/docs/guides/react-vue-angular -- -Please note that the `client` preset used in this example is compatible with `@vue/apollo-composable` (since `4.0.0-alpha.13`). +Please note that the `client` preset used in this example is compatible with +`@vue/apollo-composable` (since `4.0.0-alpha.13`). diff --git a/examples/vue/apollo-composable/index.html b/examples/vue/apollo-composable/index.html index 11603f878f1..dcd696757f4 100644 --- a/examples/vue/apollo-composable/index.html +++ b/examples/vue/apollo-composable/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/apollo-composable/package.json b/examples/vue/apollo-composable/package.json index fc577484225..eea62f61709 100644 --- a/examples/vue/apollo-composable/package.json +++ b/examples/vue/apollo-composable/package.json @@ -3,11 +3,11 @@ "version": "0.0.0", "private": true, "scripts": { - "dev": "vite", "build": "vite build", "codegen": "graphql-codegen --config codegen.ts", - "test": "cypress run", + "dev": "vite", "start": "serve -s dist", + "test": "cypress run", "test:end2end": "start-server-and-test start http://localhost:3000 test" }, "dependencies": { @@ -19,11 +19,11 @@ "devDependencies": { "@graphql-codegen/cli": "^5.0.2", "@vitejs/plugin-vue": "^5.0.0", + "cypress": "13.13.3", + "serve": "14.2.3", + "start-server-and-test": "2.0.5", "typescript": "^5.0.0", "vite": "^5.0.0", - "vue-tsc": "^1.0.24", - "serve": "14.2.3", - "cypress": "13.13.3", - "start-server-and-test": "2.0.5" + "vue-tsc": "^1.0.24" } } diff --git a/examples/vue/apollo-composable/src/App.vue b/examples/vue/apollo-composable/src/App.vue index 5764b79545e..3b47e557bdc 100644 --- a/examples/vue/apollo-composable/src/App.vue +++ b/examples/vue/apollo-composable/src/App.vue @@ -1,8 +1,8 @@ diff --git a/examples/vue/apollo-composable/src/assets/base.css b/examples/vue/apollo-composable/src/assets/base.css index db6752e21ac..df934ae17e6 100644 --- a/examples/vue/apollo-composable/src/assets/base.css +++ b/examples/vue/apollo-composable/src/assets/base.css @@ -63,10 +63,23 @@ body { min-height: 100vh; color: var(--color-text); background: var(--color-background); - transition: color 0.5s, background-color 0.5s; + transition: + color 0.5s, + background-color 0.5s; line-height: 1.6; - font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Fira Sans', - 'Droid Sans', 'Helvetica Neue', sans-serif; + font-family: + Inter, + -apple-system, + BlinkMacSystemFont, + 'Segoe UI', + Roboto, + Oxygen, + Ubuntu, + Cantarell, + 'Fira Sans', + 'Droid Sans', + 'Helvetica Neue', + sans-serif; font-size: 15px; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; diff --git a/examples/vue/apollo-composable/src/assets/logo.svg b/examples/vue/apollo-composable/src/assets/logo.svg index bc826fed80a..1fb5160cd28 100644 --- a/examples/vue/apollo-composable/src/assets/logo.svg +++ b/examples/vue/apollo-composable/src/assets/logo.svg @@ -1 +1,10 @@ - \ No newline at end of file + + + + diff --git a/examples/vue/apollo-composable/src/components/FilmItem.vue b/examples/vue/apollo-composable/src/components/FilmItem.vue index fab56f6e8dc..b96b96fe9f2 100644 --- a/examples/vue/apollo-composable/src/components/FilmItem.vue +++ b/examples/vue/apollo-composable/src/components/FilmItem.vue @@ -1,5 +1,5 @@