首页 > 解决方案 > Schema @connection to a special field

问题描述

I would like to assign configs from a table to responses. The ID of the answer is not in the configs. In the answer there is a field called exam_id and this exam_id is the ID of the config

what i have:

type Answer @model {
  id: ID!
  exam_id: String!
  user: User! @connection(name: "Answers")
  cycle: Int
  user_input: AWSJSON
  aivy_output: AWSJSON
  final_scores: AWSJSON
  score: Int
  rating: Int
  createdAt: String
  updatedAt: String
}

type ExamConfig @model { 
  id: ID!
  item_count: Int
  zscore_mean: AWSJSON
  zscore_deviation: AWSJSON
}

what i want:

type Answer @model {
  id: ID!
  exam_id: String! // = TOWER_OF_LONDON
  config: ExamConfig @connection  //BUT it have to be exam_id == ID from Config
  user: User! @connection(name: "Answers")
  cycle: Int
  user_input: AWSJSON
  aivy_output: AWSJSON
  final_scores: AWSJSON
  score: Int
  rating: Int
  createdAt: String
  updatedAt: String
}

type ExamConfig @model { 
  **** id: ID! // = TOWER_OF_LONDON
  item_count: Int
  zscore_mean: AWSJSON
  zscore_deviation: AWSJSON
}

when i request a Answer, than i want the config in the response. So for every exam_id is a special config row in the config Table.

标签: aws-amplifyamplifyjs

解决方案


您可以使用keyField连接注释的 来分配它将使用的特定字段。如果您使用的是 Amplify,请按照此处所述完成:https ://aws-amplify.github.io/docs/cli/graphql#connection

您的配置声明可能类似于:

配置:ExamConfig @connection(名称:“ExamConfigs”keyField:“exam_id”)

希望这可以帮助。


推荐阅读