Array of Objects Apollo Server and post from react

前端 未结 1 1932
北恋
北恋 2020-12-12 06:01

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 proble

相关标签:
1条回答
  • 2020-12-12 06:13

    You can only use input types for input (GraphQLInputObjectType) and object types for output (GraphQLObjectType). You are using Specials as both: As output type for the field specials in ShoppingItem and as input type in mutation argument specials. To do this you need two types. The reason for this is that output types (can) have resolvers (this is actually abstracted away from apollo server in your case). You will have to create two different types:

    type ShoppingItem {
        description: String
        specials: [Specials]
    }
    
    type Specials {
        description: String
        price: String
        qty: String
        saved: String
    }
    
    input SpecialsDraft {
        description: String
        price: String
        qty: String
        saved: String
    }
    
    type Mutation {
        saveNewItem(description: String!, specials: [SpecialsDraft]) : ShoppingItem
    }
    
    0 讨论(0)
提交回复
热议问题