我想定义以下查询
{
// return all individuals
individuals {
id
}
}
// return ONE individual by id
individuals(id:"123") {
id
}
}
Run Code Online (Sandbox Code Playgroud)
请注意,查询名称相同,只有参数不同.
今天,我发现的唯一解决方法是定义不同的查询名称.
如何定义多态查询?它甚至可能吗?
以下是我使用GraphQL架构字符串创建架构并将其附加到Express服务器的方法:
var graphql = require('graphql');
var graphqlHTTP = require('express-graphql');
[...]
return graphqlHTTP({
schema: graphql.buildSchema(schemaText),
rootValue: resolvers,
graphiql: true,
});
Run Code Online (Sandbox Code Playgroud)
这是模块的所有非常基本的用法.它运行良好,非常方便,直到我想定义一个联合:
union MediaContents = Photo|Youtube
type Media {
Id: String
Type: String
Contents: MediaContents
}
Run Code Online (Sandbox Code Playgroud)
我发现无法使这项工作,查询内容做它必须做的事情,返回正确的对象,但失败的消息Generated Schema cannot use Interface or Union types for execution
.
使用buildSchema时是否可以使用联合?