Skip to content

Commit

Permalink
Support extending non-root object types across multiple modules (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
eddeee888 authored Sep 11, 2023
1 parent d5d9577 commit ab6a9e7
Show file tree
Hide file tree
Showing 76 changed files with 6,137 additions and 95 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-countries-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eddeee888/gcg-typescript-resolver-files': minor
---

Support extending non-root object types
13 changes: 12 additions & 1 deletion packages/typescript-resolver-files-e2e/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@
"rimraf -g 'packages/typescript-resolver-files-e2e/src/test-add-option/**/*.generated.*'"
],
"parallel": false
},
"test-extended-object-types": {
"commands": [
"rimraf -g 'packages/typescript-resolver-files-e2e/src/test-extended-object-types/**/resolvers/'",
"rimraf -g 'packages/typescript-resolver-files-e2e/src/test-extended-object-types/**/*.generated.*'"
],
"parallel": false
}
}
},
Expand All @@ -136,7 +143,8 @@
"nx graphql-codegen typescript-resolver-files-e2e -c test-esm-import --verbose",
"nx graphql-codegen typescript-resolver-files-e2e -c test-scalars-module --verbose",
"nx graphql-codegen typescript-resolver-files-e2e -c test-resolver-generation --verbose",
"nx graphql-codegen typescript-resolver-files-e2e -c test-add-option --verbose"
"nx graphql-codegen typescript-resolver-files-e2e -c test-add-option --verbose",
"nx graphql-codegen typescript-resolver-files-e2e -c test-extended-object-types --verbose"
],
"parallel": false
},
Expand Down Expand Up @@ -196,6 +204,9 @@
},
"test-add-option": {
"configFile": "packages/typescript-resolver-files-e2e/src/test-add-option/codegen.ts"
},
"test-extended-object-types": {
"configFile": "packages/typescript-resolver-files-e2e/src/test-extended-object-types/codegen.ts"
}
},
"dependsOn": ["prepare-e2e-modules"]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { CodegenConfig } from '@graphql-codegen/cli';
import { defineConfig } from '@eddeee888/gcg-typescript-resolver-files';

const config: CodegenConfig = {
hooks: {
afterAllFileWrite: ['prettier --write'],
},
generates: {
'packages/typescript-resolver-files-e2e/src/test-extended-object-types/schema-base':
defineConfig(
{},
{
schema: [
'packages/typescript-resolver-files-e2e/src/test-extended-object-types/schema-base/**/*.graphqls',
'packages/typescript-resolver-files-e2e/src/test-extended-object-types/schema-base/**/*.graphqls.ts',
],
}
),
'packages/typescript-resolver-files-e2e/src/test-extended-object-types/schema-external-resolver-override-extended-object-type':
defineConfig(
{
externalResolvers: {
Topic: '~@org/topic-module#Topic as TopicResolver',
},
},
{
schema: [
'packages/typescript-resolver-files-e2e/src/test-extended-object-types/schema-external-resolver-override-extended-object-type/**/*.graphqls',
'packages/typescript-resolver-files-e2e/src/test-extended-object-types/schema-external-resolver-override-extended-object-type/**/*.graphqls.ts',
],
}
),
},
};

export default config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
type Query
type Mutation
type Subscription

interface Error {
error: ErrorType!
}

type PayloadError implements Error {
error: ErrorType!
}

enum ErrorType {
NOT_FOUND
INPUT_VALIDATION_ERROR
FORBIDDEN_ERROR
UNEXPECTED_ERROR
}

input PaginationInput {
recordsPerPage: Int
page: Int
}

type PaginationResult {
currentPage: Int!
recordsPerPage: Int!
totalPageCount: Int!
}

