I'm using go on the server side with graphql, and angular6 with apollo on client side.
I'm trying to send the following object in mutation:
{
"deliveryId": 1,
"products": [{
"id": 3,
"quantity": 1
}],
"payment": {
"name": "kfir ozer",
"number": "4580 0307 6696 9445",
"expiry": "02 / 122",
"cvc": "332"
}
}
I paste this object to the following function to send it to the server:
addOrderInfo(order) {
return this.apollo.mutate({
mutation: gql `
mutation AddOrderInfo($order: Order!) {
addOrderInfo(order: $order) {
id
}
}
`,
variables: {
order
}
});
}
and now the server side..
this is how I configure the relevant types:
cartProduct: = graphql.NewInputObject(
graphql.InputObjectConfig {
Name: "CartProduct",
Fields: graphql.InputObjectConfigFieldMap {
"id": & graphql.InputObjectFieldConfig {
Type: graphql.Int,
},
"quantity": & graphql.InputObjectFieldConfig {
Type: graphql.Int,
},
},
},
)
payment: = graphql.NewInputObject(
graphql.InputObjectConfig {
Name: "CreditCardPayment",
Fields: graphql.InputObjectConfigFieldMap {
"name": & graphql.InputObjectFieldConfig {
Type: graphql.String,
},
"number": & graphql.InputObjectFieldConfig {
Type: graphql.String,
},
"expiry": & graphql.InputObjectFieldConfig {
Type: graphql.String,
},
"cvc": & graphql.InputObjectFieldConfig {
Type: graphql.String,
},
},
},
)
order: = graphql.NewInputObject(
graphql.InputObjectConfig {
Name: "Order",
Fields: graphql.InputObjectConfigFieldMap {
"deliveryId": & graphql.InputObjectFieldConfig {
Type: graphql.Int,
},
"payment": & graphql.InputObjectFieldConfig {
Type: payment,
},
"products": & graphql.InputObjectFieldConfig {
Type: graphql.NewList(cartProduct),
},
},
},
)
and this is how I set the mutation:
RootMutation: = graphql.NewObject(graphql.ObjectConfig {
Name: "Mutation",
Fields: graphql.Fields {
"addOrderInfo": & graphql.Field {
Type: ContactUsType,
Args: graphql.FieldConfigArgument {
"order": & graphql.ArgumentConfig {
Type: order,
},
},
Resolve: func(params graphql.ResolveParams)(interface {}, error) {
### here I created a breakpoint with intellij
### and noticed that the payment related values
### are empty strings
},
},
}
...
}
}
and on the server side... the params returns the proper data but the payment property
contains the expiry
, cvc
, name
and number
properties but they are an empty string instead of the actual values.
what am I missing?
thanks