Given this schema:
interface INode {
id: ID
}
type Todo implements INode {
id: ID
title: String!
}
type Query {
node(id: ID!): INode
}
Given this class:
export default class Todo {
constructor (public id: string, public title: string) { }
isTypeOf(value: any): Boolean {
return value instanceof Todo;
}
}
Given this resolver:
type NodeArgs = {
id: string
}
export const resolver = {
node: ({ id }: NodeArgs) => {
return new Todo('1', 'Todo 1');
}
}
When I call the query:
query {
node(id: "1") {
id
... on Todo {
title
}
}
}
Then I get the return below:
{
"errors": [
{
"message": "Abstract type INode must resolve to an Object type at runtime for field Query.node with value { id: \"1\", title: \"Todo 1\" }, received \"undefined\". Either the INode type should provide a \"resolveType\" function or each possible type should provide an \"isTypeOf\" function.",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"node"
]
}
],
"data": {
"node": null
}
}
As you can see, I've implemented the isTypeOf
function but I am still getting the error message.
What am I doing wrong?
Notes:
- I am using Typescript, express and express-graphql;
makeExecutableSchema
. However I have one concern. I'm trying to create a Relay Server andmakeExecutableSchema
is from Apollo. So far I know, Relay is a "pattern" and Apollo is a "framework" with different implementation. So my question is: Wouldn't be incorrect use both in the same solution? – Vice