I have the following schema:
type Name {
first: String
last: String
}
input NameInput {
first: String
last: String
}
type Address {
line1: String
line2: String
city: String
state: String
postalCode: String
}
input AddressInput {
line1: String
line2: String
city: String
state: String
postalCode: String
}
type Person {
id: String!
organization: String
name: Name
email: String
address: Address
phone: String
}
input PersonInput {
organization: String
name: NameInput
email: String
address: AddressInput
phone: String
}
Using VueApollo, I have the following query, which populates a form:
receiver: {
query: gql`{
receiver {
organization
name {
first
last
}
email
address {
line1
line2
city
state
postalCode
}
phone
}
}`
...
And this mutation, which takes as its argument the result of the query, possibly modified in a form:
this.$apollo.mutate({
mutation: gql`mutation($receiver: PersonInput!, $sender: PersonInput!) {
updateReceiver(person: $receiver) {
id
}
updateSender(person: $sender) {
id
}
}`,
variables: {
receiver,
sender
}
}).then((response) => {
...
The problem is that the query result includes a __typename
field which a) isn’t in the associated input objects and b) I don’t want to add to them. As such, it fails because the input object receives __typename
as an invalid property. What can I do about this?
I tried delete sender.__typename
. This threw Property __typename is non-configurable and can't be deleted
, which seems to indicate that the query result is frozen. Basically I need to get rid of __typename
before I pass the query result into the value used as the input object, and I’d rather not pass the parameters individually as these are complex and deeply-nested objects.
As an aside, do I really need these input types if the input and output types are identical? Name
, for instance, looks the same whether it is being read or written. Person
on the other hand doesn’t since the output includes an ID.
Thanks.