graphql - Assigning a Type to a field in GraphQL Mutation
问题描述
In the example below I am trying to create a Creature in my database each creature has many attributes so I created an CreatureAttribute Type with many different required String and Int fields. How do I attach that Type to the Creature Type Mutation?
mutation{
createCreature(data: {
creature_name: "Drake"
creature_type: "Dragon"
creature_size: "Huge"
description: "description Text..."
habitat: "habitat text..."
combat: "combat text..."
additional_info: "additional info text..."
attributes: ********this is where I would like to bring in my CreatureAttributes Type********
)
{
creature_name
creature_type
description
habitat
combat
additional_info
attributes
}
}
Thank you for your answers in advance :)
解决方案
根据我的理解,您想创建一个关系“生物具有可能的属性”。所以属性应该接受数组,如下面的示例所示。
type Creature {
id: ID! @unique
creature_name: String!
creature_type: String!
creature_size: String!
description: String!
habitat: String!
combat: String!
additional_info: String!
attributes: [CreatureAttributes]!
}
type CreatureAttributes {
strength: Int!
health: Int!
stamina: Int!
mana: Int!
reaction: Int!
...}
参考 - https://graphql.org/learn/schema/#object-types-and-fields
推荐阅读
- java - 我的 Java 作业需要一些帮助,这是一个用于管理电话的简单程序
- c# - 从 ASP.NET (C#) 访问服务器证书
- java - InsufficientAuthenticationException:需要进行身份验证才能获取访问令牌(不允许匿名) - 在进行 ROPC 令牌请求时
- c - 在 foror 循环中使用逗号分隔变量 [C]
- react-native - 在抽屉导航中第二次单击项目时刷新页面内容
- html - 如何隐藏输入文件类型但仍显示上传的文件?
- postgresql - 使用 cloud sql 代理连接到 GCP Cloud SQL
- php - Kanboard 和反向代理认证
- asp.net-mvc - 得到 System.Threading.Tasks.Task`1[System.Int32] 错误
- python - 将列表转换为仅基于元组某些值的副本的集合