Skip to content

Commit

Permalink
update typescript (#9004)
Browse files Browse the repository at this point in the history
* update typescript

* fix some stuff

---------

Co-authored-by: Dimitri POSTOLOV <dmytropostolov@gmail.com>
  • Loading branch information
n1ru4l and dimaMachina committed Feb 22, 2023
1 parent d4657f4 commit 70314b5
Show file tree
Hide file tree
Showing 15 changed files with 555 additions and 237 deletions.
2 changes: 1 addition & 1 deletion examples/react/apollo-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/react": "^18.0.15",
"@types/react-dom": "^18.0.10",
"react-scripts": "^5.0.1",
"typescript": "4.7.4",
"typescript": "4.9.5",
"serve": "14.2.0",
"cypress": "12.6.0",
"start-server-and-test": "1.15.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/babel-optimized/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"devDependencies": {
"@graphql-codegen/client-preset": "^2.0.0",
"@graphql-codegen/cli": "^3.0.0",
"typescript": "4.7.4"
"typescript": "4.9.5"
},
"scripts": {
"start": "node scripts/start.js",
Expand Down
2 changes: 1 addition & 1 deletion examples/react/graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.10",
"react-scripts": "^5.0.1",
"typescript": "4.7.4",
"typescript": "4.9.5",
"serve": "14.2.0",
"cypress": "12.6.0",
"start-server-and-test": "1.15.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/nextjs-swr/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
"@types/react-dom": "^18.0.10",
"eslint": "^8.21.0",
"eslint-config-next": "^13.0.0",
"typescript": "4.7.4"
"typescript": "4.9.5"
}
}
2 changes: 1 addition & 1 deletion examples/react/tanstack-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@types/node": "^18.11.18",
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.10",
"typescript": "4.7.4",
"typescript": "4.9.5",
"serve": "14.2.0",
"cypress": "12.6.0",
"start-server-and-test": "1.15.4"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/urql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"@types/react-dom": "^18.0.10",
"@graphql-codegen/cli": "^3.1.0",
"@graphql-codegen/client-preset": "^2.1.0",
"typescript": "4.7.4",
"typescript": "4.9.5",
"serve": "14.2.0",
"cypress": "12.6.0",
"start-server-and-test": "1.15.4"
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"ts-jest": "28.0.8",
"ts-node": "10.9.1",
"tslib": "2.5.0",
"typescript": "4.7.4"
"tsx": "3.12.3",
"typescript": "4.9.5"
},
"lint-staged": {
"packages/**/src/**/*.{ts,tsx}": [
Expand All @@ -81,6 +82,6 @@
"**/apollo-language-server/graphql": "^16.0.0",
"**/@types/graphql-upload/graphql": "^16.0.0",
"ts-node": "10.9.1",
"typescript": "4.7.4"
"typescript": "4.9.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface ParsedResolversConfig extends ParsedConfig {
[typeName: string]: ParsedMapper;
};
defaultMapper: ParsedMapper | null;
avoidOptionals: AvoidOptionalsConfig;
avoidOptionals: AvoidOptionalsConfig | boolean;
addUnderscoreToArgsType: boolean;
enumValues: ParsedEnumValuesMap;
resolverTypeWrapperSignature: string;
Expand Down Expand Up @@ -1198,7 +1198,10 @@ export class BaseResolversVisitor<

const resolverType = isSubscriptionType ? 'SubscriptionResolver' : directiveMappings[0] ?? 'Resolver';

const avoidOptionals = this.config.avoidOptionals?.resolvers ?? this.config.avoidOptionals === true;
const avoidOptionals =
typeof this.config.avoidOptionals === 'object'
? this.config.avoidOptionals?.resolvers
: this.config.avoidOptionals === true;
const signature: {
name: string;
modifier: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type SelectionSetProcessorConfig = {
scalars: ScalarsMap;
formatNamedField(name: string, type?: GraphQLOutputType | GraphQLNamedType | null, isConditional?: boolean): string;
wrapTypeWithModifiers(baseType: string, type: GraphQLOutputType | GraphQLNamedType): string;
avoidOptionals?: AvoidOptionalsConfig;
avoidOptionals?: AvoidOptionalsConfig | boolean;
};

export class BaseSelectionSetProcessor<Config extends SelectionSetProcessorConfig> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ export class TypeScriptSelectionSetProcessor extends BaseSelectionSetProcessor<S
const avoidOptional =
// TODO: check type and exec only if relevant
this.config.avoidOptionals === true ||
this.config.avoidOptionals.field ||
this.config.avoidOptionals.inputValue ||
this.config.avoidOptionals.object;
(typeof this.config.avoidOptionals === 'object' &&
(this.config.avoidOptionals.field ||
this.config.avoidOptionals.inputValue ||
this.config.avoidOptionals.object));

const transform = avoidOptional ? 'MakeMaybe' : 'MakeOptional';
resString = `${
this.config.namespacedImportName ? `${this.config.namespacedImportName}.` : ''
Expand Down
5 changes: 4 additions & 1 deletion packages/plugins/typescript/resolvers/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ export class TypeScriptResolversVisitor extends BaseResolversVisitor<
}

protected formatRootResolver(schemaTypeName: string, resolverType: string, declarationKind: DeclarationKind): string {
const avoidOptionals = this.config.avoidOptionals?.resolvers ?? this.config.avoidOptionals === true;
const avoidOptionals =
typeof this.config.avoidOptionals === 'object'
? this.config.avoidOptionals?.resolvers
: !!this.config.avoidOptionals === true;
return `${schemaTypeName}${avoidOptionals ? '' : '?'}: ${resolverType}${this.getPunctuation(declarationKind)}`;
}

Expand Down
2 changes: 1 addition & 1 deletion website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"start": "next start",
"build": "yarn generate-json-config && next build && next-sitemap --config next-sitemap.config.cjs && next export",
"dev": "next",
"generate-json-config": "node --loader ts-node/esm --experimental-specifier-resolution=node generate-config-json-schema.ts"
"generate-json-config": "tsx generate-config-json-schema.ts"
},
"devDependencies": {
"@theguild/algolia": "1.1.2",
Expand Down
Loading

0 comments on commit 70314b5

Please sign in to comment.