eddeee888 / graphql-code-generator-plugins

List of GraphQL Code Generator plugins that complements the official plugins.
MIT License
51 stars 12 forks source link

[BUG] Issue with enum type mappers using `@apollo/federation` `buildSubgraphSchema` #312

Open tagleeson opened 3 months ago

tagleeson commented 3 months ago

Describe the bug In v 0.10.0, enum resolvers are automatically generated, but this doesn't seem to play nice with the buildSubgraphSchema function (at least from @apollo/federation v0.38.1). Ends up with an error similar to below:

TS2345: Argument of type
{   typeDefs: DocumentNode;   resolvers: Resolvers; }
is not assignable to parameter of type
DocumentNode | (DocumentNode | GraphQLSchemaModule)[] | LegacySchemaModule
Types of property resolvers are incompatible.
Type Resolvers is not assignable to type GraphQLResolverMap<any>
Property IntegrationsConnectionType is incompatible with index signature.
Type 'EnumResolverSignature<{ ValueOne?: any; ValueTwo?: any; }, ResolverTypeWrapper<"ValueOne" | "ValueTwo">>' is not assignable to type 'GraphQLScalarType<unknown, unknown> | { [enumValue: string]: string | number; } | { [fieldName: string]: GraphQLFieldResolver<any, any, any> | { requires?: string | undefined; resolve: GraphQLFieldResolver<...>; }; }'.
Type 'EnumResolverSignature<{ ValueOne?: any; ValueTwo?: any; }, ResolverTypeWrapper<"ValueOne" | "ValueTwo">>' is not assignable to type '{ [fieldName: string]: GraphQLFieldResolver<any, any, any> | { requires?: string | undefined; resolve: GraphQLFieldResolver<any, any, any>; }; }'.
Property ValueOne is incompatible with index signature.
Type 'ResolverTypeWrapper<"ValueOne" | "ValueTwo">' is not assignable to type 'GraphQLFieldResolver<any, any, any> | { requires?: string | undefined; resolve: GraphQLFieldResolver<any, any, any>; }'.
Type 'string' is not assignable to type 'GraphQLFieldResolver<any, any, any> | { requires?: string | undefined; resolve: GraphQLFieldResolver<any, any, any>; }'

To Reproduce Steps to reproduce the behavior: Using a graphql schema including an enum type, eg:

type Query {
  someTypeFetch: SomeType!
}

enum SomeEnum {
  ValueOne
  ValueTwo
}

type SomeType {
  someEnum: SomeEnum!
}

Create a corresponding typescript enum:

export enum SomeEnum {
  ValueOne = "ValueOne",
  ValueTwo = "ValueTwo"
}

With a yml config (simplified, might not be 100% correct):

schema: 'schema.graphql'
generates:
  output/schema:
    preset: '@eddeee888/gcg-typescript-resolver-files'
    watchPattern: '**/*.mappers.ts'
    presetConfig:
      typesPluginsConfig:
        federation: true
        enumValues:
          SomeEnum: "./types#SomeEnum"

Removing enumValues, and playing around with adding or removing mappers doesn't seem to change the outcome

Expected behavior Using a mapped enum works as expected

Additional context Reverting back to 0.9.2 resolves the issue