-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[typescript-resolvers] Fix resolvers union types used in `ResolversPa…
…rentTypes` (#9206)
- Loading branch information
Showing
7 changed files
with
348 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
'@graphql-codegen/visitor-plugin-common': patch | ||
'@graphql-codegen/typescript-resolvers': patch | ||
--- | ||
|
||
Fix `ResolversUnionTypes` being used in `ResolversParentTypes` | ||
|
||
Previously, objects with mappable fields are converted to Omit format that references its own type group or `ResolversTypes` or `ResolversParentTypes` e.g. | ||
|
||
```ts | ||
export type ResolversTypes = { | ||
Book: ResolverTypeWrapper<BookMapper>; | ||
BookPayload: ResolversTypes["BookResult"] | ResolversTypes["StandardError"]; | ||
// Note: `result` on the next line references `ResolversTypes["Book"]` | ||
BookResult: ResolverTypeWrapper<Omit<BookResult, "result"> & { result?: Maybe<ResolversTypes["Book"]> }>; | ||
StandardError: ResolverTypeWrapper<StandardError>; | ||
}; | ||
|
||
export type ResolversParentTypes = { | ||
Book: BookMapper; | ||
BookPayload: ResolversParentTypes["BookResult"] | ResolversParentTypes["StandardError"]; | ||
// Note: `result` on the next line references `ResolversParentTypes["Book"]` | ||
BookResult: Omit<BookResult, "result"> & { result?: Maybe<ResolversParentTypes["Book"]> }; | ||
StandardError: StandardError; | ||
}; | ||
``` | ||
|
||
In https://github.com/dotansimha/graphql-code-generator/pull/9069, we extracted resolver union types to its own group: | ||
|
||
```ts | ||
export type ResolversUnionTypes = { | ||
// Note: `result` on the next line references `ResolversTypes["Book"]` which is only correct for the `ResolversTypes` case | ||
BookPayload: (Omit<BookResult, "result"> & { result?: Maybe<ResolversTypes["Book"]> }) | StandardError; | ||
}; | ||
|
||
export type ResolversTypes = { | ||
Book: ResolverTypeWrapper<BookMapper>; | ||
BookPayload: ResolverTypeWrapper<ResolversUnionTypes["BookPayload"]>; | ||
BookResult: ResolverTypeWrapper<Omit<BookResult, "result"> & { result?: Maybe<ResolversTypes["Book"]> }>; | ||
StandardError: ResolverTypeWrapper<StandardError>; | ||
}; | ||
|
||
export type ResolversParentTypes = { | ||
Book: BookMapper; | ||
BookPayload: ResolversUnionTypes["BookPayload"]; | ||
BookResult: Omit<BookResult, "result"> & { result?: Maybe<ResolversParentTypes["Book"]> }; | ||
StandardError: StandardError; | ||
}; | ||
``` | ||
|
||
This change creates an extra `ResolversUnionParentTypes` that is referenced by `ResolversParentTypes` to ensure backwards compatibility: | ||
|
||
```ts | ||
export type ResolversUnionTypes = { | ||
BookPayload: (Omit<BookResult, "result"> & { result?: Maybe<ResolversParentTypes["Book"]> }) | StandardError; | ||
}; | ||
|
||
// ... and the reference is changed in ResolversParentTypes: | ||
export type ResolversParentTypes = { | ||
// ... other fields | ||
BookPayload: ResolversUnionParentTypes["BookPayload"]; | ||
}; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.