-
Couldn't load subscription status.
- Fork 1.4k
@skip, @include respect avoidOptionals #5104
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
@skip, @include respect avoidOptionals #5104
Conversation
🦋 Changeset detectedLatest commit: 701d609 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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.
Reviewed 10 of 10 files at r1, 42 of 42 files at r2.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @gilgardosh)
packages/plugins/typescript/operations/src/ts-selection-set-processor.ts, line 39 at r2 (raw file):
if (hasConditionals) { if (
nit:
const avoidOptional = (
// TODO: check type and exec only if relevant
this.config.avoidOptionals === true ||
this.config.avoidOptionals.field ||
this.config.avoidOptionals.inputValue ||
this.config.avoidOptionals.object
)
const transform = avoidOptional ? "MakeMaybe" : "MakeOptional"
resString = `${
this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''
}${transform}<${resString}, ${conditilnalsList.map(field => `'${field}'`).join(' | ')}>`;packages/plugins/typescript/operations/tests/ts-documents.spec.ts, line 4770 at r2 (raw file):
}); it('On avoidOptionals:true, fileds with @skip, @include should make container resolve into MakeMaybe type', async () => {
nit: fields
|
@gilgardosh ready for a review? (btw, changeset is missing) |
|
@dotansimha Ready now |
| export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] }; | ||
| export type MakeOptional<T, K extends keyof T> = Omit<T, K> & | ||
| { [SubKey in keyof Pick<T, K>]?: Maybe<Pick<T, K>[SubKey]> }; | ||
| export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> }; |
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.
I think we can experiment with TS generics inference here.
Something like :
export type MakeMaybe<T, K extends keyof T, AndOptional extends boolean> =
AndOptional extends true ?
Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> } :
Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> ;then, we can generate MakeMaybe<A, B, true> for example.
What do you think?
Related: #5099