小编jér*_*dol的帖子

如何使用GraphQL buildSchema的联合

以下是我使用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时是否可以使用联合?

graphql graphql-js

4
推荐指数
1
解决办法
1623
查看次数

标签 统计

graphql ×1

graphql-js ×1