This repository was archived by the owner on Dec 8, 2021. It is now read-only.
  
  
  - 
                Notifications
    
You must be signed in to change notification settings  - Fork 54
 
The resolvers generates incorrect return values for array of string or null #467
Copy link
Copy link
Open
Description
Description
When the return type is [String]! in schema the generated resolver return type is incompatible
Steps to reproduce
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
}
- Graphqlgen version: 0.6.0-rc9
 - OS name and version: MacOS Mojave
 
bretthadley and maria-jabon
Metadata
Metadata
Assignees
Labels
No labels