Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
alexownejazayeri committed May 13, 2024
2 parents ded1c93 + 9665a05 commit ec153e1
Show file tree
Hide file tree
Showing 38 changed files with 1,467 additions and 1,412 deletions.
6 changes: 6 additions & 0 deletions .changeset/gentle-ladybugs-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@graphql-codegen/visitor-plugin-common': patch
'@graphql-codegen/typescript-resolvers': patch
---

Add \_ prefix to generated `RefType` in `ResolversInterfaceTypes` and `ResolversUnionTypes` as it is sometimes unused
10 changes: 9 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ module.exports = {
'@typescript-eslint/no-unused-vars': 'off',
},
},
{
files: ['packages/**/*.{,c,m}ts{,x}'],
parserOptions: {
project: ['./tsconfig.json'],
},
},
],
ignorePatterns: [
'dev-test',
'website',
'examples/**/gql/**',
'examples/**',
'**/tests/test-files/**',
'**/tests/test-documents/**',
'**/react-app-env.d.ts',
'packages/presets/swc-plugin/tests/fixtures/simple-uppercase-operation-name.js',
'packages/presets/swc-plugin/tests/fixtures/simple-uppercase-operation-name.other-dir.js',
Expand Down
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ jobs:
needs:
- lint
- prettier-check
- dev-tests
- esm
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion dev-test/modules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
) => TResult | Promise<TResult>;

/** Mapping of union types */
export type ResolversUnionTypes<RefType extends Record<string, unknown>> = {
export type ResolversUnionTypes<_RefType extends Record<string, unknown>> = {
PaymentOption: CreditCard | Paypal;
};

Expand Down
10 changes: 5 additions & 5 deletions examples/persisted-documents-string-mode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"graphql-yoga": "4.0.4",
"@graphql-yoga/plugin-persisted-operations": "2.0.4"
"graphql-yoga": "5.3.1",
"@graphql-yoga/plugin-persisted-operations": "3.3.1"
},
"devDependencies": {
"@graphql-typed-document-node/core": "3.2.0",
"jest": "28.1.3",
"babel-jest": "29.6.4",
"@graphql-codegen/cli": "5.0.2",
"@babel/core": "7.23.9",
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "7.23.3"
"@babel/core": "7.24.5",
"@babel/preset-env": "7.24.5",
"@babel/preset-typescript": "7.24.1"
},
"scripts": {
"test": "jest",
Expand Down
10 changes: 5 additions & 5 deletions examples/persisted-documents/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"graphql-yoga": "4.0.4",
"@graphql-yoga/plugin-persisted-operations": "2.0.4"
"graphql-yoga": "5.3.1",
"@graphql-yoga/plugin-persisted-operations": "3.3.1"
},
"devDependencies": {
"@graphql-typed-document-node/core": "3.2.0",
"jest": "28.1.3",
"babel-jest": "29.6.4",
"@graphql-codegen/cli": "5.0.2",
"@babel/core": "7.23.9",
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "7.23.3"
"@babel/core": "7.24.5",
"@babel/preset-env": "7.24.5",
"@babel/preset-typescript": "7.24.1"
},
"scripts": {
"test": "jest",
Expand Down
2 changes: 1 addition & 1 deletion examples/programmatic-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"prettier": "2.8.8"
},
"devDependencies": {
"@types/node": "18.19.21",
"@types/node": "18.19.33",
"tsup": "7.2.0"
}
}
20 changes: 10 additions & 10 deletions examples/programmatic-typescript/src/gql.generated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> =
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
ID: string;
String: string;
Boolean: boolean;
Int: number;
Float: number;
ID: { input: string; output: string };
String: { input: string; output: string };
Boolean: { input: boolean; output: boolean };
Int: { input: number; output: number };
Float: { input: number; output: number };
};

export type Query = {
__typename?: 'Query';
hello: Scalars['String'];
hello: Scalars['String']['output'];
};

export type ResolverTypeWrapper<T> = Promise<T> | T;
Expand Down Expand Up @@ -94,15 +94,15 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
/** Mapping between all available schema types and the resolvers types */
export type ResolversTypes = {
Query: ResolverTypeWrapper<{}>;
String: ResolverTypeWrapper<Scalars['String']>;
Boolean: ResolverTypeWrapper<Scalars['Boolean']>;
String: ResolverTypeWrapper<Scalars['String']['output']>;
Boolean: ResolverTypeWrapper<Scalars['Boolean']['output']>;
};

