From fc79b65d4914fd25ae6bd5d58ebc7ded573a08a5 Mon Sep 17 00:00:00 2001 From: Dimitri POSTOLOV Date: Tue, 31 Jan 2023 00:16:20 +0100 Subject: [PATCH] eslint fixes (#8871) --- .changeset/eight-mugs-pay.md | 11 ++++++++ .../typescript-esm/src/executeOperation.ts | 2 +- packages/graphql-codegen-core/src/codegen.ts | 8 +----- .../src/base-resolvers-visitor.ts | 2 +- .../src/base-types-visitor.ts | 2 +- .../visitor-plugin-common/src/imports.ts | 2 +- .../src/selection-set-to-object.ts | 28 +++++++++---------- .../other/visitor-plugin-common/src/utils.ts | 4 +-- .../plugins/typescript/resolvers/src/index.ts | 6 ++-- packages/presets/client/src/index.ts | 5 ++-- .../presets/gql-tag-operations/src/index.ts | 5 ++-- .../presets/graphql-modules/src/builder.ts | 2 +- .../utils/plugins-helpers/src/federation.ts | 2 +- 13 files changed, 40 insertions(+), 39 deletions(-) create mode 100644 .changeset/eight-mugs-pay.md diff --git a/.changeset/eight-mugs-pay.md b/.changeset/eight-mugs-pay.md new file mode 100644 index 00000000000..defffab514d --- /dev/null +++ b/.changeset/eight-mugs-pay.md @@ -0,0 +1,11 @@ +--- +'@graphql-codegen/core': patch +'@graphql-codegen/visitor-plugin-common': patch +'@graphql-codegen/typescript-resolvers': patch +'@graphql-codegen/client-preset': patch +'@graphql-codegen/gql-tag-operations-preset': patch +'@graphql-codegen/graphql-modules-preset': patch +'@graphql-codegen/plugin-helpers': patch +--- + +eslint fixes diff --git a/examples/typescript-esm/src/executeOperation.ts b/examples/typescript-esm/src/executeOperation.ts index cc505b48dc1..6ee88075a09 100644 --- a/examples/typescript-esm/src/executeOperation.ts +++ b/examples/typescript-esm/src/executeOperation.ts @@ -26,7 +26,7 @@ export function executeOperation( request.write( JSON.stringify({ query: print(operation), - variables: variables != null ? variables : undefined, + variables: variables == null ? undefined : variables, }) ); request.end(); diff --git a/packages/graphql-codegen-core/src/codegen.ts b/packages/graphql-codegen-core/src/codegen.ts index e7a86967d34..b8d8d64ae87 100644 --- a/packages/graphql-codegen-core/src/codegen.ts +++ b/packages/graphql-codegen-core/src/codegen.ts @@ -130,13 +130,7 @@ export async function codegen(options: Types.GenerateOptions): Promise { const pluginPackage = options.pluginMap[name]; const pluginConfig = plugin[name] || {}; - const execConfig = - typeof pluginConfig !== 'object' - ? pluginConfig - : { - ...options.config, - ...pluginConfig, - }; + const execConfig = typeof pluginConfig === 'object' ? { ...options.config, ...pluginConfig } : pluginConfig; const result = await profiler.run( () => diff --git a/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts b/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts index 5544cbfca04..d5f4615bd49 100644 --- a/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts +++ b/packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts @@ -952,7 +952,7 @@ export class BaseResolversVisitor< } protected isMapperImported(groupedMappers: GroupedMappers, identifier: string, source: string): boolean { - const exists = !groupedMappers[source] ? false : !!groupedMappers[source].find(m => m.identifier === identifier); + const exists = groupedMappers[source] ? !!groupedMappers[source].find(m => m.identifier === identifier) : false; const existsFromEnums = !!Object.keys(this.config.enumValues) .map(key => this.config.enumValues[key]) .find(o => o.sourceFile === source && o.typeIdentifier === identifier); diff --git a/packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts b/packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts index 3b5839b34a6..8e77e89fd2b 100644 --- a/packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts +++ b/packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts @@ -879,7 +879,7 @@ export class BaseTypesVisitor< ? schemaEnumType.getValue(enumOption.name as any).value : undefined; let enumValue: string | number = - typeof schemaEnumValue !== 'undefined' ? schemaEnumValue : (enumOption.name as any); + typeof schemaEnumValue === 'undefined' ? (enumOption.name as any) : schemaEnumValue; if ( this.config.enumValues[typeName]?.mappedValues && diff --git a/packages/plugins/other/visitor-plugin-common/src/imports.ts b/packages/plugins/other/visitor-plugin-common/src/imports.ts index 7af57a4c791..b9e4cbde6ba 100644 --- a/packages/plugins/other/visitor-plugin-common/src/imports.ts +++ b/packages/plugins/other/visitor-plugin-common/src/imports.ts @@ -96,5 +96,5 @@ export function clearExtension(path: string): string { } export function fixLocalFilePath(path: string): string { - return !path.startsWith('..') ? `./${path}` : path; + return path.startsWith('..') ? path : `./${path}`; } diff --git a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts index d3059f2e52c..431eb16c5c9 100644 --- a/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts +++ b/packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts @@ -446,15 +446,7 @@ export class SelectionSetToObject = null; const fields = parentSchemaType.getFields(); @@ -470,12 +462,7 @@ export class SelectionSetToObject = { } else { prepend.push( `${importType} { ${parsedMapper.import} ${ - parsedMapper.import !== 'ResolverFn' ? 'as ResolverFn ' : '' + parsedMapper.import === 'ResolverFn' ? '' : 'as ResolverFn ' }} from '${parsedMapper.source}';` ); } @@ -268,7 +268,7 @@ export type DirectiveResolverFn = { }, }; -export { babelOptimizerPlugin }; - type Deferred = { resolve: (value: T) => void; reject: (value: unknown) => void; diff --git a/packages/presets/gql-tag-operations/src/index.ts b/packages/presets/gql-tag-operations/src/index.ts index d1b9e78f26e..aba70beef8f 100644 --- a/packages/presets/gql-tag-operations/src/index.ts +++ b/packages/presets/gql-tag-operations/src/index.ts @@ -5,10 +5,11 @@ import * as typedDocumentNodePlugin from '@graphql-codegen/typed-document-node'; import * as typescriptPlugin from '@graphql-codegen/typescript'; import * as typescriptOperationPlugin from '@graphql-codegen/typescript-operations'; import { ClientSideBaseVisitor } from '@graphql-codegen/visitor-plugin-common'; -import babelPlugin from './babel.js'; import * as fragmentMaskingPlugin from './fragment-masking-plugin.js'; import { processSources } from './process-sources.js'; +export { default as babelPlugin } from './babel.js'; + export type FragmentMaskingConfig = { /** * @description The module name from which a augmented module should be imported from. @@ -258,5 +259,3 @@ export const preset: Types.OutputPreset = { ]; }, }; - -export { babelPlugin }; diff --git a/packages/presets/graphql-modules/src/builder.ts b/packages/presets/graphql-modules/src/builder.ts index 317cad52369..a6fcf156022 100644 --- a/packages/presets/graphql-modules/src/builder.ts +++ b/packages/presets/graphql-modules/src/builder.ts @@ -151,7 +151,7 @@ export function buildModule( '\n}'; } - return [...(!shouldDeclare ? imports : []), content].filter(Boolean).join('\n'); + return [...(shouldDeclare ? [] : imports), content].filter(Boolean).join('\n'); /** * A dictionary of fields to pick from an object diff --git a/packages/utils/plugins-helpers/src/federation.ts b/packages/utils/plugins-helpers/src/federation.ts index 00f69b13cb3..5dbba45c927 100644 --- a/packages/utils/plugins-helpers/src/federation.ts +++ b/packages/utils/plugins-helpers/src/federation.ts @@ -234,7 +234,7 @@ export class ApolloFederation { Field(node) { return { name: node.name.value, - selection: node.selectionSet ? node.selectionSet : true, + selection: node.selectionSet || true, } as SelectionSetField; }, Document(node) {