Skip to content

Commit fc79b65

Browse files
authored
eslint fixes (#8871)
1 parent fbb0bda commit fc79b65

File tree

13 files changed

+40
-39
lines changed

13 files changed

+40
-39
lines changed

.changeset/eight-mugs-pay.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
'@graphql-codegen/core': patch
3+
'@graphql-codegen/visitor-plugin-common': patch
4+
'@graphql-codegen/typescript-resolvers': patch
5+
'@graphql-codegen/client-preset': patch
6+
'@graphql-codegen/gql-tag-operations-preset': patch
7+
'@graphql-codegen/graphql-modules-preset': patch
8+
'@graphql-codegen/plugin-helpers': patch
9+
---
10+
11+
eslint fixes

examples/typescript-esm/src/executeOperation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export function executeOperation<TResult, TVariables>(
2626
request.write(
2727
JSON.stringify({
2828
query: print(operation),
29-
variables: variables != null ? variables : undefined,
29+
variables: variables == null ? undefined : variables,
3030
})
3131
);
3232
request.end();

packages/graphql-codegen-core/src/codegen.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,7 @@ export async function codegen(options: Types.GenerateOptions): Promise<string> {
130130
const pluginPackage = options.pluginMap[name];
131131
const pluginConfig = plugin[name] || {};
132132

133-
const execConfig =
134-
typeof pluginConfig !== 'object'
135-
? pluginConfig
136-
: {
137-
...options.config,
138-
...pluginConfig,
139-
};
133+
const execConfig = typeof pluginConfig === 'object' ? { ...options.config, ...pluginConfig } : pluginConfig;
140134

141135
const result = await profiler.run(
142136
() =>

packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ export class BaseResolversVisitor<
952952
}
953953

954954
protected isMapperImported(groupedMappers: GroupedMappers, identifier: string, source: string): boolean {
955-
const exists = !groupedMappers[source] ? false : !!groupedMappers[source].find(m => m.identifier === identifier);
955+
const exists = groupedMappers[source] ? !!groupedMappers[source].find(m => m.identifier === identifier) : false;
956956
const existsFromEnums = !!Object.keys(this.config.enumValues)
957957
.map(key => this.config.enumValues[key])
958958
.find(o => o.sourceFile === source && o.typeIdentifier === identifier);

packages/plugins/other/visitor-plugin-common/src/base-types-visitor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ export class BaseTypesVisitor<
879879
? schemaEnumType.getValue(enumOption.name as any).value
880880
: undefined;
881881
let enumValue: string | number =
882-
typeof schemaEnumValue !== 'undefined' ? schemaEnumValue : (enumOption.name as any);
882+
typeof schemaEnumValue === 'undefined' ? (enumOption.name as any) : schemaEnumValue;
883883

884884
if (
885885
this.config.enumValues[typeName]?.mappedValues &&

packages/plugins/other/visitor-plugin-common/src/imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ export function clearExtension(path: string): string {
9696
}
9797

9898
export function fixLocalFilePath(path: string): string {
99-
return !path.startsWith('..') ? `./${path}` : path;
99+
return path.startsWith('..') ? path : `./${path}`;
100100
}

packages/plugins/other/visitor-plugin-common/src/selection-set-to-object.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,7 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
446446
for (const selectionNode of selectionNodes) {
447447
if ('kind' in selectionNode) {
448448
if (selectionNode.kind === 'Field') {
449-
if (!selectionNode.selectionSet) {
450-
if (selectionNode.alias) {
451-
primitiveAliasFields.set(selectionNode.alias.value, selectionNode);
452-
} else if (selectionNode.name.value === '__typename') {
453-
requireTypename = true;
454-
} else {
455-
primitiveFields.set(selectionNode.name.value, selectionNode);
456-
}
457-
} else {
449+
if (selectionNode.selectionSet) {
458450
let selectedField: GraphQLField<any, any, any> = null;
459451

460452
const fields = parentSchemaType.getFields();
@@ -470,21 +462,27 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
470462

471463
const fieldName = getFieldNodeNameValue(selectionNode);
472464
let linkFieldNode = linkFieldSelectionSets.get(fieldName);
473-
if (!linkFieldNode) {
474-
linkFieldNode = {
475-
selectedFieldType: selectedField.type,
476-
field: selectionNode,
477-
};
478-
} else {
465+
if (linkFieldNode) {
479466
linkFieldNode = {
480467
...linkFieldNode,
481468
field: {
482469
...linkFieldNode.field,
483470
selectionSet: mergeSelectionSets(linkFieldNode.field.selectionSet, selectionNode.selectionSet),
484471
},
485472
};
473+
} else {
474+
linkFieldNode = {
475+
selectedFieldType: selectedField.type,
476+
field: selectionNode,
477+
};
486478
}
487479
linkFieldSelectionSets.set(fieldName, linkFieldNode);
480+
} else if (selectionNode.alias) {
481+
primitiveAliasFields.set(selectionNode.alias.value, selectionNode);
482+
} else if (selectionNode.name.value === '__typename') {
483+
requireTypename = true;
484+
} else {
485+
primitiveFields.set(selectionNode.name.value, selectionNode);
488486
}
489487
} else if (selectionNode.kind === 'Directive') {
490488
if (['skip', 'include'].includes(selectionNode?.name?.value)) {

packages/plugins/other/visitor-plugin-common/src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function wrapWithSingleQuotes(value: string | number | NameNode, skipNume
5959

6060
if (
6161
typeof value === 'number' ||
62-
(typeof value === 'string' && !isNaN(parseInt(value)) && parseFloat(value).toString() === value)
62+
(typeof value === 'string' && !Number.isNaN(parseInt(value)) && parseFloat(value).toString() === value)
6363
) {
6464
return String(value);
6565
}
@@ -232,7 +232,7 @@ export class DeclarationBlock {
232232
}
233233

234234
return stripTrailingSpaces(
235-
(this._comment ? this._comment : '') +
235+
(this._comment || '') +
236236
result +
237237
(this._kind === 'interface' || this._kind === 'enum' || this._kind === 'namespace' || this._kind === 'function'
238238
? ''

packages/plugins/typescript/resolvers/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TCo
5555
} else {
5656
prepend.push(
5757
`${importType} { ${parsedMapper.import} ${
58-
parsedMapper.import !== resolverFnName ? `as ${resolverFnName} ` : ''
58+
parsedMapper.import === resolverFnName ? '' : `as ${resolverFnName} `
5959
}} from '${parsedMapper.source}';`
6060
);
6161
}
@@ -166,7 +166,7 @@ export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
166166
} else {
167167
prepend.push(
168168
`${importType} { ${parsedMapper.import} ${
169-
parsedMapper.import !== 'ResolverFn' ? 'as ResolverFn ' : ''
169+
parsedMapper.import === 'ResolverFn' ? '' : 'as ResolverFn '
170170
}} from '${parsedMapper.source}';`
171171
);
172172
}
@@ -268,7 +268,7 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
268268
}
269269
prepend.push(
270270
`import { ${parsedMapper.import} ${
271-
parsedMapper.import !== 'GraphQLResolveInfo' ? 'as GraphQLResolveInfo' : ''
271+
parsedMapper.import === 'GraphQLResolveInfo' ? '' : 'as GraphQLResolveInfo'
272272
} } from '${parsedMapper.source}';`
273273
);
274274
} else {

packages/presets/client/src/index.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import * as typescriptPlugin from '@graphql-codegen/typescript';
66
import * as typescriptOperationPlugin from '@graphql-codegen/typescript-operations';
77
import { ClientSideBaseVisitor } from '@graphql-codegen/visitor-plugin-common';
88
import { DocumentNode } from 'graphql';
9-
import babelOptimizerPlugin from './babel.js';
109
import * as fragmentMaskingPlugin from './fragment-masking-plugin.js';
1110
import { generateDocumentHash, normalizeAndPrintDocumentNode } from './persisted-documents.js';
1211
import { processSources } from './process-sources.js';
1312

13+
export { default as babelOptimizerPlugin } from './babel.js';
14+
1415
export type FragmentMaskingConfig = {
1516
/** @description Name of the function that should be used for unmasking a masked fragment property.
1617
* @default `'useFragment'`
@@ -322,8 +323,6 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
322323
},
323324
};
324325

325-
export { babelOptimizerPlugin };
326-
327326
type Deferred<T = void> = {
328327
resolve: (value: T) => void;
329328
reject: (value: unknown) => void;

0 commit comments

Comments
 (0)