From 406fbb628543608a51e747b6b576de894c589175 Mon Sep 17 00:00:00 2001 From: RokasVaitkevicius Date: Tue, 23 Jan 2024 19:26:22 +0200 Subject: [PATCH] Added codegen afterOneFileWrite script which fixes generated imports --- backend/codegen.ts | 20 +- backend/src/__generated__/resolvers-types.ts | 307 ++++++------------- 2 files changed, 106 insertions(+), 221 deletions(-) diff --git a/backend/codegen.ts b/backend/codegen.ts index 80491bf..92fbbcb 100644 --- a/backend/codegen.ts +++ b/backend/codegen.ts @@ -1,4 +1,5 @@ import type { CodegenConfig } from '@graphql-codegen/cli'; +import fs from 'fs'; const config: CodegenConfig = { overwrite: true, @@ -14,8 +15,23 @@ const config: CodegenConfig = { }, hooks: { afterOneFileWrite: [ - // "sed -i '' 's/import { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from '\\''graphql'\\'';/import type { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from '\\''graphql'\\'';/g' src/__generated__/resolvers-types.ts", - // "sed -i '' 's/import { ApolloContext } from '\\''..\\/server\\/apollo.js'\\'';/import type { ApolloContext } from '\\''..\\/server\\/apollo.js'\\'';/g' src/__generated__/resolvers-types.ts", + (filePath) => { + if (filePath.endsWith('resolvers-types.ts')) { + const content = fs.readFileSync(filePath, 'utf8'); + + const graphqlImportRegex = + /import { (GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig) } from 'graphql';/g; + const apolloContextImportRegex = /import { (ApolloContext) } from '\.\.\/server\/apollo\.js';/g; + + let modifiedContent = content.replace(graphqlImportRegex, "import type { $1 } from 'graphql';"); + modifiedContent = modifiedContent.replace( + apolloContextImportRegex, + "import type { $1 } from '../server/apollo.js';" + ); + + fs.writeFileSync(filePath, modifiedContent); + } + }, ], }, config: { diff --git a/backend/src/__generated__/resolvers-types.ts b/backend/src/__generated__/resolvers-types.ts index 06da423..777b68f 100644 --- a/backend/src/__generated__/resolvers-types.ts +++ b/backend/src/__generated__/resolvers-types.ts @@ -1,7 +1,5 @@ import type { GraphQLResolveInfo, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'; - import type { ApolloContext } from '../server/apollo.js'; - export type Maybe = T | null; export type InputMaybe = Maybe; export type Exact = { [K in keyof T]: T[K] }; @@ -12,13 +10,13 @@ export type Incremental = T | { [P in keyof T]?: P extends ' $fragmentName' | export type RequireFields = Omit & { [P in K]-?: NonNullable }; /** 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 }; - DateTime: { input: any; output: any }; - Upload: { input: any; output: any }; + 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; } + DateTime: { input: any; output: any; } + Upload: { input: any; output: any; } }; export type AddItemToViewStateItemInput = { @@ -68,14 +66,14 @@ export type Board = { export enum BoardStyle { Kanban = 'KANBAN', - Scrum = 'SCRUM', + Scrum = 'SCRUM' } export enum Custom_Field_Type { Boolean = 'BOOLEAN', Date = 'DATE', Number = 'NUMBER', - Text = 'TEXT', + Text = 'TEXT' } export type Column = { @@ -279,113 +277,139 @@ export type Mutation = { uploadAsset?: Maybe; }; + export type MutationAddItemToViewStateArgs = { input: AddItemToViewStateItemInput; }; + export type MutationAddUserToProjectArgs = { input: AddUserToProjectInput; }; + export type MutationAssignAssetAsAvatarArgs = { input: AssignAssetAsAvatarInput; }; + export type MutationCreateBoardArgs = { input?: InputMaybe; }; + export type MutationCreateIssueArgs = { input?: InputMaybe; }; + export type MutationCreateIssueCommentArgs = { input: CreateIssueCommentInput; }; + export type MutationCreateIssueLinkArgs = { input: CreateIssueLinkInput; }; + export type MutationCreateIssueStatusArgs = { input: CreateIssueStatusInput; }; + export type MutationCreateProjectArgs = { input?: InputMaybe; }; + export type MutationCreateProjectCustomFieldArgs = { input: CreateProjectCustomFieldInput; }; + export type MutationCreateProjectTagArgs = { input: CreateProjectTagInput; }; + export type MutationCreateViewStateArgs = { input: CreateViewStateInput; }; + export type MutationDeleteAssetArgs = { input: DeleteAssetInput; }; + export type MutationDeleteIssueArgs = { input: DeleteIssueInput; }; + export type MutationDeleteIssueCommentArgs = { input: DeleteIssueCommentInput; }; + export type MutationDeleteIssueLinkArgs = { input: DeleteIssueLinkInput; }; + export type MutationDeleteProjectCustomFieldArgs = { input: DeleteProjectCustomFieldInput; }; + export type MutationDeleteProjectTagArgs = { input: DeleteProjectTagInput; }; + export type MutationRemoveItemFromViewStateArgs = { input: RemoveItemFromViewStateItemInput; }; + export type MutationRemoveUserFromProjectArgs = { input: RemoveUserFromProjectInput; }; + export type MutationUpdateBoardArgs = { input?: InputMaybe; }; + export type MutationUpdateIssueArgs = { input?: InputMaybe; }; + export type MutationUpdateIssueCommentArgs = { input: UpdateIssueCommentInput; }; + export type MutationUpdateMeArgs = { input: UpdateMeInput; }; + export type MutationUpdateViewStateArgs = { input: UpdateViewStateInput; }; + export type MutationUploadAssetArgs = { input: UploadAssetInput; }; export enum Order { Asc = 'ASC', - Desc = 'DESC', + Desc = 'DESC' } export type Project = { @@ -408,6 +432,7 @@ export type Project = { visibility?: Maybe; }; + export type ProjectIssuesArgs = { input?: InputMaybe; }; @@ -424,7 +449,7 @@ export type ProjectTag = { export enum ProjectVisibility { Internal = 'INTERNAL', Private = 'PRIVATE', - Public = 'PUBLIC', + Public = 'PUBLIC' } export type Query = { @@ -443,30 +468,37 @@ export type Query = { users?: Maybe>>; }; + export type QueryBoardArgs = { input: QueryBoardInput; }; + export type QueryCreateProjectValidationArgs = { input: CreateProjectValidationInput; }; + export type QueryIssueArgs = { input?: InputMaybe; }; + export type QueryIssuesArgs = { input?: InputMaybe; }; + export type QueryProjectArgs = { input?: InputMaybe; }; + export type QueryProjectTagsArgs = { input: QueryProjectTagsInput; }; + export type QueryProjectsArgs = { input?: InputMaybe; }; @@ -608,12 +640,11 @@ export type ResolversObject = WithIndex; export type ResolverTypeWrapper = Promise | T; + export type ResolverWithResolve = { resolve: ResolverFn; }; -export type Resolver = - | ResolverFn - | ResolverWithResolve; +export type Resolver = ResolverFn | ResolverWithResolve; export type ResolverFn = ( parent: TParent, @@ -660,11 +691,7 @@ export type TypeResolveFn = ( info: GraphQLResolveInfo ) => Maybe | Promise>; -export type IsTypeOfResolverFn = ( - obj: T, - context: TContext, - info: GraphQLResolveInfo -) => boolean | Promise; +export type IsTypeOfResolverFn = (obj: T, context: TContext, info: GraphQLResolveInfo) => boolean | Promise; export type NextResolverFn = () => Promise; @@ -676,6 +703,8 @@ export type DirectiveResolverFn TResult | Promise; + + /** Mapping between all available schema types and the resolvers types */ export type ResolversTypes = ResolversObject<{ AddItemToViewStateItemInput: ResolverTypeWrapper>; @@ -835,20 +864,14 @@ export type BoardResolvers; }>; -export type ColumnResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['Column'], -> = ResolversObject<{ +export type ColumnResolvers = ResolversObject<{ id?: Resolver; issues?: Resolver>>, ParentType, ContextType>; title?: Resolver; __isTypeOf?: IsTypeOfResolverFn; }>; -export type CustomFieldResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['CustomField'], -> = ResolversObject<{ +export type CustomFieldResolvers = ResolversObject<{ createdAt?: Resolver, ParentType, ContextType>; fieldName?: Resolver; fieldType?: Resolver; @@ -858,10 +881,7 @@ export type CustomFieldResolvers< __isTypeOf?: IsTypeOfResolverFn; }>; -export type CustomFieldValueResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['CustomFieldValue'], -> = ResolversObject<{ +export type CustomFieldValueResolvers = ResolversObject<{ createdAt?: Resolver, ParentType, ContextType>; customField?: Resolver, ParentType, ContextType>; customFieldId?: Resolver; @@ -904,10 +924,7 @@ export type IssueResolvers; }>; -export type IssueCommentResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['IssueComment'], -> = ResolversObject<{ +export type IssueCommentResolvers = ResolversObject<{ comment?: Resolver; createdAt?: Resolver, ParentType, ContextType>; id?: Resolver; @@ -917,10 +934,7 @@ export type IssueCommentResolvers< __isTypeOf?: IsTypeOfResolverFn; }>; -export type IssueStatusResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['IssueStatus'], -> = ResolversObject<{ +export type IssueStatusResolvers = ResolversObject<{ createdAt?: Resolver, ParentType, ContextType>; id?: Resolver; name?: Resolver; @@ -929,161 +943,42 @@ export type IssueStatusResolvers< __isTypeOf?: IsTypeOfResolverFn; }>; -export type MessageAndStatusResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['MessageAndStatus'], -> = ResolversObject<{ +export type MessageAndStatusResolvers = ResolversObject<{ message?: Resolver, ParentType, ContextType>; status?: Resolver, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }>; -export type MutationResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['Mutation'], -> = ResolversObject<{ - addItemToViewState?: Resolver< - Maybe>>, - ParentType, - ContextType, - RequireFields - >; - addUserToProject?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - assignAssetAsAvatar?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; +export type MutationResolvers = ResolversObject<{ + addItemToViewState?: Resolver>>, ParentType, ContextType, RequireFields>; + addUserToProject?: Resolver, ParentType, ContextType, RequireFields>; + assignAssetAsAvatar?: Resolver, ParentType, ContextType, RequireFields>; createBoard?: Resolver, ParentType, ContextType, Partial>; createIssue?: Resolver, ParentType, ContextType, Partial>; - createIssueComment?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - createIssueLink?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - createIssueStatus?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - createProject?: Resolver< - Maybe, - ParentType, - ContextType, - Partial - >; - createProjectCustomField?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - createProjectTag?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - createViewState?: Resolver< - Maybe>>, - ParentType, - ContextType, - RequireFields - >; - deleteAsset?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - deleteIssue?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - deleteIssueComment?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - deleteIssueLink?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - deleteProjectCustomField?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - deleteProjectTag?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - removeItemFromViewState?: Resolver< - Maybe>>, - ParentType, - ContextType, - RequireFields - >; - removeUserFromProject?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; + createIssueComment?: Resolver, ParentType, ContextType, RequireFields>; + createIssueLink?: Resolver, ParentType, ContextType, RequireFields>; + createIssueStatus?: Resolver, ParentType, ContextType, RequireFields>; + createProject?: Resolver, ParentType, ContextType, Partial>; + createProjectCustomField?: Resolver, ParentType, ContextType, RequireFields>; + createProjectTag?: Resolver, ParentType, ContextType, RequireFields>; + createViewState?: Resolver>>, ParentType, ContextType, RequireFields>; + deleteAsset?: Resolver, ParentType, ContextType, RequireFields>; + deleteIssue?: Resolver, ParentType, ContextType, RequireFields>; + deleteIssueComment?: Resolver, ParentType, ContextType, RequireFields>; + deleteIssueLink?: Resolver, ParentType, ContextType, RequireFields>; + deleteProjectCustomField?: Resolver, ParentType, ContextType, RequireFields>; + deleteProjectTag?: Resolver, ParentType, ContextType, RequireFields>; + removeItemFromViewState?: Resolver>>, ParentType, ContextType, RequireFields>; + removeUserFromProject?: Resolver, ParentType, ContextType, RequireFields>; updateBoard?: Resolver, ParentType, ContextType, Partial>; updateIssue?: Resolver, ParentType, ContextType, Partial>; - updateIssueComment?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - updateMe?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; - updateViewState?: Resolver< - Maybe>>, - ParentType, - ContextType, - RequireFields - >; - uploadAsset?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; + updateIssueComment?: Resolver, ParentType, ContextType, RequireFields>; + updateMe?: Resolver, ParentType, ContextType, RequireFields>; + updateViewState?: Resolver>>, ParentType, ContextType, RequireFields>; + uploadAsset?: Resolver, ParentType, ContextType, RequireFields>; }>; -export type ProjectResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['Project'], -> = ResolversObject<{ +export type ProjectResolvers = ResolversObject<{ boards?: Resolver>>, ParentType, ContextType>; createdAt?: Resolver, ParentType, ContextType>; customFields?: Resolver>>, ParentType, ContextType>; @@ -1103,10 +998,7 @@ export type ProjectResolvers< __isTypeOf?: IsTypeOfResolverFn; }>; -export type ProjectTagResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['ProjectTag'], -> = ResolversObject<{ +export type ProjectTagResolvers = ResolversObject<{ createdAt?: Resolver, ParentType, ContextType>; id?: Resolver; name?: Resolver; @@ -1118,29 +1010,14 @@ export type ProjectTagResolvers< export type QueryResolvers = ResolversObject<{ board?: Resolver, ParentType, ContextType, RequireFields>; boards?: Resolver>>, ParentType, ContextType>; - createProjectValidation?: Resolver< - Maybe, - ParentType, - ContextType, - RequireFields - >; + createProjectValidation?: Resolver, ParentType, ContextType, RequireFields>; helloWorld?: Resolver; issue?: Resolver, ParentType, ContextType, Partial>; issues?: Resolver>>, ParentType, ContextType, Partial>; me?: Resolver, ParentType, ContextType>; project?: Resolver, ParentType, ContextType, Partial>; - projectTags?: Resolver< - Maybe>>, - ParentType, - ContextType, - RequireFields - >; - projects?: Resolver< - Maybe>>, - ParentType, - ContextType, - Partial - >; + projectTags?: Resolver>>, ParentType, ContextType, RequireFields>; + projects?: Resolver>>, ParentType, ContextType, Partial>; user?: Resolver, ParentType, ContextType>; users?: Resolver>>, ParentType, ContextType>; }>; @@ -1161,30 +1038,21 @@ export type UserResolvers; }>; -export type ViewStateResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['ViewState'], -> = ResolversObject<{ +export type ViewStateResolvers = ResolversObject<{ id?: Resolver; items?: Resolver>>, ParentType, ContextType>; title?: Resolver, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }>; -export type ViewStateIssueStatusResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['ViewStateIssueStatus'], -> = ResolversObject<{ +export type ViewStateIssueStatusResolvers = ResolversObject<{ id?: Resolver; name?: Resolver, ParentType, ContextType>; projectId?: Resolver, ParentType, ContextType>; __isTypeOf?: IsTypeOfResolverFn; }>; -export type ViewStateItemResolvers< - ContextType = ApolloContext, - ParentType = ResolversParentTypes['ViewStateItem'], -> = ResolversObject<{ +export type ViewStateItemResolvers = ResolversObject<{ id?: Resolver; status?: Resolver, ParentType, ContextType>; title?: Resolver, ParentType, ContextType>; @@ -1213,3 +1081,4 @@ export type Resolvers = ResolversObject<{ ViewStateIssueStatus?: ViewStateIssueStatusResolvers; ViewStateItem?: ViewStateItemResolvers; }>; +