Hi there,
I'm getting this error Generated Schema cannot use Interface or Union types for execution when querying an apolloHapi endpoint with a graphql-tools generated schema that looks like this:
interface Searchable {
searchPreviewText: String!
}
type User implements Searchable {
searchPreviewText: String!
username: String!
}
type Movie implements Searchable {
searchPreviewText: String!
directory: String!
}
type Book implements Searchable {
searchPreviewText: String!
author: String!
}
type Query {
search(text: String!): [Searchable]!
}
I thought that maybe this comment meant that this was supported, but looking around it seems that it might work for mocking but that there's no implementation yet on the server side?
Is this on the roadmap for apollo server, or should this be work done upstream ?
Cheers,
Jun
The only thing you need to do is specify __resolveType: http://dev.apollodata.com/tools/graphql-tools/resolvers.html#addResolveFunctionsToSchema
The docs for this are pretty bad right now, but you can see an example here: https://github.com/graphql/graphql.github.io/blob/9d669d2fd26d52ed6b5a9160ae906fe4e298d00c/site/_core/swapiSchema.js#L381
If you have time, it would be great to add a section about it to this page: http://dev.apollodata.com/tools/graphql-tools/generate-schema.html
Or maybe a new page, just like we have "custom scalars".
Generated Schema cannot use Interface or Union types for execution
This error message is something produced by the core GraphQL.js package, and was added after graphql-tools was initially built. We should add some stuff to graphql-tools to override that message and point out the correct way.
It works! Thanks! Changing this to a documentation task.
If we're being really nitpicky it probably belongs here: https://github.com/apollostack/tools-docs
Most helpful comment
The only thing you need to do is specify
__resolveType: http://dev.apollodata.com/tools/graphql-tools/resolvers.html#addResolveFunctionsToSchemaThe docs for this are pretty bad right now, but you can see an example here: https://github.com/graphql/graphql.github.io/blob/9d669d2fd26d52ed6b5a9160ae906fe4e298d00c/site/_core/swapiSchema.js#L381
If you have time, it would be great to add a section about it to this page: http://dev.apollodata.com/tools/graphql-tools/generate-schema.html
Or maybe a new page, just like we have "custom scalars".