Open sabith-th opened 5 years ago
When the return type is [String]! in schema the generated resolver return type is incompatible
Schema:
type Episode { directors: [String]! guestStars: [String]! writers: [String]! } type Query { episodes: [Episode]! }
Generated Interface from graphqlgen
export interface Episode { directors: string[] | null; guestStars: string[] | null; writers: string[] | null; }
Generated Resolver
export const Episode: EpisodeResolvers.Type = { ...EpisodeResolvers.defaultResolvers };
Generated Default Resolvers
export namespace EpisodeResolvers { export const defaultResolvers = { directors: (parent: Episode) => parent.directors === undefined ? null : parent.directors, guestStars: (parent: Episode) => parent.guestStars === undefined ? null : parent.guestStars, writers: (parent: Episode) => parent.writers === undefined ? null : parent.writers }; export type DirectorsResolver = | (( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>) | { fragment: string; resolve: ( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>; }; export type GuestStarsResolver = | (( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>) | { fragment: string; resolve: ( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>; }; export type WritersResolver = | (( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>) | { fragment: string; resolve: ( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>; }; export interface Type { directors: | (( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>) | { fragment: string; resolve: ( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>; }; guestStars: | (( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>) | { fragment: string; resolve: ( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>; }; writers: | (( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>) | { fragment: string; resolve: ( parent: Episode, args: {}, ctx: Context, info: GraphQLResolveInfo ) => Array<string | null> | Promise<Array<string | null>>; }; } }
The following error is thrown
{ "resource": "/Documents/workspace/GraphQL/tvdb-graphql/src/generated/test-resolvers/Episode.ts", "owner": "typescript", "code": "2322", "severity": 8, "message": "Type '{ directors: (parent: Episode) => string[] | null; guestStars: (parent: Episode) => string[] | null; writers: (parent: Episode) => string[] | null; }' is not assignable to type 'Type'.\n Types of property 'directors' are incompatible.\n Type '(parent: Episode) => string[] | null' is not assignable to type '((parent: Episode, args: {}, ctx: any, info: GraphQLResolveInfo) => (string | null)[] | Promise<(string | null)[]>) | { fragment: string; resolve: (parent: Episode, args: {}, ctx: any, info: GraphQLResolveInfo) => (string | null)[] | Promise<...>; }'.\n Type '(parent: Episode) => string[] | null' is not assignable to type '(parent: Episode, args: {}, ctx: any, info: GraphQLResolveInfo) => (string | null)[] | Promise<(string | null)[]>'.\n Type 'string[] | null' is not assignable to type '(string | null)[] | Promise<(string | null)[]>'.\n Type 'null' is not assignable to type '(string | null)[] | Promise<(string | null)[]>'.", "source": "ts", "startLineNumber": 6, "startColumn": 14, "endLineNumber": 6, "endColumn": 21 }
Description
When the return type is [String]! in schema the generated resolver return type is incompatible
Steps to reproduce
Schema:
Generated Interface from graphqlgen
Generated Resolver
Generated Default Resolvers
The following error is thrown