Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dotansimha/graphql-code-generator
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: @graphql-codegen/visitor-plugin-common@4.1.2
Choose a base ref
...
head repository: dotansimha/graphql-code-generator
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: @graphql-codegen/visitor-plugin-common@5.0.0
Choose a head ref
  • 6 commits
  • 31 files changed
  • 7 contributors

Commits on Feb 6, 2024

  1. Minor structure update (#9838)

    Missed one `#`
    lachieh authored Feb 6, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4acf545 View commit details

Commits on Feb 20, 2024

  1. refactor: import and export statements in BaseResolversVisitor and ma… (

    #9845)
    
    * refactor: import and export statements in BaseResolversVisitor and mappers.ts
    
    * run prettier
    
    * Refactor mapper functions to use includes() instead of startsWith() and replace()
    
    * yarn changeset
    
    * feat: add test
    
    * Remove unused query.ts file
    
    * Add RoleStatus enum and import it in result.d.ts and schema.graphql
    productdevbook authored Feb 20, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    53f270a View commit details
  2. Update plugin-structure.mdx (#9778)

    Seems there is now a nested "plugins:" key missing from that listed in the docs so added it in, was throwing errors without it
    PeteDuncanson authored Feb 20, 2024
    Copy the full SHA
    2e43476 View commit details
  3. Copy the full SHA
    60d26e2 View commit details
  4. Copy the full SHA
    2a40b3b View commit details
  5. chore(release): update monorepo packages versions (#9846)

    Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
    theguild-bot and github-actions[bot] authored Feb 20, 2024
    Copy the full SHA
    8c40cdf View commit details
Showing with 346 additions and 47 deletions.
  1. +11 −0 dev-test/codegen.ts
  2. +167 −0 dev-test/subpath-import/result.d.ts
  3. +17 −0 dev-test/subpath-import/schema.graphql
  4. +4 −4 examples/programmatic-typescript/package.json
  5. +2 −2 examples/typescript-resolvers/package.json
  6. +7 −0 packages/plugins/other/introspection/CHANGELOG.md
  7. +2 −2 packages/plugins/other/introspection/package.json
  8. +6 −0 packages/plugins/other/visitor-plugin-common/CHANGELOG.md
  9. +1 −1 packages/plugins/other/visitor-plugin-common/package.json
  10. +12 −2 packages/plugins/other/visitor-plugin-common/src/base-resolvers-visitor.ts
  11. +15 −1 packages/plugins/other/visitor-plugin-common/src/mappers.ts
  12. +7 −0 packages/plugins/typescript/document-nodes/CHANGELOG.md
  13. +2 −2 packages/plugins/typescript/document-nodes/package.json
  14. +7 −0 packages/plugins/typescript/gql-tag-operations/CHANGELOG.md
  15. +2 −2 packages/plugins/typescript/gql-tag-operations/package.json
  16. +8 −0 packages/plugins/typescript/operations/CHANGELOG.md
  17. +3 −3 packages/plugins/typescript/operations/package.json
  18. +8 −0 packages/plugins/typescript/resolvers/CHANGELOG.md
  19. +3 −3 packages/plugins/typescript/resolvers/package.json
  20. +7 −0 packages/plugins/typescript/typed-document-node/CHANGELOG.md
  21. +2 −2 packages/plugins/typescript/typed-document-node/package.json
  22. +7 −0 packages/plugins/typescript/typescript/CHANGELOG.md
  23. +2 −2 packages/plugins/typescript/typescript/package.json
  24. +11 −0 packages/presets/client/CHANGELOG.md
  25. +6 −6 packages/presets/client/package.json
  26. +7 −0 packages/presets/graphql-modules/CHANGELOG.md
  27. +2 −2 packages/presets/graphql-modules/package.json
  28. +6 −6 website/package.json
  29. +2 −0 website/src/pages/docs/config-reference/codegen-config.mdx
  30. +9 −6 website/src/pages/docs/custom-codegen/plugin-structure.mdx
  31. +1 −1 website/src/pages/plugins/typescript/typescript-msw.mdx
11 changes: 11 additions & 0 deletions dev-test/codegen.ts
Original file line number Diff line number Diff line change
@@ -232,6 +232,17 @@ const config: CodegenConfig = {
mergeFragmentTypes: true,
},
},
'./dev-test/subpath-import/result.d.ts': {
schema: './dev-test/subpath-import/schema.graphql',
plugins: ['typescript', 'typescript-resolvers'],
config: {
contextType: '\\#test-null-value/context#TestContext',
fieldContextTypes: ['mutation.createUser#\\#test/root#FiedContextType'],
enumValues: {
RoleStatus: '\\#changeName/server/drizzle/schema#RoleStatus',
},
},
},
},
};

167 changes: 167 additions & 0 deletions dev-test/subpath-import/result.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { RoleStatus } from '#changeName/server/drizzle/schema';
import { GraphQLResolveInfo } from 'graphql';
import { TestContext } from '#test-null-value/context';
import { FiedContextType } from '#test/root';
export type Maybe<T> = T | null;
export type InputMaybe<T> = Maybe<T>;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]?: Maybe<T[SubKey]> };
export type MakeMaybe<T, K extends keyof T> = Omit<T, K> & { [SubKey in K]: Maybe<T[SubKey]> };
export type MakeEmpty<T extends { [key: string]: unknown }, K extends keyof T> = { [_ in K]?: never };
export type Incremental<T> = T | { [P in keyof T]?: P extends ' $fragmentName' | '__typename' ? T[P] : never };
export type EnumResolverSignature<T, AllowedValues = any> = { [key in keyof T]?: AllowedValues };
export type RequireFields<T, K extends keyof T> = Omit<T, K> & { [P in K]-?: NonNullable<T[P]> };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
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 { RoleStatus };

export type User = {
__typename?: 'User';
createdAt: Scalars['String']['output'];
email: Scalars['String']['output'];
id: Scalars['ID']['output'];
name: Scalars['String']['output'];
password: Scalars['String']['output'];
updatedAt: Scalars['String']['output'];
};

export type Mutation = {
__typename?: 'mutation';
createUser: User;
};

export type MutationCreateUserArgs = {
email: Scalars['String']['input'];
name: Scalars['String']['input'];
password: Scalars['String']['input'];
};

export type ResolverTypeWrapper<T> = Promise<T> | T;

export type ResolverWithResolve<TResult, TParent, TContext, TArgs> = {
resolve: ResolverFn<TResult, TParent, TContext, TArgs>;
};
export type Resolver<TResult, TParent = {}, TContext = {}, TArgs = {}> =
| ResolverFn<TResult, TParent, TContext, TArgs>
| ResolverWithResolve<TResult, TParent, TContext, TArgs>;

export type ResolverFn<TResult, TParent, TContext, TArgs> = (
parent: TParent,
args: TArgs,
context: TContext,
info: GraphQLResolveInfo
) => Promise<TResult> | TResult;

export type SubscriptionSubscribeFn<TResult, TParent, TContext, TArgs> = (
parent: TParent,
args: TArgs,
context: TContext,
info: GraphQLResolveInfo
) => AsyncIterable<TResult> | Promise<AsyncIterable<TResult>>;

export type SubscriptionResolveFn<TResult, TParent, TContext, TArgs> = (
parent: TParent,
args: TArgs,
context: TContext,
info: GraphQLResolveInfo
) => TResult | Promise<TResult>;

export interface SubscriptionSubscriberObject<TResult, TKey extends string, TParent, TContext, TArgs> {
subscribe: SubscriptionSubscribeFn<{ [key in TKey]: TResult }, TParent, TContext, TArgs>;
resolve?: SubscriptionResolveFn<TResult, { [key in TKey]: TResult }, TContext, TArgs>;
}

export interface SubscriptionResolverObject<TResult, TParent, TContext, TArgs> {
subscribe: SubscriptionSubscribeFn<any, TParent, TContext, TArgs>;
resolve: SubscriptionResolveFn<TResult, any, TContext, TArgs>;
}

export type SubscriptionObject<TResult, TKey extends string, TParent, TContext, TArgs> =
| SubscriptionSubscriberObject<TResult, TKey, TParent, TContext, TArgs>
| SubscriptionResolverObject<TResult, TParent, TContext, TArgs>;

export type SubscriptionResolver<TResult, TKey extends string, TParent = {}, TContext = {}, TArgs = {}> =
| ((...args: any[]) => SubscriptionObject<TResult, TKey, TParent, TContext, TArgs>)
| SubscriptionObject<TResult, TKey, TParent, TContext, TArgs>;

export type TypeResolveFn<TTypes, TParent = {}, TContext = {}> = (
parent: TParent,
context: TContext,
info: GraphQLResolveInfo
) => Maybe<TTypes> | Promise<Maybe<TTypes>>;

export type IsTypeOfResolverFn<T = {}, TContext = {}> = (
obj: T,
context: TContext,
info: GraphQLResolveInfo
) => boolean | Promise<boolean>;

export type NextResolverFn<T> = () => Promise<T>;

export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs = {}> = (
next: NextResolverFn<TResult>,
parent: TParent,
args: TArgs,
context: TContext,
info: GraphQLResolveInfo
) => TResult | Promise<TResult>;

