0
votes

I do not quite understand what the error even is to be able to tackle this problem. Checking server console also doesn't show any descriptive error. I have added all the necessary code that is related to this issue.

Here is the mutation:

mutation SaveTrials($event: ID!, $input: [ResultTrialsInputType!]!) {
    saveTrials(event: $event, results: $input) {
        results {
            id
            trials
        }
    }
}

I am using Graphene (Python) in backend but the types correspond to the following:

input ResultTrialsInputType {
    id: ID
    person: ID!
    trials: [String]
}

Here is the Python code if it matters:

class ResultTrialsInputType(graphene.InputObjectType):
    id = graphene.ID()
    person = graphene.ID(required=True)
    trials = graphene.List(graphene.String)

When I send data from the apollo using the mutation above, this is what is being sent to the API:

{
    "operationName": "SaveTrials",
    "variables": {
        "event": "207e9f27-be66-4564-9c28-ac92ec44235d",
        "input": [
            {
                "id": "8eb80b8b-c93a-44b1-9624-e75436c13780",
                "trials": [
                    "32.1",
                    "92.2",
                    "12.1",
                    "12.2",
                    "23.2",
                    ""
                ],
                "__typename": "ResultTrialsObjectType",
                "person": "a6f18ab5-df23-421e-b916-73e569bf73ad"
            }
        ]
    },
    "query": "mutation SaveTrials($event: ID!, $input: [ResultTrialsInputType!]!) {\n  saveTrials(event: $event, results: $input) {\n    results {\n      id\n      trials\n      __typename\n    }\n    __typename\n  }\n}\n"
}

Response for this query is an error about "__typename":

{
    "errors": [
        {
            "message": "Variable \"$input\" got invalid value [{\"__typename\": \"ResultTrialsObjectType\", \"person\": \"a6f18ab5-df23-421e-b916-73e569bf73ad\", \"id\": \"8eb80b8b-c93a-44b1-9624-e75436c13780\", \"trials\": [\"32.1\", \"92.2\", \"12.1\", \"12.2\", \"23.2\", \"\"]}].\nIn element #0: In field \"__typename\": Unknown field.",
            "locations": [
                {
                    "line": 1,
                    "column": 34
                }
            ]
        }
    ]
}

In anywhere else in my application where an input argument is not array of custom objects as expected. What is the deal here? Am I setting my input arguments in the wrong way? Or am I missing something here?

I tried to add __typename manually to the input type; however, nothing happened.

Thanks!

EDIT: Now that I am checking this out, for some reason __typename is displayed as ResultTrialsObjectType but it should be ResultTrialsInputType. How is this value being generated? Does Apollo generate it or does server generate it and Apollo fetches it?

1

1 Answers

0
votes

Your schema specifies that ResultTrialsInputType has three fields: id, person, trials. __typename is a special meta-field that signifies the type of an object -- it should not be added to the schema. In fact, any names that start with two underscores are reserved and should not be used for field names.

As the error indicates, the issue is that __typename is not a field that's specified for ResultTrialsInputType, but you're sending it anyway.

Apollo will automatically attach __typename to any selection sets in your request (not inputs or variable values). So a query like this:

query {
  foo {
    bar
  }
}

becomes:

query {
  foo {
    bar
    __typename
  }
}

Apollo needs the __typename for every Object returned in your response in order to effectively cache the response. However, this means any time you are working with a data object returned by Apollo, it will have __typename properties throughout its structure.

What this boils down to is that, generally speaking, you cannot and should not make a query, mutate the response and then turn around and use that as an input to another query or mutation.