Getting "Schema must contain uniquely named types but contains multiple types named" for a single type

See original GitHub issue

Hello, I have the following schema:

@ObjectType()
class Action {
  @Field(type => Skill, { nullable: true })
  skill?: Skill;
}

@ObjectType()
export class ActionResult {
  @Field(type => [Action])
  actions!: Action[];
  @Field({ nullable: true })
  count?: number
}

@ObjectType()
export class Skill {}

@Resolver(Action)
export class ActionResolver  extends BaseResolver {
  @Query(returns => ActionResult)
  async actions (@Args() args: ActionArgs, @Info() info){

  }

  @FieldResolver()
  async skill(@Root() action: Action) {
  }
}

@Resolver(Skill)
export class SkillResolver extends BaseResolver {
  @Query(returns => [Skill])
  async allSkills (){

  }
}

From this I generate a schema like this:

  return buildSchema({
    resolvers: [ActionResolver, SkillResolver],
    emitSchemaFile: { path: 'schema.graphql' },
  })

And I get the error:

UnhandledPromiseRejectionWarning: Error: Schema must contain uniquely named types but contains multiple types named "Skill".

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:45 (6 by maintainers)

github_iconTop GitHub Comments

143reactions
jonlambertcommented, Aug 28, 2019

This was a hard one to track down, with an annoying fix (Nest specific, not the fault of type-graphql). For anyone experiencing the same issue make sure to delete dist/ directory and run the app again.

78reactions
vlad-elagincommented, Nov 25, 2019

For anyone who is struggling with this issue and tried above recipes with no luck: try to implicitly give a name to your types. My issue was solved with following

@ObjectType('user')
export class User {

Note an arg that was passed to ObjectType

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: Schema must contain uniquely named types but ...
This error usually occurs if you have named two or more of your Object Types with the same name . For example,
Read more >
GraphQL schema basics
An object type contains a collection of fields, each of which has its own type. Two object types can include each other as...
Read more >
Types - GraphQL - Dgraph
How to use GraphQL types to set a GraphQL schema for the Dgraph database. Includes scalars, enums, types, interfaces, union, password, & geolocation...
Read more >
Schemas and Types - GraphQL
A GraphQL object type has a name and fields, but at some point those fields have to resolve to some concrete data. That's...
Read more >
Schema | Cloud Search API - Google Developers
Each object definition must be uniquely named within a schema. ... If the operator spans across different object types, this option has to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found