问题描述
我的Nodejs Apollo Server的以下JSON输出:
attributes: [ { id: 8, name: 'Size', position: 0, visible: true, variation: true, options: [Array] } ],现在我想为此创建一个GraphQL方案. 我可以访问像ID,位置,可见的所有项目.但是我无法访问的选项.
如何为此编写GraphQL方案? 当前方案是:
const ProductAttributes = ` type ProductAttributes { id: Int! name: String! position: String! visible: Boolean! Variation: Boolean! // todo Options: [array] ? } `;
我发现选项数组看起来像这样,但没有键分配给它:
[ { id: 8, name: 'Size', position: 0, visible: true, variation: true, options: [ 'L32 W35', 'L32 W36', 'L32 W37', 'L32 W38', 'L28 W22', 'L28 W23', 'L28 W24', 'L28 W25', 'L32 W34' ] } ]
我必须用graphql分配一个关键吗?或者我必须在我的nodejs ajax请求中执行此操作吗?
e.g .:选项:{ 名称:'l32 w35', 名称:'L32 W36'等...
推荐答案
如果[array]是对象的数组,您需要执行此操作.
` type ProductAttributes { id: Int! name: String! position: String! visible: Boolean! Variation: Boolean! options: [String!] } `
如果[array]是 array 的数组,则在每个最后一个内部数组中,都应按照上面的对象或字符串进行.您可以在最后一个阵列中处理这些步骤. 现在在您的字符串数组中,因此您可以使用direct string 类型.
问题描述
I have the following JSON output from my NodeJS Apollo server:
attributes: [ { id: 8, name: 'Size', position: 0, visible: true, variation: true, options: [Array] } ],
Now I want to create a graphql scheme for this. I can access all the items like id, position, visible.. but the options I can't access.
How can I write the graphql scheme for this? Current scheme is:
const ProductAttributes = ` type ProductAttributes { id: Int! name: String! position: String! visible: Boolean! Variation: Boolean! // todo Options: [array] ? } `;
I found out the options array looks like this but no key is assigned to it:
[ { id: 8, name: 'Size', position: 0, visible: true, variation: true, options: [ 'L32 W35', 'L32 W36', 'L32 W37', 'L32 W38', 'L28 W22', 'L28 W23', 'L28 W24', 'L28 W25', 'L32 W34' ] } ]
Do I have to assign a key to this with GraphQL ? or do I have to do this in my NodeJS ajax request?
e.g.: options: { name: 'L32 W35', name: 'l32 W36', etc...
推荐答案
If [Array] is array of object you need to do that.
` type ProductAttributes { id: Int! name: String! position: String! visible: Boolean! Variation: Boolean! options: [String!] } `
If [Array] is an array of the array then in every last inner array should object or string take as above. And you can process these steps till the last array. Now in your case array of string so you can use direct String type.