【问题标题】:Schema @connection to a special fieldSchema @connection 到一个特殊的字段
【发布时间】:2019-05-14 12:00:15
【问题描述】:

我想将表格中的配置分配给响应。 答案的 ID 不在配置中。在答案中有一个名为exam_id 的字段,这个exam_id 是配置的ID

我有什么:

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
}

我想要什么:

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
}

当我请求答案时,我想要响应中的配置。 因此,对于每个exam_id,配置表中都有一个特殊的配置行。

【问题讨论】:

    标签: aws-amplify amplifyjs


    【解决方案1】:

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

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

    config: ExamConfig @connection(name: "ExamConfigs" keyField: "exam_id")

    希望这会有所帮助。

    【讨论】:

    • INFO: name: "examconfigs" 它不允许在我猜的名字中使用大写字母......所以我得到一个错误...但这是有效的 - 谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-04-10
    • 1970-01-01
    • 1970-01-01
    • 2020-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-31
    相关资源
    最近更新 更多