Getting "Schema must contain uniquely named types but contains multiple types named" for a single type
See original GitHub issueHello, 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:
- Created 4 years ago
- Reactions:6
- Comments:45 (6 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.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
Note an arg that was passed to ObjectType