Skip to content

Commit

Permalink
eslint fixes (#8871)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina committed Jan 30, 2023
1 parent fbb0bda commit fc79b65
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 39 deletions.
11 changes: 11 additions & 0 deletions .changeset/eight-mugs-pay.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion examples/typescript-esm/src/executeOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function executeOperation<TResult, TVariables>(
request.write(
JSON.stringify({
query: print(operation),
variables: variables != null ? variables : undefined,
variables: variables == null ? undefined : variables,
})
);
request.end();
Expand Down
8 changes: 1 addition & 7 deletions packages/graphql-codegen-core/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,7 @@ export async function codegen(options: Types.GenerateOptions): Promise<string> {
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(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -446,15 +446,7 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
for (const selectionNode of selectionNodes) {
if ('kind' in selectionNode) {
if (selectionNode.kind === 'Field') {
if (!selectionNode.selectionSet) {
if (selectionNode.alias) {
primitiveAliasFields.set(selectionNode.alias.value, selectionNode);
} else if (selectionNode.name.value === '__typename') {
requireTypename = true;
} else {
primitiveFields.set(selectionNode.name.value, selectionNode);
}
} else {
if (selectionNode.selectionSet) {
let selectedField: GraphQLField<any, any, any> = null;

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

const fieldName = getFieldNodeNameValue(selectionNode);
let linkFieldNode = linkFieldSelectionSets.get(fieldName);
if (!linkFieldNode) {
linkFieldNode = {
selectedFieldType: selectedField.type,
field: selectionNode,
};
} else {
if (linkFieldNode) {
linkFieldNode = {
...linkFieldNode,
field: {
...linkFieldNode.field,
selectionSet: mergeSelectionSets(linkFieldNode.field.selectionSet, selectionNode.selectionSet),
},
};
} else {
linkFieldNode = {
selectedFieldType: selectedField.type,
field: selectionNode,
};
}
linkFieldSelectionSets.set(fieldName, linkFieldNode);
} else if (selectionNode.alias) {
primitiveAliasFields.set(selectionNode.alias.value, selectionNode);
} else if (selectionNode.name.value === '__typename') {
requireTypename = true;
} else {
primitiveFields.set(selectionNode.name.value, selectionNode);
}
} else if (selectionNode.kind === 'Directive') {
if (['skip', 'include'].includes(selectionNode?.name?.value)) {
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/other/visitor-plugin-common/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function wrapWithSingleQuotes(value: string | number | NameNode, skipNume

if (
typeof value === 'number' ||
(typeof value === 'string' && !isNaN(parseInt(value)) && parseFloat(value).toString() === value)
(typeof value === 'string' && !Number.isNaN(parseInt(value)) && parseFloat(value).toString() === value)
) {
return String(value);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ export class DeclarationBlock {
}

return stripTrailingSpaces(
(this._comment ? this._comment : '') +
(this._comment || '') +
result +
(this._kind === 'interface' || this._kind === 'enum' || this._kind === 'namespace' || this._kind === 'function'
? ''
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/typescript/resolvers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export type Resolver${capitalizedDirectiveName}WithResolve<TResult, TParent, TCo
} else {
prepend.push(
`${importType} { ${parsedMapper.import} ${
parsedMapper.import !== resolverFnName ? `as ${resolverFnName} ` : ''
parsedMapper.import === resolverFnName ? '' : `as ${resolverFnName} `
}} from '${parsedMapper.source}';`
);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
} else {
prepend.push(
`${importType} { ${parsedMapper.import} ${
parsedMapper.import !== 'ResolverFn' ? 'as ResolverFn ' : ''
parsedMapper.import === 'ResolverFn' ? '' : 'as ResolverFn '
}} from '${parsedMapper.source}';`
);
}
Expand Down Expand Up @@ -268,7 +268,7 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
}
prepend.push(
`import { ${parsedMapper.import} ${
parsedMapper.import !== 'GraphQLResolveInfo' ? 'as GraphQLResolveInfo' : ''
parsedMapper.import === 'GraphQLResolveInfo' ? '' : 'as GraphQLResolveInfo'
} } from '${parsedMapper.source}';`
);
} else {
Expand Down
5 changes: 2 additions & 3 deletions packages/presets/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import * as typescriptPlugin from '@graphql-codegen/typescript';
import * as typescriptOperationPlugin from '@graphql-codegen/typescript-operations';
import { ClientSideBaseVisitor } from '@graphql-codegen/visitor-plugin-common';
import { DocumentNode } from 'graphql';
import babelOptimizerPlugin from './babel.js';
import * as fragmentMaskingPlugin from './fragment-masking-plugin.js';
import { generateDocumentHash, normalizeAndPrintDocumentNode } from './persisted-documents.js';
import { processSources } from './process-sources.js';

export { default as babelOptimizerPlugin } from './babel.js';

export type FragmentMaskingConfig = {
/** @description Name of the function that should be used for unmasking a masked fragment property.
* @default `'useFragment'`
Expand Down Expand Up @@ -322,8 +323,6 @@ export const preset: Types.OutputPreset<ClientPresetConfig> = {
},
};

export { babelOptimizerPlugin };

type Deferred<T = void> = {
resolve: (value: T) => void;
reject: (value: unknown) => void;
Expand Down
5 changes: 2 additions & 3 deletions packages/presets/gql-tag-operations/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -258,5 +259,3 @@ export const preset: Types.OutputPreset<GqlTagConfig> = {
];
},
};

export { babelPlugin };
2 changes: 1 addition & 1 deletion packages/presets/graphql-modules/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/plugins-helpers/src/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit fc79b65

Please sign in to comment.