-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[typescript-operations] Cut down avoidOptionals to only support object, inputValue and defaultValue (+ minor drive-by fixes)
#10579
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,6 @@ | ||
| --- | ||
| '@graphql-codegen/typescript-operations': major | ||
| '@graphql-codegen/client-preset': major | ||
| --- | ||
|
|
||
| BREAKING CHANGE: config.avoidOptionals now only supports object, inputValue, defaultValue |
33 changes: 33 additions & 0 deletions
33
packages/plugins/typescript/operations/src/config.avoidOptionals.ts
This file contains hidden or 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,33 @@ | ||
| /** | ||
| * This version of AvoidOptionalsConfig is a cut down version of the type of the same name in `@graphql-codegen/visitor-plugins-common` | ||
| * This version only deal with types available in client use cases. | ||
| */ | ||
| export interface AvoidOptionalsConfig { | ||
| object?: boolean; | ||
| inputValue?: boolean; | ||
| defaultValue?: boolean; | ||
| } | ||
| export type NormalizedAvoidOptionalsConfig = Required<AvoidOptionalsConfig>; | ||
|
|
||
| export const normalizeAvoidOptionals = ( | ||
| avoidOptionals?: boolean | AvoidOptionalsConfig | ||
| ): NormalizedAvoidOptionalsConfig => { | ||
| const defaultAvoidOptionals: NormalizedAvoidOptionalsConfig = { | ||
| object: false, | ||
| inputValue: false, | ||
| defaultValue: false, | ||
| }; | ||
|
|
||
| if (typeof avoidOptionals === 'boolean') { | ||
| return { | ||
| object: avoidOptionals, | ||
| inputValue: avoidOptionals, | ||
| defaultValue: avoidOptionals, | ||
| }; | ||
| } | ||
|
|
||
| return { | ||
| ...defaultAvoidOptionals, | ||
| ...avoidOptionals, | ||
| }; | ||
| }; |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,15 +1,13 @@ | ||
| import { | ||
| AvoidOptionalsConfig, | ||
| type ConvertSchemaEnumToDeclarationBlockString, | ||
| type EnumValuesMap, | ||
| RawDocumentsConfig, | ||
| } from '@graphql-codegen/visitor-plugin-common'; | ||
| import type { AvoidOptionalsConfig } from './config.avoidOptionals'; | ||
|
|
||
| /** | ||
| * @description This plugin generates TypeScript types based on your GraphQLSchema _and_ your GraphQL operations and fragments. | ||
| * It generates types for your GraphQL documents: Query, Mutation, Subscription and Fragment. | ||
| * | ||
| * Note: In most configurations, this plugin requires you to use `typescript as well, because it depends on its base types. | ||
|
Comment on lines
-11
to
-12
Collaborator
Author
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. Removing this makes me feel we are so close now! |
||
| */ | ||
| export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | ||
| /** | ||
|
|
@@ -28,7 +26,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * arrayInputCoercion: false | ||
| * }, | ||
|
|
@@ -55,7 +53,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * avoidOptionals: true | ||
| * }, | ||
|
|
@@ -74,13 +72,12 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * avoidOptionals: { | ||
| * field: true | ||
| * inputValue: true | ||
| * object: true | ||
| * defaultValue: true | ||
| * inputValue: true, | ||
| * object: true, | ||
| * defaultValue: true, | ||
| * } | ||
| * }, | ||
| * }, | ||
|
|
@@ -102,7 +99,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * immutableTypes: true | ||
| * }, | ||
|
|
@@ -125,7 +122,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript', 'typescript-operations'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * flattenGeneratedTypes: true | ||
| * }, | ||
|
|
@@ -149,7 +146,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript', 'typescript-operations'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * flattenGeneratedTypes: true, | ||
| * flattenGeneratedTypesIncludeFragments: true | ||
|
|
@@ -175,7 +172,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * noExport: true | ||
| * }, | ||
|
|
@@ -206,23 +203,19 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * const config: CodegenConfig = { | ||
| * // ... | ||
| * generates: { | ||
| * "./typings/api.ts": { | ||
| * "plugins": [ | ||
| * "typescript" | ||
| * ] | ||
| * }, | ||
| * "./": { | ||
| * "./": { | ||
| * "preset": "near-operation-file", | ||
| * "presetConfig": { | ||
| * "baseTypesPath": "./typings/api.ts", | ||
| * "extension": ".gql.d.ts" | ||
| * "baseTypesPath": "./typings/api.ts", | ||
| * "extension": ".gql.d.ts" | ||
| * }, | ||
| * "plugins": [ | ||
| * "@graphql-codegen/typescript-operations" | ||
| * "typescript-operations" | ||
| * ], | ||
| * "config": { | ||
| * "addOperationExport": true | ||
| * "addOperationExport": true | ||
| * } | ||
| * } | ||
| * } | ||
| * }; | ||
| * export default config; | ||
|
|
@@ -298,7 +291,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * allowUndefinedQueryVariables: true | ||
| * }, | ||
|
|
@@ -339,7 +332,7 @@ export interface TypeScriptDocumentsPluginConfig extends RawDocumentsConfig { | |
| * // ... | ||
| * generates: { | ||
| * 'path/to/file.ts': { | ||
| * plugins: ['typescript', 'typescript-operations'], | ||
| * plugins: ['typescript-operations'], | ||
| * config: { | ||
| * nullability: { | ||
| * errorHandlingClient: true | ||
|
|
||
2 changes: 1 addition & 1 deletion
2
packages/plugins/typescript/operations/src/ts-operation-variables-to-object.ts
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -12,8 +12,6 @@ import { | |
| getEnumsImports, | ||
| isNativeNamedType, | ||
| LoadedFragment, | ||
| normalizeAvoidOptionals, | ||
| NormalizedAvoidOptionalsConfig, | ||
| ParsedDocumentsConfig, | ||
| type ParsedEnumValuesMap, | ||
| parseEnumValues, | ||
|
|
@@ -46,8 +44,9 @@ import { | |
| visit, | ||
| visitWithTypeInfo, | ||
| } from 'graphql'; | ||
| import { TypeScriptDocumentsPluginConfig } from './config.js'; | ||
| import type { TypeScriptDocumentsPluginConfig } from './config.js'; | ||
| import { TypeScriptOperationVariablesToObject, SCALARS } from './ts-operation-variables-to-object.js'; | ||
| import { normalizeAvoidOptionals, NormalizedAvoidOptionalsConfig } from './config.avoidOptionals.js'; | ||
|
|
||
| export interface TypeScriptDocumentsParsedConfig extends ParsedDocumentsConfig { | ||
| arrayInputCoercion: boolean; | ||
|
|
@@ -175,9 +174,6 @@ export class TypeScriptDocumentsVisitor extends BaseDocumentsVisitor< | |
| this.setVariablesTransformer( | ||
| new TypeScriptOperationVariablesToObject( | ||
| { | ||
| // FIXME: this is the legacy avoidOptionals which was used to make Result fields non-optional. This use case is no longer valid. | ||
| // It's also being used for Variables so people could already be using it. | ||
| // Maybe it's better to deprecate and remove, to see what users think. | ||
|
Comment on lines
-178
to
-180
Collaborator
Author
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. Let's keep it for now to keep the scope of this project manageable |
||
| avoidOptionals: this.config.avoidOptionals, | ||
| immutableTypes: this.config.immutableTypes, | ||
| inputMaybeValue: this.config.inputMaybeValue, | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Similar to
examplefolders, the modules indev-test(which includes the example for Apollo tooling migration), should be ignored, otherwise it'd show up in Changeset interface