Graphql UnionType
See original GitHub issueI’m submitting a…
[ ] Regression
[x?] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I try to integrate a UnionType with Graphql, but unfortunately without success.
I get the error message:
Either the SearchResult type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."
Expected behavior
A working UnionType with Graphql 😃
Minimal reproduction of the problem with instructions
I have already tried to solve the problem with a ResolveProperty named resolveType
inside of a resolver. But the function is not executed.
When I name the function __resolveType
I get the error message Name "__resolveType" must not begin with "__", which is reserved by GraphQL introspection.
the createUnionType function:
export const SearchResultUnion = createUnionType({
name: "SearchResult", // the name of the GraphQL union
types: [CPublicStore,CArticle, CService], // array of object types classes
});
My Search-ObjectType:
@ObjectType()
export class CSearch implements ISearch {
@Field(type => [SearchResultUnion]) source: (CArticle | CService | CPublicStore)[]
...
}
and the resolver which should resolve the source property:
@Resolver(of => CSearch)
export class SearchTransform implements ResolverInterface<CSearch>{
...
@ResolveProperty("__resolveType",()=>String)
__resolveType(obj) {
....
}
}
Environment
[System Information]
OS Version : Linux 4.15
NodeJS Version : v10.15.1
YARN Version : 1.12.3
[Nest Information]
platform-express version : 6.0.0
passport version : 6.0.0
graphql version : 6.0.2
swagger version : 3.0.2
common version : 6.0.0
core version : 6.0.0
Thank you
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Unions and interfaces - Apollo GraphQL Docs
Unions and interfaces are abstract GraphQL types that enable a schema field to return one of multiple object types. Union type.
Read more >GraphQL Unions – Customize your results!
Let's understand unions: Unions are abstract schema types. To define a union type, we declare which object types are included in the union....
Read more >Schemas and Types
Note that members of a union type need to be concrete object types; you can't create a union type out of interfaces or...
Read more >Unions
Read more about the GraphQL Union Type in the official GraphQL docs. Usage. Let's start by creating the object types from the example...
Read more >Class: GraphQL::UnionType
So, when you query, you must use fragment spreads to access fields. Examples: A union of object types. MediaUnion = GraphQL ...
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
It should be fixed in the @next version (
$ npm i @nestjs/graphql@next
). You will also have to update@nestjs/core
to 6.2.0 ($ npm i @nestjs/core@6.2.0
). Please, let me know if you face any issue.Okay, I found the problem. Is it possible that ResolveProperty does not work with a Union type? I have the following implementation:
but I get the following error:
"message": "Abstract type SearchResult must resolve to an Object type at runtime for field CSearch.source with value [{}], received \"undefined\". Either the SearchResult type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function."