Rust 如何向GraphQL Union类型的GraphQL结构添加字段?(铁锈和刺柏)

Rust 如何向GraphQL Union类型的GraphQL结构添加字段?(铁锈和刺柏),rust,graphql,juniper,Rust,Graphql,Juniper,我从中复制了简单的GraphQL联合示例 使用juniper::{graphql_union,GraphQLObject}; //我从JuniperGitbook上复制了以下内容 #[导出(GraphQLObject)] 结构人{ id:String, 家园星球:弦, } #[导出(GraphQLObject)] 结构机器人{ id:String, 主函数:字符串, } 枚举字符{ 人(人),, 机器人, } graphql_联盟!(字符:()其中标量=|和self |{ 实例_解析器:||{

我从中复制了简单的GraphQL联合示例

使用juniper::{graphql_union,GraphQLObject};
//我从JuniperGitbook上复制了以下内容
#[导出(GraphQLObject)]
结构人{
id:String,
家园星球:弦,
}
#[导出(GraphQLObject)]
结构机器人{
id:String,
主函数:字符串,
}
枚举字符{
人(人),,
机器人,
}
graphql_联盟!(字符:()其中标量=|和self |{
实例_解析器:||{
&Human=>match*self{Character::Human(ref h)=>Some(h),=>None},
&Droid=>match*self{Character::Droid(ref d)=>Some(d),=>None},
}
});
这很有效。但后来我尝试在GraphQLObject结构中使用我的新字段


//我自己加的
#[导出(GraphQLObject)]
结构电影{
主角:性格,
标题:字符串,
}
这给了我一个奇怪的错误:

error[E0277]: the trait bound `Character: juniper::types::base::GraphQLType<__S>` is not satisfied
  --> src/main.rs:24:10
   |
24 | #[derive(GraphQLObject)]
   |          ^^^^^^^^^^^^^ the trait `juniper::types::base::GraphQLType<__S>` is not implemented for `Character`
   |
   = help: consider adding a `where Character: juniper::types::base::GraphQLType<__S>` bound
   = note: required because of the requirements on the impl of `juniper::types::base::GraphQLType<__S>` for `&Character`
   = note: required because of the requirements on the impl of `juniper::executor::IntoResolvable<'_, __S, &Character, _>` for `&Character`
   = note: required by `juniper::executor::IntoResolvable::into`
error[E0277]:不满足特性绑定'Character:juniper::types::base::GraphQLType'
-->src/main.rs:24:10
|
24 |#[导出(图形对象)]
|^^^^^^^^^^^^^^^未为`字符'实现特性` juniper::types::base::GraphQLType'`
|
=帮助:考虑添加一个“WHOLD字符:Juniper::类型::Base:GracqLyType”绑定
=注意:由于对“`&Character”的“juniper::types::base::GraphQLType` impl”的要求,因此必需`

=注意:由于“juniper::executor::intosolvable”的impl上的要求,需要将
中的Scalar=
添加到
图形库中定义:

graphql\u union!(字符:()其中标量=|和self |{
实例_解析器:||{
&Human=>match*self{Character::Human(ref h)=>Some(h),=>None},
&Droid=>match*self{Character::Droid(ref d)=>Some(d),=>None},
}
});

这修复了错误。我在桌子上找到了这个。可能当前发布的文档已过期。

您需要将
where Scalar=
添加到您的
图形库中定义:

graphql\u union!(字符:()其中标量=|和self |{
实例_解析器:||{
&Human=>match*self{Character::Human(ref h)=>Some(h),=>None},
&Droid=>match*self{Character::Droid(ref d)=>Some(d),=>None},
}
});
这修复了错误。我在桌子上找到了这个。也许当前发布的文档已经过时了