SilverStripe GraphQL - 查询具有后代的类型时出错
SilverStripe GraphQL - error when querying types with descendants
我在尝试查询类型和后代时遇到此错误:
"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 的文档中它说:
When reading types that have exposed descendants (e.g. reading Page, when RedirectorPage is also exposed), the return type is a union of the base type and all exposed descendants. This union type takes on the name {BaseType}WithDescendants.
是的,这是 SilverStripe graphql 模块中的错误。你正在做的应该有效。
我相信修复程序正在 https://github.com/silverstripe/silverstripe-graphql/pull/176 进行中,您可以在那里关注进度。也许试试这个补丁并留下一些评论。
我在尝试查询类型和后代时遇到此错误:
"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 的文档中它说:
When reading types that have exposed descendants (e.g. reading Page, when RedirectorPage is also exposed), the return type is a union of the base type and all exposed descendants. This union type takes on the name {BaseType}WithDescendants.
是的,这是 SilverStripe graphql 模块中的错误。你正在做的应该有效。
我相信修复程序正在 https://github.com/silverstripe/silverstripe-graphql/pull/176 进行中,您可以在那里关注进度。也许试试这个补丁并留下一些评论。