So i'm trying to figure out how to pass an array of objects from a POST request to apollo server on AWS lambda.
I've checked this out but it's not the same problem
Array of objects convert into object of objects when I use Apollo
The post request looks like this...
api.post('query', { query : `mutation {saveNewItem(description: "${description}", specials: ${JSON.stringify(specials)}){name}}`})
// comment to get rid of silly scroll bar overlapping code
Schema looks like this...
const { gql } = require('apollo-server-lambda')
const typeDefs = gql`
type ShoppingItem {
description: String
specials: [Specials]
}
input Specials {
description: String
price: String
qty: String
saved: String
}
type Mutation {
saveNewItem(description: String!, specials: [Specials]) : ShoppingItem
}
`
example Specials looks like this...
[{ // Object One
description: "First One"
price: "1.00"
qty: "1"
saved: "false"
},{ // Object two
description: "Second One"
price: "1.00"
qty: "1"
saved: "false"
}]
The error I get currently is...
'Error: The type of ShoppingItem.specials must be Output Type but got: [Specials].',
'at assertValidSchema (/Users/me/Desktop/Projects/app/build/node_modules/graphql/type/validate.js:71:11)',
If I change it to a normal "type" it complains about it not being Input type.
I've also been through the apollo server docs and can't quite see what I'm doing wrong?
Please that as mentioned by Daniel in comments whilst technically the "duplicate" answer given is correct the information offered here is far more high quality and useful to people facing the problem(in my opinion)
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…