scalar DateTime
scalar SomeRandomScalar
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { PaginationResultResolvers } from './../../types.generated';
export const PaginationResult: PaginationResultResolvers = {
/* Implement PaginationResult resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { PayloadErrorResolvers } from './../../types.generated';
export const PayloadError: PayloadErrorResolvers = {
/* Implement PayloadError resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { GraphQLScalarType } from 'graphql';
export const SomeRandomScalar = new GraphQLScalarType({
name: 'SomeRandomScalar',
description: 'SomeRandomScalar description',
serialize: (value) => {
/* Implement logic to turn the returned value from resolvers to a value that can be sent to clients */
},
parseValue: (value) => {
/* Implement logic to parse input that was sent to the server as variables */
},
parseLiteral: (ast) => {
/* Implement logic to parse input that was sent to the server as literal values (string, number, or boolean) */
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { BookStore_NewResolvers } from './../../types.generated';
export const BookStore_New: BookStore_NewResolvers = {
/* Implement BookStore_New resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { TopicResolvers } from './../../types.generated';
export const Topic: Pick<TopicResolvers, 'bookStore_for_topic'> = {
/* Implement Topic resolver logic here */
bookStore_for_topic: () => {
/* Topic.bookStore_for_topic resolver is required because Topic.bookStore_for_topic exists but TopicMapper.bookStore_for_topic does not */
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { UserResolvers } from './../../types.generated';
export const User: Pick<UserResolvers, 'bookStore_4_user'> = {
/* Implement User resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
type BookStore_New {
id: ID!
}

extend type Topic {
bookStore_for_topic: BookStore_New
}

extend type User {
bookStore_4_user: BookStore_New
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* This file was automatically generated. DO NOT UPDATE MANUALLY. */
import type { Resolvers } from './types.generated';
import { BookStore_New } from './book-store_new/resolvers/BookStore_New';
import { topicCreate as Mutation_topicCreate } from './topic/resolvers/Mutation/topicCreate';
import { topicEdit as Mutation_topicEdit } from './topic/resolvers/Mutation/topicEdit';
import { PaginationResult } from './base/resolvers/PaginationResult';
import { PayloadError } from './base/resolvers/PayloadError';
import { Profile } from './user/resolvers/Profile';
import { me as Query_me } from './user/resolvers/Query/me';
import { topicById as Query_topicById } from './topic/resolvers/Query/topicById';
import { topicsCreatedByUser as Query_topicsCreatedByUser } from './topic/resolvers/Query/topicsCreatedByUser';
import { userByAccountName as Query_userByAccountName } from './user/resolvers/Query/userByAccountName';
import { SomeRandomScalar } from './base/resolvers/SomeRandomScalar';
import { profileChanges as Subscription_profileChanges } from './user/resolvers/Subscription/profileChanges';
import { Topic as book_store_new_Topic } from './book-store_new/resolvers/Topic';
import { Topic as topic_Topic } from './topic/resolvers/Topic';
import { Topic as user_Topic } from './user/resolvers/Topic';
import { TopicByIdResult } from './topic/resolvers/TopicByIdResult';
import { TopicCreateResult } from './topic/resolvers/TopicCreateResult';
import { TopicEditResult } from './topic/resolvers/TopicEditResult';
import { TopicsCreatedByUserResult } from './topic/resolvers/TopicsCreatedByUserResult';
import { User as user_User } from './user/resolvers/User';
import { User as book_store_new_User } from './book-store_new/resolvers/User';
import { UserResult } from './user/resolvers/UserResult';
import { DateTimeResolver } from 'graphql-scalars';
export const resolvers: Resolvers = {
Query: {
me: Query_me,
topicById: Query_topicById,
topicsCreatedByUser: Query_topicsCreatedByUser,
userByAccountName: Query_userByAccountName,
},
Mutation: {
topicCreate: Mutation_topicCreate,
topicEdit: Mutation_topicEdit,
},
Subscription: { profileChanges: Subscription_profileChanges },
BookStore_New: BookStore_New,
PaginationResult: PaginationResult,
PayloadError: PayloadError,
Profile: Profile,
SomeRandomScalar: SomeRandomScalar,
Topic: { ...book_store_new_Topic, ...topic_Topic, ...user_Topic },
TopicByIdResult: TopicByIdResult,
TopicCreateResult: TopicCreateResult,
TopicEditResult: TopicEditResult,
TopicsCreatedByUserResult: TopicsCreatedByUserResult,
User: { ...user_User, ...book_store_new_User },
UserResult: UserResult,
DateTime: DateTimeResolver,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { MutationResolvers } from './../../../types.generated';
export const topicCreate: NonNullable<
MutationResolvers['topicCreate']
> = async (_parent, _arg, _ctx) => {
/* Implement Mutation.topicCreate resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { MutationResolvers } from './../../../types.generated';
export const topicEdit: NonNullable<MutationResolvers['topicEdit']> = async (
_parent,
_arg,
_ctx
) => {
/* Implement Mutation.topicEdit resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { QueryResolvers } from './../../../types.generated';
export const topicById: NonNullable<QueryResolvers['topicById']> = async (
_parent,
_arg,
_ctx
) => {
/* Implement Query.topicById resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type { QueryResolvers } from './../../../types.generated';
export const topicsCreatedByUser: NonNullable<
QueryResolvers['topicsCreatedByUser']
> = async (_parent, _arg, _ctx) => {
/* Implement Query.topicsCreatedByUser resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { TopicResolvers } from './../../types.generated';
export const Topic: Pick<
TopicResolvers,
| 'createdAt'
| 'extendedTopicFieldInDifferentFileAndSameModule1'
| 'extendedTopicFieldInDifferentFileAndSameModule2'
| 'extendedTopicFieldInDifferentFileAndSameModule3'
| 'extendedTopicFieldInTheSameFileAndSameModule1'
| 'extendedTopicFieldInTheSameFileAndSameModule2'
| 'extendedTopicFieldInTheSameFileAndSameModule3'
| 'id'
| 'name'
| 'url'
> = {
/* Implement Topic resolver logic here */
extendedTopicFieldInDifferentFileAndSameModule1: () => {
/* Topic.extendedTopicFieldInDifferentFileAndSameModule1 resolver is required because Topic.extendedTopicFieldInDifferentFileAndSameModule1 exists but TopicMapper.extendedTopicFieldInDifferentFileAndSameModule1 does not */
},
extendedTopicFieldInDifferentFileAndSameModule2: () => {
/* Topic.extendedTopicFieldInDifferentFileAndSameModule2 resolver is required because Topic.extendedTopicFieldInDifferentFileAndSameModule2 exists but TopicMapper.extendedTopicFieldInDifferentFileAndSameModule2 does not */
},
extendedTopicFieldInDifferentFileAndSameModule3: () => {
/* Topic.extendedTopicFieldInDifferentFileAndSameModule3 resolver is required because Topic.extendedTopicFieldInDifferentFileAndSameModule3 exists but TopicMapper.extendedTopicFieldInDifferentFileAndSameModule3 does not */
},
extendedTopicFieldInTheSameFileAndSameModule1: () => {
/* Topic.extendedTopicFieldInTheSameFileAndSameModule1 resolver is required because Topic.extendedTopicFieldInTheSameFileAndSameModule1 exists but TopicMapper.extendedTopicFieldInTheSameFileAndSameModule1 does not */
},
extendedTopicFieldInTheSameFileAndSameModule2: () => {
/* Topic.extendedTopicFieldInTheSameFileAndSameModule2 resolver is required because Topic.extendedTopicFieldInTheSameFileAndSameModule2 exists but TopicMapper.extendedTopicFieldInTheSameFileAndSameModule2 does not */
},
extendedTopicFieldInTheSameFileAndSameModule3: () => {
/* Topic.extendedTopicFieldInTheSameFileAndSameModule3 resolver is required because Topic.extendedTopicFieldInTheSameFileAndSameModule3 exists but TopicMapper.extendedTopicFieldInTheSameFileAndSameModule3 does not */
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { TopicByIdResultResolvers } from './../../types.generated';
export const TopicByIdResult: TopicByIdResultResolvers = {
/* Implement TopicByIdResult resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { TopicCreateResultResolvers } from './../../types.generated';
export const TopicCreateResult: TopicCreateResultResolvers = {
/* Implement TopicCreateResult resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { TopicEditResultResolvers } from './../../types.generated';
export const TopicEditResult: TopicEditResultResolvers = {
/* Implement TopicEditResult resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import type { TopicsCreatedByUserResultResolvers } from './../../types.generated';
export const TopicsCreatedByUserResult: TopicsCreatedByUserResultResolvers = {
/* Implement TopicsCreatedByUserResult resolver logic here */
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
extend type Query {
topicById(id: ID!): TopicByIdPayload!
topicsCreatedByUser(
input: TopicsCreatedByUserInput!
): TopicsCreatedByUserPayload!
}

extend type Mutation {
topicCreate(input: TopicCreateInput!): TopicCreatePayload!
topicEdit(input: TopicEditInput!): TopicEditPayload!
}

type Topic {
id: ID!
name: String!
url: String
createdAt: DateTime!
}

extend type Topic {
extendedTopicFieldInTheSameFileAndSameModule1: Profile!
}

extend type Topic {
extendedTopicFieldInTheSameFileAndSameModule2: Profile!
extendedTopicFieldInTheSameFileAndSameModule3: Profile!
}

type TopicByIdResult {
result: Topic
}

union TopicByIdPayload = TopicByIdResult | PayloadError

input TopicsCreatedByUserInput {
userId: ID!
}

type TopicsCreatedByUserResult {
result: [Topic!]!
}

union TopicsCreatedByUserPayload = TopicsCreatedByUserResult | PayloadError

input TopicCreateInput {
name: String!
url: String
}

type TopicCreateResult {
result: Topic!
}

union TopicCreatePayload = TopicCreateResult | PayloadError

input TopicEditInput {
id: ID!
name: String!
url: String
}

type TopicEditResult {
result: Topic!
}

union TopicEditPayload = TopicEditResult | PayloadError
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export type TopicMapper = {
id: string;
name: string;
url: string | null;
creator: string;
createdAt: Date;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extend type Topic {
extendedTopicFieldInDifferentFileAndSameModule1: Topic!
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extend type Topic {
extendedTopicFieldInDifferentFileAndSameModule2: Topic!
extendedTopicFieldInDifferentFileAndSameModule3: Topic!
}
Loading

0 comments on commit ab6a9e7

Please sign in to comment.