gpt4 book ai didi

indexing - 如何在 AWS-amplify graphql 模式中通过非主键查询

转载 作者:行者123 更新时间:2023-12-05 07:21:03 24 4
gpt4 key购买 nike

我在 aws-amplify、appsync 中有一个 graphql 架构。

我的模式是:

type Project 
@model
{
id: ID!
project_number: String!
name: String!
architect: String!
interfaces: [Interface] @connection(name: "ProjectInterfaces")

}
type Interface
@model
{
id: ID!
interface_name: String!
version: String!
release: String!
source_feature: String!
MFT_feature_id: String!
state: String!
source_application: String!
source_env: String!
source_go_live: String!
source_payload: String!
source_payload_format: String!
source_payload_volume: String!
source_protocol: String!
target_application: String!
target_env: String!
target_go_live: String!
target_payload: String!
target_payload_format: String!
target_payload_volume: String!
target_protocol: String!
frequency: String!
authentication: String!
payload_security: String!
transport_security: String!
network_paths: String!
project: Project @connection(name: "ProjectInterfaces")
}

我想知道我是否可以通过项目编号而不是 id 来搜索项目接口(interface)。我在 project_name 上添加了一个索引,但它似乎不起作用。我当前的查询是

query GetProject {
getProject(project_number:"P200") {
name
architect
interfaces{
items{
interface_name
version
release
source_feature
MFT_feature_id
state
source_application
source_env
source_go_live
source_payload
source_payload_format
source_payload_volume
source_protocol
target_application
target_env
target_go_live
target_payload
target_payload_format
target_payload_volume
target_protocol
frequency
authentication
payload_security
transport_security
network_paths
}
}
}
}

如果可行,请告诉我。我想要它,这样我就可以按项目名称搜索,然后从界面中获取所有详细信息。

最佳答案

因此,根据 Amplify 文档,您必须在要查询的字段上添加 @index。我已经更新了您的项目模型,以便在 project_number 字段上有一个索引。

type Project 
@model
{
id: ID!
project_number: String! @index(name: "byProjectName", queryField: "projectByNumber", sortKeyFields: ["id"])
name: String!
architect: String!
interfaces: [Interface] @connection(name: "ProjectInterfaces")
}

然后按project_number查询,使用索引中queryField(projectByNumber)中设置的查询名称:

query projectByNumber($projectNumber: String!) {
projectByNumber(project_number: $projectNumber) {
items {
id
project_number
name
architect
...
}
}
}

请查看按员工姓名查询员工详细信息 下的文档以更好地理解:https://docs.amplify.aws/cli/graphql/examples-and-solutions/#2-query-employee-details-by-employee-name

关于indexing - 如何在 AWS-amplify graphql 模式中通过非主键查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57152911/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com