AWS Amplify / Dynamodb - 对象数组作为字符串数组返回
AWS Amplify / Dynamo - array of objects coming back as array of strings
我在 react-app 中使用 react-select
作为 'multi-select' 来设置多种音乐流派。这会生成一个对象数组作为该输入的值。我正在使用 AWS Amplify/DynamoDB。
我不确定这是否是我的 schema.graphql(下图)、我如何处理/错误处理数据的问题,或者只是我的一般编码缺陷,但数据是这样发送的:
[{label='Afrobeat', value='Afrobeat'}, {label='Bikutsi', value='Bikutsi'}, {label='Benga', value='Benga'}]
和returns像这样(去掉单引号,在每个节点周围添加双引号):
["{label=Afrobeat, value=Afrobeat}", "{label=Bikutsi, value=Bikutsi}", "{label=Benga, value=Benga}"]
react-select
无法像那样处理数据,但我无法想象我必须做一些棘手的客户端处理才能使其正常工作。任何帮助将不胜感激。
我的 schema.graphql 此歌曲类型是:
type Song @model {
album: Album @connection(name: "AlbumSongs")
composer: String
description: String
duration: String
genre: [String!]! // is this the correct value for an array?
id: ID!
instruments: String
tags: [String!]!
title: String!
}
需要另一种类型 GenreOptions
以使其 return 作为对象数组而不是字符串数组。
类似于:
type GenreOptions {
label: String!
value: String! // also another option is to have an enum type
}
type Song @model {
genre: [GenreOptions!]!
}
那么查询将如下所示:
Song {
genre {
label
value
}
}
我在 react-app 中使用 react-select
作为 'multi-select' 来设置多种音乐流派。这会生成一个对象数组作为该输入的值。我正在使用 AWS Amplify/DynamoDB。
我不确定这是否是我的 schema.graphql(下图)、我如何处理/错误处理数据的问题,或者只是我的一般编码缺陷,但数据是这样发送的:
[{label='Afrobeat', value='Afrobeat'}, {label='Bikutsi', value='Bikutsi'}, {label='Benga', value='Benga'}]
和returns像这样(去掉单引号,在每个节点周围添加双引号):
["{label=Afrobeat, value=Afrobeat}", "{label=Bikutsi, value=Bikutsi}", "{label=Benga, value=Benga}"]
react-select
无法像那样处理数据,但我无法想象我必须做一些棘手的客户端处理才能使其正常工作。任何帮助将不胜感激。
我的 schema.graphql 此歌曲类型是:
type Song @model {
album: Album @connection(name: "AlbumSongs")
composer: String
description: String
duration: String
genre: [String!]! // is this the correct value for an array?
id: ID!
instruments: String
tags: [String!]!
title: String!
}
需要另一种类型 GenreOptions
以使其 return 作为对象数组而不是字符串数组。
类似于:
type GenreOptions {
label: String!
value: String! // also another option is to have an enum type
}
type Song @model {
genre: [GenreOptions!]!
}
那么查询将如下所示:
Song {
genre {
label
value
}
}