Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

The resolvers generates incorrect return values for array of string or null #467

Open
sabith-th opened this issue Mar 12, 2019 · 0 comments

Comments

@sabith-th
Copy link

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
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant