Skip to content

Commit 5e594ef

Browse files
feat(client-preset): preserving Array<T> or ReadonlyArray<T> in useFragment() 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 <[email protected]>
1 parent 39e6e80 commit 5e594ef

File tree

25 files changed

+382
-120
lines changed

25 files changed

+382
-120
lines changed

Diff for: .changeset/proud-cycles-design.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-codegen/client-preset': minor
3+
---
4+
5+
Preserving `Array<T>` or `ReadonlyArray<T>` in `useFragment()` return type.

Diff for: dev-test/gql-tag-operations-masking/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: dev-test/gql-tag-operations-urql/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: dev-test/gql-tag-operations/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: dev-test/gql-tag-operations/graphql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: examples/persisted-documents-string-mode/src/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,21 @@ export function useFragment<TType>(
2222
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2323
): TType | null | undefined;
2424
// return array of non-nullable if `fragmentType` is array of non-nullable
25+
export function useFragment<TType>(
26+
_documentNode: DocumentTypeDecoration<TType, any>,
27+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
28+
): Array<TType>;
29+
// return array of nullable if `fragmentType` is array of nullable
30+
export function useFragment<TType>(
31+
_documentNode: DocumentTypeDecoration<TType, any>,
32+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
33+
): Array<TType> | null | undefined;
34+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2535
export function useFragment<TType>(
2636
_documentNode: DocumentTypeDecoration<TType, any>,
2737
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2838
): ReadonlyArray<TType>;
29-
// return array of nullable if `fragmentType` is array of nullable
39+
// return readonly array of nullable if `fragmentType` is array of nullable
3040
export function useFragment<TType>(
3141
_documentNode: DocumentTypeDecoration<TType, any>,
3242
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -35,10 +45,11 @@ export function useFragment<TType>(
3545
_documentNode: DocumentTypeDecoration<TType, any>,
3646
fragmentType:
3747
| FragmentType<DocumentTypeDecoration<TType, any>>
48+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3849
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| null
4051
| undefined
41-
): TType | ReadonlyArray<TType> | null | undefined {
52+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4253
return fragmentType as any;
4354
}
4455

Diff for: examples/persisted-documents/src/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: examples/react/apollo-client-defer/src/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: examples/react/apollo-client-swc-plugin/src/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: examples/react/apollo-client/src/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

Diff for: examples/react/http-executor/src/gql/fragment-masking.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,21 @@ export function useFragment<TType>(
2323
fragmentType: FragmentType<DocumentTypeDecoration<TType, any>> | null | undefined
2424
): TType | null | undefined;
2525
// return array of non-nullable if `fragmentType` is array of non-nullable
26+
export function useFragment<TType>(
27+
_documentNode: DocumentTypeDecoration<TType, any>,
28+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>>
29+
): Array<TType>;
30+
// return array of nullable if `fragmentType` is array of nullable
31+
export function useFragment<TType>(
32+
_documentNode: DocumentTypeDecoration<TType, any>,
33+
fragmentType: Array<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
34+
): Array<TType> | null | undefined;
35+
// return readonly array of non-nullable if `fragmentType` is array of non-nullable
2636
export function useFragment<TType>(
2737
_documentNode: DocumentTypeDecoration<TType, any>,
2838
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
2939
): ReadonlyArray<TType>;
30-
// return array of nullable if `fragmentType` is array of nullable
40+
// return readonly array of nullable if `fragmentType` is array of nullable
3141
export function useFragment<TType>(
3242
_documentNode: DocumentTypeDecoration<TType, any>,
3343
fragmentType: ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>> | null | undefined
@@ -36,10 +46,11 @@ export function useFragment<TType>(
3646
_documentNode: DocumentTypeDecoration<TType, any>,
3747
fragmentType:
3848
| FragmentType<DocumentTypeDecoration<TType, any>>
49+
| Array<FragmentType<DocumentTypeDecoration<TType, any>>>
3950
| ReadonlyArray<FragmentType<DocumentTypeDecoration<TType, any>>>
4051
| null
4152
| undefined
42-
): TType | ReadonlyArray<TType> | null | undefined {
53+
): TType | Array<TType> | ReadonlyArray<TType> | null | undefined {
4354
return fragmentType as any;
4455
}
4556

0 commit comments

Comments
 (0)