/** Mapping between all available schema types and the resolvers types */
export type ResolversTypes = {
Boolean: ResolverTypeWrapper<Scalars['Boolean']['output']>;
ID: ResolverTypeWrapper<Scalars['ID']['output']>;
RoleStatus: RoleStatus;
String: ResolverTypeWrapper<Scalars['String']['output']>;
User: ResolverTypeWrapper<User>;
mutation: ResolverTypeWrapper<Mutation>;
};

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

export type RoleStatusResolvers = EnumResolverSignature<{ ADMIN?: any; USER?: any }, ResolversTypes['RoleStatus']>;

export type UserResolvers<
ContextType = TestContext,
ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User']
> = {
createdAt?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
email?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
name?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
password?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
updatedAt?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type MutationResolvers<
ContextType = TestContext,
ParentType extends ResolversParentTypes['mutation'] = ResolversParentTypes['mutation']
> = {
createUser?: Resolver<
ResolversTypes['User'],
ParentType,
FiedContextType,
RequireFields<MutationCreateUserArgs, 'email' | 'name' | 'password'>
>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};

export type Resolvers<ContextType = TestContext> = {
RoleStatus?: RoleStatusResolvers;
User?: UserResolvers<ContextType>;
mutation?: MutationResolvers<ContextType>;
};
17 changes: 17 additions & 0 deletions dev-test/subpath-import/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type User {
id: ID!
name: String!
email: String!
password: String!
createdAt: String!
updatedAt: String!
}

enum RoleStatus {
ADMIN
USER
}

type mutation {
createUser(name: String!, email: String!, password: String!): User!
}
8 changes: 4 additions & 4 deletions examples/programmatic-typescript/package.json
Original file line number Diff line number Diff line change
@@ -12,10 +12,10 @@
"dependencies": {
"@graphql-codegen/core": "4.0.2",
"@graphql-codegen/plugin-helpers": "5.0.3",
"@graphql-codegen/typed-document-node": "5.0.4",
"@graphql-codegen/typescript": "4.0.4",
"@graphql-codegen/typescript-operations": "4.1.2",
"@graphql-codegen/typescript-resolvers": "4.0.4",
"@graphql-codegen/typed-document-node": "5.0.5",
"@graphql-codegen/typescript": "4.0.5",
"@graphql-codegen/typescript-operations": "4.1.3",
"@graphql-codegen/typescript-resolvers": "4.0.5",
"@graphql-tools/graphql-file-loader": "8.0.0",
"@graphql-tools/load": "8.0.0",
"@graphql-tools/schema": "10.0.0",
4 changes: 2 additions & 2 deletions examples/typescript-resolvers/package.json
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@
"private": true,
"devDependencies": {
"@graphql-codegen/cli": "5.0.2",
"@graphql-codegen/typescript": "4.0.4",
"@graphql-codegen/typescript-resolvers": "4.0.4"
"@graphql-codegen/typescript": "4.0.5",
"@graphql-codegen/typescript-resolvers": "4.0.5"
},
"dependencies": {
"graphql": "16.8.0",
7 changes: 7 additions & 0 deletions packages/plugins/other/introspection/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @graphql-codegen/introspection

## 4.0.3

### Patch Changes

- Updated dependencies [[`53f270a`](https://github.com/dotansimha/graphql-code-generator/commit/53f270acfa1da992e0f9d2e50921bb588392f8a5)]:
- @graphql-codegen/visitor-plugin-common@5.0.0

## 4.0.2

### Patch Changes
4 changes: 2 additions & 2 deletions packages/plugins/other/introspection/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/introspection",
"version": "4.0.2",
"version": "4.0.3",
"description": "GraphQL Code Generator plugin for generating an introspection JSON file for a GraphQLSchema",
"repository": {
"type": "git",
@@ -14,7 +14,7 @@
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^5.0.3",
"@graphql-codegen/visitor-plugin-common": "^4.1.2",
"@graphql-codegen/visitor-plugin-common": "^5.0.0",
"tslib": "~2.6.0"
},
"peerDependencies": {
6 changes: 6 additions & 0 deletions packages/plugins/other/visitor-plugin-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @graphql-codegen/visitor-plugin-common

## 5.0.0

### Major Changes

- [#9845](https://github.com/dotansimha/graphql-code-generator/pull/9845) [`53f270a`](https://github.com/dotansimha/graphql-code-generator/commit/53f270acfa1da992e0f9d2e50921bb588392f8a5) Thanks [@productdevbook](https://github.com/productdevbook)! - path starts with "#"

## 4.1.2

### Patch Changes
2 changes: 1 addition & 1 deletion packages/plugins/other/visitor-plugin-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/visitor-plugin-common",
"version": "4.1.2",
"version": "5.0.0",
"license": "MIT",
"repository": {
"type": "git",
Original file line number Diff line number Diff line change
@@ -1075,21 +1075,31 @@ export class BaseResolversVisitor<

protected createFieldContextTypeMap(): FieldContextTypeMap {
return this.config.fieldContextTypes.reduce<FieldContextTypeMap>((prev, fieldContextType) => {
const isScoped = fieldContextType.includes('\\#');
if (fieldContextType.includes('\\#')) {
fieldContextType = fieldContextType.replace('\\#', '');
}
const items = fieldContextType.split('#');
if (items.length === 3) {
const [path, source, contextTypeName] = items;
return { ...prev, [path]: parseMapper(`${source}#${contextTypeName}`) };
const sourceStr = isScoped ? `\\#${source}` : source;
return { ...prev, [path]: parseMapper(`${sourceStr}#${contextTypeName}`) };
}
const [path, contextType] = items;
return { ...prev, [path]: parseMapper(contextType) };
}, {});
}
protected createDirectivedContextType(): FieldContextTypeMap {
return this.config.directiveContextTypes.reduce<FieldContextTypeMap>((prev, fieldContextType) => {
const isScoped = fieldContextType.includes('\\#');
if (fieldContextType.includes('\\#')) {
fieldContextType = fieldContextType.replace('\\#', '');
}
const items = fieldContextType.split('#');
if (items.length === 3) {
const [path, source, contextTypeName] = items;
return { ...prev, [path]: parseMapper(`${source}#${contextTypeName}`) };
const sourceStr = isScoped ? `\\#${source}` : source;
return { ...prev, [path]: parseMapper(`${sourceStr}#${contextTypeName}`) };
}
const [path, contextType] = items;
return { ...prev, [path]: parseMapper(contextType) };
16 changes: 15 additions & 1 deletion packages/plugins/other/visitor-plugin-common/src/mappers.ts
Original file line number Diff line number Diff line change
@@ -33,10 +33,16 @@ interface Helpers {
}

function prepareLegacy(mapper: string): Helpers {
const isScoped = mapper.includes('\\#');
if (mapper.includes('\\#')) {
mapper = mapper.replace('\\#', '');
}
const items = mapper.split('#');
const isNamespace = items.length === 3;
const isDefault = items[1].trim() === 'default' || items[1].startsWith('default ');
const hasAlias = items[1].includes(' as ');
const source = isScoped ? `#${items[0]}` : items[0];
items[0] = source;

return {
items,
@@ -47,10 +53,15 @@ function prepareLegacy(mapper: string): Helpers {
}

function prepare(mapper: string): Helpers {
const [source, path] = mapper.split('#');
const isScoped = mapper.includes('\\#');
if (mapper.includes('\\#')) {
mapper = mapper.replace('\\#', '');
}
let [source, path] = mapper.split('#');
const isNamespace = path.includes('.');
const isDefault = path.trim() === 'default' || path.startsWith('default ');
const hasAlias = path.includes(' as ');
source = isScoped ? `#${source}` : source;

return {
items: isNamespace ? [source, ...path.split('.')] : [source, path],
@@ -61,6 +72,9 @@ function prepare(mapper: string): Helpers {
}

function isLegacyMode(mapper: string) {
if (mapper.includes('\\#')) {
mapper = mapper.replace('\\#', '');
}
return mapper.split('#').length === 3;
}

7 changes: 7 additions & 0 deletions packages/plugins/typescript/document-nodes/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# @graphql-codegen/typescript-document-nodes

## 4.0.5

### Patch Changes

- Updated dependencies [[`53f270a`](https://github.com/dotansimha/graphql-code-generator/commit/53f270acfa1da992e0f9d2e50921bb588392f8a5)]:
- @graphql-codegen/visitor-plugin-common@5.0.0

## 4.0.4

### Patch Changes
4 changes: 2 additions & 2 deletions packages/plugins/typescript/document-nodes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@graphql-codegen/typescript-document-nodes",
"version": "4.0.4",
"version": "4.0.5",
"description": "GraphQL Code Generator plugin for generating TypeScript modules with embedded GraphQL document nodes",
"repository": {
"type": "git",
@@ -14,7 +14,7 @@
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^5.0.3",
"@graphql-codegen/visitor-plugin-common": "4.1.2",
"@graphql-codegen/visitor-plugin-common": "5.0.0",
"auto-bind": "~4.0.0",
"tslib": "~2.6.0"
},
Loading