php - SilverStripe GraphQL - 查询具有后代的类型时出错
问题描述
尝试查询类型和后代时出现此错误:
"Fragment cannot be spread here as objects of type \"AppTestObject\" can never be of type \"AppTestChild\"."
我使用 recipe-core、admin、graphql 和 graphql-devtools(都是最新的)设置了一个测试安装,以在基本设置中进行测试。我创建了 2 个对象:
class TestObject extends DataObject {
private static $singular_name = "Test Object";
private static $plural_name = "Test Objects";
private static $table_name = "TestObject";
private static $db = [
'Title' => 'Varchar(255)'
];
}
class TestChild extends DataObject {
private static $singular_name = "Test Child";
private static $plural_name = "Test Children";
private static $table_name = "TestChild";
private static $db = [
'Title' => 'Varchar(255)'
];
}
并通过配置搭建简单的脚手架:
SilverStripe\GraphQL\Controller:
schema:
scaffolding:
types:
App\TestObject:
fields: [ID]
operations:
read: true
App\TestChild:
fields: [ID, Title]
operations:
read: true
我可以毫无问题地单独查询这些类型中的每一个。但是当我尝试TestChild
成为我的后代时,TestObject
我得到了上面的错误。这是我的查询示例:
query {
readAppTestObjects {
edges {
node {
...on AppTestChild {
Title
}
}
}
}
}
检查 graphiql 中架构的文档,在readAppTestObjects
引用后代下没有任何内容,尽管在 silverstripe/graphql 的文档中它说:
当读取具有暴露后代的类型时(例如读取 Page,当 RedirectorPage 也暴露时),返回类型是基类型和所有暴露后代的联合。此联合类型采用名称 {BaseType}WithDescendants。
解决方案
是的,这是 SilverStripe graphql 模块中的一个错误。你在做什么应该工作。
我相信修复程序已在https://github.com/silverstripe/silverstripe-graphql/pull/176进行,您可以在那里跟踪进度。也许尝试补丁并留下一些评论。
推荐阅读
- python - 如何防止在 PyYAML 中将八进制/十六进制/二进制隐式转换为 Int?
- c++ - 读取输入文件时忽略剩余的换行符和空格(C++)
- java - 如何更改仅满足条件的文本视图的颜色?
- string - sparklyr 将双精度转换为字符
- javascript - IIFE 中的变量可在全局范围内访问
- python - 在 Python 中使用汇总统计量绘制分面条形图
- python - 我在这个乒乓球比赛中做了一个边界,但是桨可以越过它。我该如何阻止它?
- python - 基于列条件将两行放入新列的相似性
- jupyter-notebook - 有一种方法可以隐藏滑块(ipywidgets)的值吗?
- amazon-web-services - IAM 政策不适用于 AWS MediaPackage