Description
In GraphQL.js > 15.1.0 the ExecutionResult
now has an optional extensions
field, and I wonder how this should be best implemented in Python.
So far, ExtensionResult
has been a named tuple with the two fields data
and error
. Should we now:
- add a third field
extensions
to the named tuple? - or rather use a data class for
ExtensionResult
instead of a named tuple?
A problem with the first solution is that the named tuple now becomes a bit clumsy and verbose, the extensions
fille would then always be printed as part of the __repr__()
even if it is not used, and it would be mandatory in the __init__()
signature. Unfortunatelly, it's also not possible to overwrite the __init__()
method of named tuples to make the third argument optional.
A problem with the second solution is that real data classes are only available in Python 3.7, but we currently still support Python 3.6. It's not a big problem, since we could use a normal class and add the data class methods manually, or make use of the "dataclasses" package for Python 3.6.
A problem with both is that it will cause some backward incompatibility, e.g. in comparisons like
result == (data, errors)
or assignments with unpacking like
data, errors = result
We could solve the first by using a custom __eq__
method that would allow comparisons with 2- or 3-tuples. The second could be solved by making it an iterable with two elements. But then it would not be possible to do
data, errors, extensions = result
So probably better not make it an iterator, because "In the face of ambiguity, refuse the temptation to guess."
I would be glad to get some feedback from the community here.