Skip to content

Commit

Permalink
commit (#8801)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored Jan 7, 2023
1 parent 92fb925 commit 7e3445e
Show file tree
Hide file tree
Showing 15 changed files with 69 additions and 211 deletions.
1 change: 0 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ module.exports = {
'unicorn/filename-case': 'off',
'import/extensions': 'off',
'import/no-default-export': 'off',
'logical-assignment-operators': 'off',
// todo: enable in v3
'unicorn/prefer-node-protocol': 'off',
},
Expand Down
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@
"@graphql-typed-document-node/core": "3.1.1",
"@reduxjs/toolkit": "1.8.5",
"@tanstack/react-query": "4.2.3",
"@theguild/eslint-config": "0.4.2",
"@theguild/eslint-config": "0.5.0",
"@theguild/prettier-config": "0.1.1",
"@types/common-tags": "1.8.1",
"@types/jest": "28.1.8",
"@types/mkdirp": "1.0.2",
"@types/node": "18.11.18",
"@types/react": "18.0.18",
"@types/webpack-env": "1.18.0",
"@typescript-eslint/eslint-plugin": "5.36.2",
"@typescript-eslint/parser": "5.36.2",
"@urql/exchange-graphcache": "5.0.5",
"@vue/apollo-composable": "4.0.0-alpha.19",
"@vue/composition-api": "1.7.0",
Expand All @@ -59,13 +57,7 @@
"bob-the-bundler": "4.0.0",
"chalk": "4.1.2",
"dotenv": "16.0.2",
"eslint": "8.23.0",
"eslint-config-prettier": "8.5.0",
"eslint-config-standard": "17.0.0",
"eslint-plugin-import": "2.26.0",
"eslint-plugin-n": "15.2.5",
"eslint-plugin-promise": "6.0.1",
"eslint-plugin-react-hooks": "4.6.0",
"eslint": "8.31.0",
"flow-bin": "0.186.0",
"flow-parser": "0.186.0",
"fs-extra": "10.1.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/graphql-codegen-cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ export async function loadCodegenConfig({
packageProp,
loaders: customLoaders,
}: LoadCodegenConfigOptions): Promise<LoadCodegenConfigResult> {
configFilePath = configFilePath || process.cwd();
moduleName = moduleName || 'codegen';
packageProp = packageProp || moduleName;
configFilePath ||= process.cwd();
moduleName ||= 'codegen';
packageProp ||= moduleName;
const cosmi = cosmiconfig(moduleName, {
searchPlaces: generateSearchPlaces(moduleName).concat(additionalSearchPlaces || []),
packageProp,
Expand Down
8 changes: 2 additions & 6 deletions packages/graphql-codegen-cli/src/init/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,12 @@ export async function writePackage(answers: Answers, configLocation: string) {
const pkg = JSON.parse(pkgContent);
const { indent } = detectIndent(pkgContent);

if (!pkg.scripts) {
pkg.scripts = {};
}
pkg.scripts ||= {};

pkg.scripts[answers.script] = `graphql-codegen --config ${configLocation}`;

// plugin
if (!pkg.devDependencies) {
pkg.devDependencies = {};
}
pkg.devDependencies ||= {};

await Promise.all(
(answers.plugins || []).map(async plugin => {
Expand Down
14 changes: 5 additions & 9 deletions packages/graphql-codegen-core/src/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,11 @@ function validateDuplicateDocuments(files: Types.DocumentFile[]) {
deduplicatedDefinitions: Set<DefinitionNode>
) {
if (typeof node.name !== 'undefined') {
if (!definitionMap[node.kind]) {
definitionMap[node.kind] = {};
}
if (!definitionMap[node.kind][node.name.value]) {
definitionMap[node.kind][node.name.value] = {
paths: new Set(),
contents: new Set(),
};
}
definitionMap[node.kind] ||= {};
definitionMap[node.kind][node.name.value] ||= {
paths: new Set(),
contents: new Set(),
};

const definitionKindMap = definitionMap[node.kind];

Expand Down
4 changes: 1 addition & 3 deletions packages/graphql-codegen-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ export function hasFederationSpec(schemaOrAST: GraphQLSchema | DocumentNode) {
}

export function extractHashFromSchema(schema: GraphQLSchema): string | null {
if (!schema.extensions) {
schema.extensions = {};
}
schema.extensions ||= {};

return (schema.extensions['hash'] as string) ?? null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,7 @@ export class BaseResolversVisitor<

const addMapper = (source: string, identifier: string, asDefault: boolean) => {
if (!this.isMapperImported(groupedMappers, identifier, source)) {
if (!groupedMappers[source]) {
groupedMappers[source] = [];
}
groupedMappers[source] ||= [];

groupedMappers[source].push({ identifier, asDefault });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export function parseEnumValues({
const enumType = schema.getType(enumTypeName) as GraphQLEnumType;
for (const { name, value } of enumType.getValues()) {
if (value !== name) {
mapOrStr[enumTypeName] = mapOrStr[enumTypeName] || {};
mapOrStr[enumTypeName] ||= {};
if (typeof mapOrStr[enumTypeName] !== 'string' && !mapOrStr[enumTypeName][name]) {
mapOrStr[enumTypeName][name] = typeof value === 'string' ? escapeString(value) : value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,7 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD
possibleTypesForFragment.length === 1 ? null : possibleType.name
);

if (!selectionNodesByTypeName[possibleType.name]) {
selectionNodesByTypeName[possibleType.name] = [];
}
selectionNodesByTypeName[possibleType.name] ||= [];

selectionNodesByTypeName[possibleType.name].push({
fragmentName: spread.name.value,
Expand Down Expand Up @@ -326,9 +324,7 @@ export class SelectionSetToObject<Config extends ParsedDocumentsConfig = ParsedD

const selectionNodes = selectionNodesByTypeName.get(typeName) || [];

if (!prev[typeName]) {
prev[typeName] = [];
}
prev[typeName] ||= [];

const { fields } = this.buildSelectionSet(schemaType, selectionNodes);
const transformedSet = this.selectionSetStringFromFields(fields);
Expand Down
8 changes: 2 additions & 6 deletions packages/presets/graphql-modules/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,7 @@ export function buildModule(
const name = node.name.value;

if (node.fields) {
if (!picksObj[name]) {
picksObj[name] = [];
}
picksObj[name] ||= [];

node.fields.forEach(field => {
picksObj[name].push(field.name.value);
Expand All @@ -392,9 +390,7 @@ export function buildModule(
const name = node.name.value;

if (node.values) {
if (!picks.enums[name]) {
picks.enums[name] = [];
}
picks.enums[name] ||= [];

node.values.forEach(field => {
picks.enums[name].push(field.name.value);
Expand Down
4 changes: 1 addition & 3 deletions packages/presets/graphql-modules/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ export function groupSourcesByModule(sources: Source[], basePath: string): Recor
// PERF: we could guess the module by matching source.location with a list of already resolved paths
const mod = extractModuleDirectory(source.location, basePath);

if (!grouped[mod]) {
grouped[mod] = [];
}
grouped[mod] ||= [];

grouped[mod].push(source);
}
Expand Down
4 changes: 1 addition & 3 deletions packages/utils/plugins-helpers/src/federation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,7 @@ export class ApolloFederation {
.reduce((prev, curr) => [...prev, ...curr], []);
const ofType = getBaseType(field.type);

if (!providesMap[ofType.name]) {
providesMap[ofType.name] = [];
}
providesMap[ofType.name] ||= [];

providesMap[ofType.name].push(...provides);
});
Expand Down
4 changes: 2 additions & 2 deletions packages/utils/plugins-helpers/src/oldVisit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export function oldVisit(
): any {
if (typeof enterVisitors === 'object') {
for (const key in enterVisitors) {
newVisitor[key] = newVisitor[key] || {};
newVisitor[key] ||= {};
newVisitor[key].enter = enterVisitors[key];
}
}
if (typeof leaveVisitors === 'object') {
for (const key in leaveVisitors) {
newVisitor[key] = newVisitor[key] || {};
newVisitor[key] ||= {};
newVisitor[key].leave = leaveVisitors[key];
}
}
Expand Down
1 change: 1 addition & 0 deletions scripts/match-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const pkg = require(pkgPath);

const version = argv[2];

// eslint-disable-next-line logical-assignment-operators -- can be removed after drop support of Node.js 12
pkg.resolutions = pkg.resolutions || {};
if (pkg.resolutions.graphql.startsWith(version)) {
// eslint-disable-next-line no-console
Expand Down
Loading

0 comments on commit 7e3445e

Please sign in to comment.