GraphQl 数组模式
GraphQl Array Schema
我有来自外部的回复 API
genre_ids: [0: 16, 1: 21, 2: 46];
在这一点上,我不知道如何为类似的东西定义模式。
不确定 0: 1: 2: 等是什么,但我假设它是数组中的索引。如果你想实现整数或 id 数组,你应该使用 GraphQL 修饰符。它称为 GraphQL 列表,您可以在 graphql-js 中在您的模式中执行类似的操作。
genreIds: {
type: new GraphQLList(GraphQLID),
resolve: () => {
// your external api call
return [ 16, 21, 46]
}
}
如果您想了解更多详情。我最近发布了 article on implementing arrays in GraphQL schema. Here is the full code 关于如何实现获取用户数组的文章。顺便提一句。不确定你想用这些 id 做什么,但是用 GraphQL 对象类型替换它并根据这些 id 获取流派列表是更好的模式架构。希望对你有帮助。
大卫
我有来自外部的回复 API
genre_ids: [0: 16, 1: 21, 2: 46];
在这一点上,我不知道如何为类似的东西定义模式。
不确定 0: 1: 2: 等是什么,但我假设它是数组中的索引。如果你想实现整数或 id 数组,你应该使用 GraphQL 修饰符。它称为 GraphQL 列表,您可以在 graphql-js 中在您的模式中执行类似的操作。
genreIds: {
type: new GraphQLList(GraphQLID),
resolve: () => {
// your external api call
return [ 16, 21, 46]
}
}
如果您想了解更多详情。我最近发布了 article on implementing arrays in GraphQL schema. Here is the full code 关于如何实现获取用户数组的文章。顺便提一句。不确定你想用这些 id 做什么,但是用 GraphQL 对象类型替换它并根据这些 id 获取流派列表是更好的模式架构。希望对你有帮助。
大卫