1

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...

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot, I edited my question to make things more clear.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.