diff --git a/dev-test/codegen.ts b/dev-test/codegen.ts index 04584a36395..5e928a0009d 100644 --- a/dev-test/codegen.ts +++ b/dev-test/codegen.ts @@ -175,6 +175,9 @@ const config: CodegenConfig = { preset: 'graphql-modules', presetConfig: { baseTypesPath: 'types.ts', filename: 'generated.ts' }, plugins: ['typescript', 'typescript-resolvers'], + config: { + addInterfaceFieldResolverTypes: true, + }, }, './dev-test/star-wars/types.globallyAvailable.d.ts': { schema: './dev-test/star-wars/schema.json', diff --git a/dev-test/modules/interface/generated.ts b/dev-test/modules/interface/generated.ts new file mode 100644 index 00000000000..2735c1103fe --- /dev/null +++ b/dev-test/modules/interface/generated.ts @@ -0,0 +1,42 @@ +import * as Types from '../types.js'; +import * as gm from 'graphql-modules'; +export namespace InterfaceModule { + interface DefinedFields { + Flower: 'id' | 'species' | 'age' | 'color'; + Tree: 'id' | 'species' | 'age' | 'height'; + Plant: 'id' | 'species' | 'age'; + } + + export type Plant = Pick; + export type Flower = Pick; + export type Tree = Pick; + + export type FlowerResolvers = Pick; + export type TreeResolvers = Pick; + export type PlantResolvers = Pick; + + export interface Resolvers { + Flower?: FlowerResolvers; + Tree?: TreeResolvers; + } + + export interface MiddlewareMap { + '*'?: { + '*'?: gm.Middleware[]; + }; + Flower?: { + '*'?: gm.Middleware[]; + id?: gm.Middleware[]; + species?: gm.Middleware[]; + age?: gm.Middleware[]; + color?: gm.Middleware[]; + }; + Tree?: { + '*'?: gm.Middleware[]; + id?: gm.Middleware[]; + species?: gm.Middleware[]; + age?: gm.Middleware[]; + height?: gm.Middleware[]; + }; + } +} diff --git a/dev-test/modules/interface/types/plants.graphql b/dev-test/modules/interface/types/plants.graphql new file mode 100644 index 00000000000..ada7d83b432 --- /dev/null +++ b/dev-test/modules/interface/types/plants.graphql @@ -0,0 +1,19 @@ +interface Plant { + id: ID! + species: String! + age: Int! +} + +type Flower implements Plant { + id: ID! + species: String! + age: Int! + color: String! +} + +type Tree implements Plant { + id: ID! + species: String! + age: Int! + height: Float! +} diff --git a/dev-test/modules/types.ts b/dev-test/modules/types.ts index f516a7e65c6..197e0107224 100644 --- a/dev-test/modules/types.ts +++ b/dev-test/modules/types.ts @@ -46,6 +46,14 @@ export type DonationInput = { user: Scalars['ID']['input']; }; +export type Flower = Plant & { + __typename?: 'Flower'; + age: Scalars['Int']['output']; + color: Scalars['String']['output']; + id: Scalars['ID']['output']; + species: Scalars['String']['output']; +}; + export type Mutation = { __typename?: 'Mutation'; donate?: Maybe; @@ -64,6 +72,12 @@ export type Paypal = { url: Scalars['String']['output']; }; +export type Plant = { + age: Scalars['Int']['output']; + id: Scalars['ID']['output']; + species: Scalars['String']['output']; +}; + export type Query = { __typename?: 'Query'; articleById?: Maybe
; @@ -86,6 +100,14 @@ export type QueryUserByIdArgs = { id: Scalars['ID']['input']; }; +export type Tree = Plant & { + __typename?: 'Tree'; + age: Scalars['Int']['output']; + height: Scalars['Float']['output']; + id: Scalars['ID']['output']; + species: Scalars['String']['output']; +}; + export type User = { __typename?: 'User'; firstName: Scalars['String']['output']; @@ -183,6 +205,11 @@ export type ResolversUnionTypes<_RefType extends Record> = { PaymentOption: CreditCard | Paypal; }; +/** Mapping of interface types */ +export type ResolversInterfaceTypes<_RefType extends Record> = { + Plant: Flower | Tree; +}; + /** Mapping between all available schema types and the resolvers types */ export type ResolversTypes = { Article: ResolverTypeWrapper & { author: ResolversTypes['User'] }>; @@ -193,13 +220,16 @@ export type ResolversTypes = { >; DonationInput: DonationInput; Float: ResolverTypeWrapper; + Flower: ResolverTypeWrapper; ID: ResolverTypeWrapper; Int: ResolverTypeWrapper; Mutation: ResolverTypeWrapper>; PaymentOption: ResolverTypeWrapper['PaymentOption']>; Paypal: ResolverTypeWrapper; + Plant: ResolverTypeWrapper['Plant']>; Query: ResolverTypeWrapper>; String: ResolverTypeWrapper; + Tree: ResolverTypeWrapper; User: ResolverTypeWrapper< Omit & { paymentOptions?: Maybe> } >; @@ -216,13 +246,16 @@ export type ResolversParentTypes = { }; DonationInput: DonationInput; Float: Scalars['Float']['output']; + Flower: Flower; ID: Scalars['ID']['output']; Int: Scalars['Int']['output']; Mutation: Record; PaymentOption: ResolversUnionTypes['PaymentOption']; Paypal: Paypal; + Plant: ResolversInterfaceTypes['Plant']; Query: Record; String: Scalars['String']['output']; + Tree: Tree; User: Omit & { paymentOptions?: Maybe> }; }; @@ -256,6 +289,17 @@ export type DonationResolvers< sender?: Resolver; }; +export type FlowerResolvers< + ContextType = any, + ParentType extends ResolversParentTypes['Flower'] = ResolversParentTypes['Flower'] +> = { + age?: Resolver; + color?: Resolver; + id?: Resolver; + species?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type MutationResolvers< ContextType = any, ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation'] @@ -280,6 +324,16 @@ export type PaypalResolvers< __isTypeOf?: IsTypeOfResolverFn; }; +export type PlantResolvers< + ContextType = any, + ParentType extends ResolversParentTypes['Plant'] = ResolversParentTypes['Plant'] +> = { + __resolveType: TypeResolveFn<'Flower' | 'Tree', ParentType, ContextType>; + age?: Resolver; + id?: Resolver; + species?: Resolver; +}; + export type QueryResolvers< ContextType = any, ParentType extends ResolversParentTypes['Query'] = ResolversParentTypes['Query'] @@ -302,6 +356,17 @@ export type QueryResolvers< users?: Resolver>, ParentType, ContextType>; }; +export type TreeResolvers< + ContextType = any, + ParentType extends ResolversParentTypes['Tree'] = ResolversParentTypes['Tree'] +> = { + age?: Resolver; + height?: Resolver; + id?: Resolver; + species?: Resolver; + __isTypeOf?: IsTypeOfResolverFn; +}; + export type UserResolvers< ContextType = any, ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User'] @@ -316,9 +381,12 @@ export type Resolvers = { Article?: ArticleResolvers; CreditCard?: CreditCardResolvers; Donation?: DonationResolvers; + Flower?: FlowerResolvers; Mutation?: MutationResolvers; PaymentOption?: PaymentOptionResolvers; Paypal?: PaypalResolvers; + Plant?: PlantResolvers; Query?: QueryResolvers; + Tree?: TreeResolvers; User?: UserResolvers; };