-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TypedDocumentNode string alternative #9137
Changes from 8 commits
4a7b339
504367a
c7105db
13e48a9
02ed2b3
2d5a4e7
590b2e2
8e4e93f
7a5d42d
3892ba2
ef28588
961251f
dbd2053
8005ea3
2c6ee68
7b073f3
db98f71
346e1e5
4e732da
82b75f0
56170f6
e3120b3
8b5ad73
f960ccf
ed34330
0283daf
cfd9380
a97276b
2e99784
bdc1e7d
e954bea
0f155b4
5771e6d
5ce6b4f
a86f4bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-codegen/client-preset": patch | ||
--- | ||
dependencies updates: | ||
- Updated dependency [`@graphql-typed-document-node/core@3.2.0-alpha-20230309104331-975d9d2` ↗︎](https://www.npmjs.com/package/@graphql-typed-document-node/core/v/3.2.0) (from `3.1.2`, in `dependencies`) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,46 @@ | ||
import { ResultOf, TypedDocumentNode as DocumentNode } from '@graphql-typed-document-node/core'; | ||
import { ResultOf, DocumentTypeDecoration } from '@graphql-typed-document-node/core'; | ||
|
||
export type FragmentType<TDocumentType extends DocumentNode<any, any>> = TDocumentType extends DocumentNode< | ||
infer TType, | ||
any | ||
> | ||
? TType extends { ' $fragmentName'?: infer TKey } | ||
? TKey extends string | ||
? { ' $fragmentRefs'?: { [key in TKey]: TType } } | ||
export type FragmentType<TDocumentType extends DocumentTypeDecoration<any, any>> = | ||
TDocumentType extends DocumentTypeDecoration<infer TType, any> | ||
? TType extends { ' $fragmentName'?: infer TKey } | ||
? TKey extends string | ||
? { ' $fragmentRefs'?: { [key in TKey]: TType } } | ||
: never | ||
Comment on lines
-3
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so, people shouldn't use this type with anything else than our generated stuff. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed should be fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, as I think about it a bit more, this change kinda requires people to upgrade their typed document node version. 🤔 In graphql-yoga we treat e.g. So I think we should treat this the same here (minor change). Here the special case is that it is not listed as a peer dependency, but theoretically, it could be one, as people will need to install it, otherwise, their code won't compile with strict package manages like pnpm and yarn that do no hoisting. 🤔 Then, however, whether it should be a peer dependency or not also depends on the location where the code is generated. So the safest option would be to ship this as a breaking change. I am sure people will open issues if we don't... |
||
: never | ||
: never | ||
: never; | ||
: never; | ||
|
||
// return non-nullable if `fragmentType` is non-nullable | ||
export function useFragment<TType>( | ||
_documentNode: DocumentNode<TType, any>, | ||
fragmentType: FragmentType<DocumentNode<TType, any>> | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | ||
): TType; | ||
// return nullable if `fragmentType` is nullable | ||
export function useFragment<TType>( | ||
_documentNode: DocumentNode<TType, any>, | ||
fragmentType: FragmentType<DocumentNode<TType, any>> | null | undefined | ||
_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: DocumentNode<TType, any>, | ||
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | ||
): ReadonlyArray<TType>; | ||
// return array of nullable if `fragmentType` is array of nullable | ||
export function useFragment<TType>( | ||
_documentNode: DocumentNode<TType, any>, | ||
fragmentType: ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | null | undefined | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined | ||
): ReadonlyArray<TType> | null | undefined; | ||
export function useFragment<TType>( | ||
_documentNode: DocumentNode<TType, any>, | ||
_documentNode: DocumentTypeDecoration<TType, any>, | ||
fragmentType: | ||
| FragmentType<DocumentNode<TType, any>> | ||
| ReadonlyArray<FragmentType<DocumentNode<TType, any>>> | ||
| FragmentType<DocumentTypeDecoration<TType, any>> | ||
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | ||
| null | ||
| undefined | ||
): TType | ReadonlyArray<TType> | null | undefined { | ||
return fragmentType as any; | ||
} | ||
|
||
export function makeFragmentData<F extends DocumentNode, FT extends ResultOf<F>>( | ||
export function makeFragmentData<F extends DocumentTypeDecoration<any, any>, FT extends ResultOf<F>>( | ||
data: FT, | ||
_fragment: F | ||
): FragmentType<F> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: update with the latest version when a PR to
@graphql-typed-document-node/core
is accepted and released