Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotansimha/graphql-code-generator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: @graphql-codegen/typescript@4.0.7
Choose a base ref
...
head repository: dotansimha/graphql-code-generator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: @graphql-codegen/typescript@4.0.8
Choose a head ref
  • 12 commits
  • 74 files changed
  • 11 contributors

Commits on Jun 4, 2024

  1. Simple grammar fix (#9924)

    alexownejazayeri authored Jun 4, 2024

    Verified

    This commit was signed with the committer’s verified signature.
    IvanGoncharov Ivan Goncharov
    Copy the full SHA
    c720b1b View commit details

Commits on Jun 6, 2024

  1. docs: vanilla typescript guide (#9990)

    n1ru4l authored Jun 6, 2024
    Copy the full SHA
    32e0507 View commit details

Commits on Jun 8, 2024

  1. docs: add "Created by The Guild" logo to the readme (#9992)

    * add the guild README.md badge
    
    * cleanup
    capaj authored Jun 8, 2024
    Copy the full SHA
    39e6e80 View commit details

Commits on Jun 13, 2024

  1. feat(client-preset): preserving Array<T> or ReadonlyArray<T> in useFr…

    …agment() data (#9804)
    
    * Preserving Array<T> or ReadonlyArray<T>
    
    * adding changeset
    
    * Fixing Property 'join' does not exist on type 'string' error
    
    * update fixtures
    
    * changeset formatting
    
    ---------
    
    Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
    rachel-church and n1ru4l authored Jun 13, 2024
    Copy the full SHA
    5e594ef View commit details
  2. feat(client-preset): persisted document custom hash function (#9996)

    * Custom hash function
    
    * Moving hash function to existing hashAlgorithm field
    
    * Docs for hash algorithm function + test to match example in docs
    
    * [preset/client] Adding changeset for custom hash function
    
    * Added configuration example to changeset
    nathan-ahn authored Jun 13, 2024
    Copy the full SHA
    99f449c View commit details
  3. feat: support discriminating null and undefined within useFragment (#…

    …10001)
    
    * feat: support discriminating null and undefined within useFragment
    
    * fix: changeset
    n1ru4l authored Jun 13, 2024
    Copy the full SHA
    1be6e65 View commit details
  4. feat(plugin/add): export config type (#9987)

    * feat(plugin/add): export config
    
    * Add changeset for @graphql-codegen/add
    
    * update changeset
    
    * Update polite-dancers-warn.md
    
    ---------
    
    Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
    taro-28 and n1ru4l authored Jun 13, 2024
    Copy the full SHA
    5501c62 View commit details
  5. Upcoming Release Changes (#10000)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    theguild-bot and github-actions[bot] authored Jun 13, 2024
    Copy the full SHA
    cac19e5 View commit details

Commits on Jun 17, 2024

  1. Add generated resolversMap to typescript-resolvers plugin meta (#10007)

    * Add generated resolversMap to ts-resolvers plugin meta
    
    * Add changeset
    eddeee888 authored Jun 17, 2024
    Copy the full SHA
    808ada5 View commit details

Commits on Jun 18, 2024

  1. Split ts-resolvers test into smaller chunks to make it easier to targ…

    …et (#10011)
    eddeee888 authored Jun 18, 2024
    Copy the full SHA
    9af9ce2 View commit details

Commits on Jun 24, 2024

  1. Only compute ClientSideBaseVisitor's fragmentsGraph once, at inst…

    …antiation time (#10019)
    
    * feat: Pre-compute ClientSideBaseVisitor's fragmentsGraph
    
    * chore: changeset
    
    * Update .changeset/rotten-eels-eat.md
    
    ---------
    
    Co-authored-by: Victor Magalhães <vhfmag@users.noreply.github.com>
    Co-authored-by: Laurin Quast <laurinquast@googlemail.com>
    3 people authored Jun 24, 2024
    Copy the full SHA
    14ce39e View commit details

Commits on Jun 28, 2024

  1. Upcoming Release Changes (#10010)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    theguild-bot and github-actions[bot] authored Jun 28, 2024
    Copy the full SHA
    61b6a94 View commit details
Showing with 1,796 additions and 553 deletions.
  1. +6 −1 README.md
  2. +23 −2 dev-test/gql-tag-operations-masking/gql/fragment-masking.ts
  3. +6 −6 dev-test/gql-tag-operations-masking/src/index.tsx
  4. +23 −2 dev-test/gql-tag-operations-urql/gql/fragment-masking.ts
  5. +23 −2 dev-test/gql-tag-operations/gql/fragment-masking.ts
  6. +23 −2 dev-test/gql-tag-operations/graphql/fragment-masking.ts
  7. +4 −4 dev-test/gql-tag-operations/src/index.ts
  8. +23 −2 examples/persisted-documents-string-mode/src/gql/fragment-masking.ts
  9. +23 −2 examples/persisted-documents/src/gql/fragment-masking.ts
  10. +4 −4 examples/programmatic-typescript/package.json
  11. +23 −2 examples/react/apollo-client-defer/src/gql/fragment-masking.ts
  12. +23 −2 examples/react/apollo-client-swc-plugin/src/gql/fragment-masking.ts
  13. +23 −2 examples/react/apollo-client/src/gql/fragment-masking.ts
  14. +23 −2 examples/react/http-executor/src/gql/fragment-masking.ts
  15. +23 −2 examples/react/nextjs-swr/gql/fragment-masking.ts
  16. +23 −2 examples/react/tanstack-react-query/src/gql/fragment-masking.ts
  17. +23 −2 examples/react/urql/src/gql/fragment-masking.ts
  18. +23 −2 examples/typescript-esm/src/gql/fragment-masking.ts
  19. +23 −2 examples/typescript-graphql-request/src/gql/fragment-masking.ts
  20. +2 −2 examples/typescript-resolvers/package.json
  21. +23 −2 examples/vite/vite-react-cts/src/gql/fragment-masking.ts
  22. +23 −2 examples/vite/vite-react-mts/src/gql/fragment-masking.ts
  23. +23 −2 examples/vite/vite-react-ts/src/gql/fragment-masking.ts
  24. +23 −2 examples/vue/apollo-composable/src/gql/fragment-masking.ts
  25. +23 −2 examples/vue/urql/src/gql/fragment-masking.ts
  26. +23 −2 examples/vue/villus/src/gql/fragment-masking.ts
  27. +23 −2 examples/yoga-tests/src/gql/fragment-masking.ts
  28. +10 −0 packages/plugins/other/add/CHANGELOG.md
  29. +1 −1 packages/plugins/other/add/package.json
  30. +2 −0 packages/plugins/other/add/src/index.ts
  31. +10 −0 packages/plugins/other/visitor-plugin-common/CHANGELOG.md
  32. +1 −1 packages/plugins/other/visitor-plugin-common/package.json
  33. +13 −4 packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts
  34. +4 −2 packages/plugins/other/visitor-plugin-common/src/client-side-base-visitor.ts
  35. +7 −0 packages/plugins/typescript/document-nodes/CHANGELOG.md
  36. +2 −2 packages/plugins/typescript/document-nodes/package.json
  37. +7 −0 packages/plugins/typescript/gql-tag-operations/CHANGELOG.md
  38. +2 −2 packages/plugins/typescript/gql-tag-operations/package.json
  39. +8 −0 packages/plugins/typescript/operations/CHANGELOG.md
  40. +3 −3 packages/plugins/typescript/operations/package.json
  41. +12 −0 packages/plugins/typescript/resolvers/CHANGELOG.md
  42. +3 −3 packages/plugins/typescript/resolvers/package.json
  43. +6 −1 packages/plugins/typescript/resolvers/src/index.ts
  44. 0 packages/plugins/typescript/resolvers/tests/{federation.spec.ts → ts-resolvers.federation.spec.ts}
  45. +169 −0 packages/plugins/typescript/resolvers/tests/ts-resolvers.interface.spec.ts
  46. +1 −1 packages/plugins/typescript/resolvers/tests/{mapping.spec.ts → ts-resolvers.mapping.spec.ts}
  47. +119 −0 packages/plugins/typescript/resolvers/tests/ts-resolvers.meta.spec.ts
  48. +0 −352 packages/plugins/typescript/resolvers/tests/ts-resolvers.spec.ts
  49. +97 −0 packages/plugins/typescript/resolvers/tests/ts-resolvers.union.spec.ts
  50. +7 −0 packages/plugins/typescript/typed-document-node/CHANGELOG.md
  51. +2 −2 packages/plugins/typescript/typed-document-node/package.json
  52. +7 −0 packages/plugins/typescript/typescript/CHANGELOG.md
  53. +2 −2 packages/plugins/typescript/typescript/package.json
  54. +65 −0 packages/presets/client/CHANGELOG.md
  55. +7 −7 packages/presets/client/package.json
  56. +50 −40 packages/presets/client/src/fragment-masking-plugin.ts
  57. +4 −2 packages/presets/client/src/index.ts
  58. +9 −3 packages/presets/client/src/persisted-documents.ts
  59. +337 −52 packages/presets/client/tests/client-preset.spec.ts
  60. +7 −0 packages/presets/graphql-modules/CHANGELOG.md
  61. +2 −2 packages/presets/graphql-modules/package.json
  62. +6 −6 website/package.json
  63. BIN website/public/assets/{docs → pages/docs/advanced/profiler}/codegen-profile-1.png
  64. BIN website/public/assets/{docs → pages/docs/advanced/profiler}/codegen-profile-2.png
  65. BIN website/public/assets/{docs → pages/docs/guides/react-vue}/graphqlsp.png
  66. BIN website/public/assets/pages/docs/guides/vanilla-typescript/graphql-lsp-autocomplete.png
  67. BIN website/public/assets/pages/docs/guides/vanilla-typescript/typesafe-execution-result.png
  68. BIN website/public/assets/pages/docs/guides/vanilla-typescript/typescript-typed-result.png
  69. +2 −2 website/src/pages/docs/advanced/profiler.mdx
  70. +2 −1 website/src/pages/docs/getting-started/index.mdx
  71. +1 −0 website/src/pages/docs/guides/_meta.ts
  72. +1 −1 website/src/pages/docs/guides/react-vue.mdx
  73. +255 −0 website/src/pages/docs/guides/vanilla-typescript.mdx
  74. +25 −0 website/src/pages/plugins/presets/preset-client.mdx
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
[![CodeGen](./logo.svg)](https://the-guild.dev/graphql/codegen)
<div>
<img src="./logo.svg" width="150px" alt="GraphQL Code Generator logo"/>
<a href="https://the-guild.dev">
<img align="right" src="https://the-guild-org.github.io/press-kit/full-dark-logo.svg" alt="Created by The Guild" style="width: 100px;align:right;"/>
</a>
</div>

[![npm version](https://badge.fury.io/js/%40graphql-codegen%2Fcli.svg)](https://badge.fury.io/js/%40graphql-codegen%2Fcli)

25 changes: 23 additions & 2 deletions dev-test/gql-tag-operations-masking/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -17,17 +17,37 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
): TType;
// return nullable if `fragmentType` is undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
): TType | undefined;
// return nullable if `fragmentType` is nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
): TType | null;
// return nullable if `fragmentType` is nullable or undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
): TType | null | undefined;
// return array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
): Array<TType>;
// return array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
): Array<TType> | null | undefined;
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
): ReadonlyArray<TType>;
// return array of nullable if `fragmentType` is array of nullable
// return readonly array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +56,11 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType:
| FragmentType<DocumentTypeDecoration<TType, any>>
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
| null
| undefined
): TType | ReadonlyArray<TType> | null | undefined {
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
return fragmentType as any;
}

12 changes: 6 additions & 6 deletions dev-test/gql-tag-operations-masking/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import React from 'react';
import { gql, FragmentType, useFragment } from '../gql';
import { graphql, FragmentType, useFragment } from '../gql';
import { useQuery } from 'urql';

const TweetFragment = gql(/* GraphQL */ `
const TweetFragment = graphql(/* GraphQL */ `
fragment TweetFragment on Tweet {
id
body
...TweetAuthorFragment
}
`);

const TweetAuthorFragment = gql(/* GraphQL */ `
const TweetAuthorFragment = graphql(/* GraphQL */ `
fragment TweetAuthorFragment on Tweet {
id
author {
@@ -21,7 +21,7 @@ const TweetAuthorFragment = gql(/* GraphQL */ `
}
`);

const TweetsFragment = gql(/* GraphQL */ `
const TweetsFragment = graphql(/* GraphQL */ `
fragment TweetsFragment on Query {
Tweets {
id
@@ -30,7 +30,7 @@ const TweetsFragment = gql(/* GraphQL */ `
}
`);

const TweetAppQuery = gql(/* GraphQL */ `
const TweetAppQuery = graphql(/* GraphQL */ `
query TweetAppQuery {
...TweetsFragment
}
@@ -53,7 +53,7 @@ const TweetAuthor = (props: { tweet: FragmentType<typeof TweetAuthorFragment> })
return <div>{tweet.author?.username}</div>;
};

const Tweets = (props: { tweets: FragmentType<typeof TweetsFragment> | undefined }) => {
const Tweets = (props: { tweets: FragmentType<typeof TweetsFragment> | null | undefined }) => {
const tweets = useFragment(TweetsFragment, props.tweets);

return <ul>{tweets?.Tweets?.map(tweet => <Tweet key={tweet.id} tweet={tweet} />) ?? null}</ul>;
25 changes: 23 additions & 2 deletions dev-test/gql-tag-operations-urql/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -17,17 +17,37 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
): TType;
// return nullable if `fragmentType` is undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
): TType | undefined;
// return nullable if `fragmentType` is nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
): TType | null;
// return nullable if `fragmentType` is nullable or undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
): TType | null | undefined;
// return array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
): Array<TType>;
// return array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
): Array<TType> | null | undefined;
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
): ReadonlyArray<TType>;
// return array of nullable if `fragmentType` is array of nullable
// return readonly array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +56,11 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType:
| FragmentType<DocumentTypeDecoration<TType, any>>
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
| null
| undefined
): TType | ReadonlyArray<TType> | null | undefined {
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
return fragmentType as any;
}

25 changes: 23 additions & 2 deletions dev-test/gql-tag-operations/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -17,17 +17,37 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
): TType;
// return nullable if `fragmentType` is undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
): TType | undefined;
// return nullable if `fragmentType` is nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
): TType | null;
// return nullable if `fragmentType` is nullable or undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
): TType | null | undefined;
// return array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
): Array<TType>;
// return array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
): Array<TType> | null | undefined;
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
): ReadonlyArray<TType>;
// return array of nullable if `fragmentType` is array of nullable
// return readonly array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +56,11 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType:
| FragmentType<DocumentTypeDecoration<TType, any>>
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
| null
| undefined
): TType | ReadonlyArray<TType> | null | undefined {
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
return fragmentType as any;
}

25 changes: 23 additions & 2 deletions dev-test/gql-tag-operations/graphql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -17,17 +17,37 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
): TType;
// return nullable if `fragmentType` is undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
): TType | undefined;
// return nullable if `fragmentType` is nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
): TType | null;
// return nullable if `fragmentType` is nullable or undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
): TType | null | undefined;
// return array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
): Array<TType>;
// return array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
): Array<TType> | null | undefined;
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
): ReadonlyArray<TType>;
// return array of nullable if `fragmentType` is array of nullable
// return readonly array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +56,11 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType:
| FragmentType<DocumentTypeDecoration<TType, any>>
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
| null
| undefined
): TType | ReadonlyArray<TType> | null | undefined {
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
return fragmentType as any;
}

8 changes: 4 additions & 4 deletions dev-test/gql-tag-operations/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
/* eslint-disable @typescript-eslint/no-unused-vars */

import { gql, DocumentType } from '../gql.js';
import { graphql, DocumentType } from '../gql/gql.js';

const FooQuery = gql(/* GraphQL */ `
const FooQuery = graphql(/* GraphQL */ `
query Foo {
Tweets {
id
}
}
`);

const LelFragment = gql(/* GraphQL */ `
const LelFragment = graphql(/* GraphQL */ `
fragment Lel on Tweet {
id
body
}
`);

const BarQuery = gql(/* GraphQL */ `
const BarQuery = graphql(/* GraphQL */ `
query Bar {
Tweets {
...Lel
Original file line number Diff line number Diff line change
@@ -16,17 +16,37 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
): TType;
// return nullable if `fragmentType` is undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
): TType | undefined;
// return nullable if `fragmentType` is nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
): TType | null;
// return nullable if `fragmentType` is nullable or undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
): TType | null | undefined;
// return array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
): Array<TType>;
// return array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
): Array<TType> | null | undefined;
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
): ReadonlyArray<TType>;
// return array of nullable if `fragmentType` is array of nullable
// return readonly array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -35,10 +55,11 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType:
| FragmentType<DocumentTypeDecoration<TType, any>>
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
| null
| undefined
): TType | ReadonlyArray<TType> | null | undefined {
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
return fragmentType as any;
}

25 changes: 23 additions & 2 deletions examples/persisted-documents/src/gql/fragment-masking.ts
Original file line number Diff line number Diff line change
@@ -17,17 +17,37 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>>
): TType;
// return nullable if `fragmentType` is undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | undefined
): TType | undefined;
// return nullable if `fragmentType` is nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null
): TType | null;
// return nullable if `fragmentType` is nullable or undefined
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
): TType | null | undefined;
// return array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
): Array<TType>;
// return array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
): Array<TType> | null | undefined;
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
): ReadonlyArray<TType>;
// return array of nullable if `fragmentType` is array of nullable
// return readonly array of nullable if `fragmentType` is array of nullable
export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +56,11 @@ export function useFragment<TType>(
_documentNode: DocumentTypeDecoration<TType, any>,
fragmentType:
| FragmentType<DocumentTypeDecoration<TType, any>>
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
| null
| undefined
): TType | ReadonlyArray<TType> | null | undefined {
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
return fragmentType as any;
}

Loading