Avijit Dutta
Avijit Dutta

Reputation: 3861

GraphQL InputObjectType

What will be the input object type for this object variable?

let data = {
      companyId: "ABCD",
      source: "tally", 
      formDataId: "154",
      formData: [{
                    value: "02",
                    fieldPath: "voucher/sales"
                  },
                  {
                    value: "5o kgs",
                    fieldPath: "voucher/sales"
                  },
                  {
                    value: "soap"
                    fieldPath: "voucher/sales"
                  }],
      date: "2017-03-29"
 };

I'm confused with the value field because it has multiple types of data.

Upvotes: 1

Views: 363

Answers (1)

Locco0_0
Locco0_0

Reputation: 3500

The GraphQL input type for your data object could look like this:

...

`
input SalePropertyInput {
  value: String!
  relatedProperty: String!
}

input SaleInput {
  companyId: ID!
  source: String!
  properties: [SalePropertyInput!]!
}
`

...

But i think before you start the mutation you should map the values from the form to the data you really need on the server. E.g. you don't need the formDataId. And i suggest you check the form you're using on the client that the field path can be mapped to some sort of sale property. Which can be used to differentiate the input on the server

Upvotes: 1

Related Questions