/** Mapping between all available schema types and the resolvers parents */
export type ResolversParentTypes = {
Query: {};
String: Scalars['String'];
Boolean: Scalars['Boolean'];
String: Scalars['String']['output'];
Boolean: Scalars['Boolean']['output'];
};

export type QueryResolvers<
Expand Down
6 changes: 3 additions & 3 deletions examples/react/apollo-client-defer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
"private": true,
"dependencies": {
"@apollo/client": "^3.7.10",
"@graphql-yoga/plugin-defer-stream": "^2.0.0",
"@graphql-yoga/plugin-defer-stream": "^3.0.0",
"graphql": "^16.6.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"graphql-yoga": "4.0.4"
"graphql-yoga": "5.3.1"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.2",
Expand All @@ -18,7 +18,7 @@
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.1.0",
"cypress": "12.17.4",
"serve": "14.2.1",
"serve": "14.2.3",
"start-server-and-test": "2.0.3",
"typescript": "5.2.2",
"vite": "^4.1.0"
Expand Down
8 changes: 4 additions & 4 deletions examples/react/apollo-client-swc-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
"private": true,
"dependencies": {
"@apollo/client": "^3.7.10",
"react": "18.2.0",
"react-dom": "18.2.0"
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@graphql-codegen/client-preset-swc-plugin": "0.2.0",
"@graphql-codegen/cli": "^5.0.2",
"@vitejs/plugin-react-swc": "^3.3.0",
"@types/react": "18.2.60",
"@types/react-dom": "18.2.19",
"@types/react": "18.3.1",
"@types/react-dom": "18.3.0",
"typescript": "5.2.2",
"vite": "^4.1.0"
},
Expand Down
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",
"typescript": "5.2.2",
"serve": "14.2.1",
"serve": "14.2.3",
"cypress": "12.17.4",
"start-server-and-test": "2.0.3",
"vite": "^4.1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/http-executor/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",
"typescript": "5.2.2",
"serve": "14.2.1",
"serve": "14.2.3",
"cypress": "12.17.4",
"start-server-and-test": "2.0.3",
"vite": "^4.1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/react/nextjs-swr/hooks/use-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function useGraphQL<TResult, TVariables>(
document.definitions.find(isOperationDefinition)?.name,
variables,
] as const,
async (_key: string, variables: any) =>
async ([_key, variables]: any) =>
executor({
document,
variables,
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 @@ -13,7 +13,7 @@
},
"dependencies": {
"@graphql-tools/executor-http": "^1.0.0",
"next": "^13.3.0",
"next": "13.3.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"swr": "^2.0.0"
Expand Down
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 @@ -15,7 +15,7 @@
"@types/react": "^18.0.17",
"@types/react-dom": "^18.0.10",
"typescript": "5.2.2",
"serve": "14.2.1",
"serve": "14.2.3",
"cypress": "12.17.4",
"start-server-and-test": "2.0.3",
"vite": "^4.1.0"
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 @@ -13,7 +13,7 @@
"@graphql-codegen/cli": "^5.0.2",
"@vitejs/plugin-react": "^3.1.0",
"typescript": "5.2.2",
"serve": "14.2.1",
"serve": "14.2.3",
"cypress": "12.17.4",
"start-server-and-test": "2.0.3",
"vite": "^4.1.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/typescript-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"graphql": "16.8.0",
"graphql-yoga": "4.0.4",
"graphql-yoga": "5.3.1",
"graphql-request": "5.2.0"
},
"scripts": {
Expand Down
3 changes: 0 additions & 3 deletions examples/typescript-graphql-request/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,3 @@ export const getPeople = async (first?: number) => {
}
return res?.allPeople?.edges;
};

getPeople().then(res => console.log(res));
getPeople(10).then(res => console.log(res));
2 changes: 1 addition & 1 deletion examples/typescript-resolvers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"dependencies": {
"graphql": "16.8.0",
"graphql-yoga": "4.0.4"
"graphql-yoga": "5.3.1"
},
"scripts": {
"codegen": "graphql-codegen --config codegen.ts",
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/apollo-composable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"typescript": "^5.0.0",
"vite": "^4.1.0",
"vue-tsc": "^1.0.24",
"serve": "14.2.1",
"serve": "14.2.3",
"cypress": "12.17.4",
"start-server-and-test": "2.0.3"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/urql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typescript": "^5.0.0",
"vite": "^4.1.0",
"vue-tsc": "^1.0.24",
"serve": "14.2.1",
"serve": "14.2.3",
"cypress": "12.17.4",
"start-server-and-test": "2.0.3"
}
Expand Down
2 changes: 1 addition & 1 deletion examples/vue/villus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"typescript": "^5.0.0",
"vite": "^4.1.0",
"vue-tsc": "^1.0.24",
"serve": "14.2.1",
"serve": "14.2.3",
"cypress": "12.17.4",
"start-server-and-test": "2.0.3"
}
Expand Down
8 changes: 4 additions & 4 deletions examples/yoga-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"version": "0.0.0",
"private": true,
"dependencies": {
"graphql-yoga": "4.0.4"
"graphql-yoga": "5.3.1"
},
"devDependencies": {
"@graphql-typed-document-node/core": "3.2.0",
"jest": "28.1.3",
"babel-jest": "29.6.4",
"@graphql-codegen/cli": "5.0.2",
"@babel/core": "7.23.9",
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "7.23.3"
"@babel/core": "7.24.5",
"@babel/preset-env": "7.24.5",
"@babel/preset-typescript": "7.24.1"
},
"scripts": {
"test": "jest",
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
"examples/**/*"
],
"devDependencies": {
"@babel/core": "7.23.9",
"@babel/preset-env": "7.23.9",
"@babel/preset-typescript": "7.23.3",
"@babel/core": "7.24.5",
"@babel/preset-env": "7.24.5",
"@babel/preset-typescript": "7.24.1",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.1",
"@theguild/eslint-config": "0.11.3",
"@theguild/eslint-config": "0.11.8",
"@theguild/prettier-config": "0.1.1",
"@types/jest": "28.1.8",
"babel-jest": "29.6.4",
Expand All @@ -67,7 +67,7 @@
"ts-jest": "28.0.8",
"ts-node": "10.9.1",
"tslib": "2.6.2",
"tsx": "4.7.1",
"tsx": "4.9.3",
"typescript": "5.2.2"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"yargs": "^17.0.0"
},
"devDependencies": {
"@graphql-tools/merge": "9.0.3",
"@graphql-tools/merge": "9.0.4",
"@parcel/watcher": "^2.1.0",
"@types/debounce": "1.2.4",
"@types/inquirer": "8.2.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql-codegen-cli/tests/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os from 'os';
import { join, parse, relative, resolve } from 'path';
import makeDir from 'make-dir';
import rimraf from 'rimraf';
import * as rimraf from 'rimraf';

const fs = jest.requireActual('fs');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ export class BaseResolversVisitor<
// - If there are fields to Omit, keep track of these "type with maybe Omit" to replace in original unionMemberValue
const fieldsToOmit = this.getRelevantFieldsToOmit({
schemaType: type,
getTypeToUse: baseType => `RefType['${baseType}']`,
getTypeToUse: baseType => `_RefType['${baseType}']`,
});
if (fieldsToOmit.length > 0) {
typeValue = this.replaceFieldsInType(typeValue, fieldsToOmit);
Expand Down Expand Up @@ -1147,7 +1147,7 @@ export class BaseResolversVisitor<
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind(declarationKind)
.withName(this.convertName('ResolversUnionTypes'), `<RefType extends Record<string, unknown>>`)
.withName(this.convertName('ResolversUnionTypes'), `<_RefType extends Record<string, unknown>>`)
.withComment('Mapping of union types')
.withBlock(
Object.entries(this._resolversUnionTypes)
Expand All @@ -1165,7 +1165,7 @@ export class BaseResolversVisitor<
return new DeclarationBlock(this._declarationBlockConfig)
.export()
.asKind(declarationKind)
.withName(this.convertName('ResolversInterfaceTypes'), `<RefType extends Record<string, unknown>>`)
.withName(this.convertName('ResolversInterfaceTypes'), `<_RefType extends Record<string, unknown>>`)
.withComment('Mapping of interface types')
.withBlock(
Object.entries(this._resolversInterfaceTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -926,10 +926,7 @@ export class BaseTypesVisitor<
let enumValue: string | number =
typeof schemaEnumValue === 'undefined' ? (enumOption.name as any) : schemaEnumValue;

if (
this.config.enumValues[typeName]?.mappedValues &&
typeof this.config.enumValues[typeName].mappedValues[enumValue] !== 'undefined'
) {
if (typeof this.config.enumValues[typeName]?.mappedValues?.[enumValue] !== 'undefined') {
enumValue = this.config.enumValues[typeName].mappedValues[enumValue];
}

Expand Down

0 comments on commit ec153e1

Please sign in to comment.