-
-
Notifications
You must be signed in to change notification settings - Fork 140
Adding an extension field to the ExecutionResult #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
In Graphene we are using a dataclass port when used in Python < 3.6. I think w can still allow unpacking the way we were doing before data, errors = result |
I'm also leaning towards that solution. To allow the unpacking, we would need to make it appear like an iterable with 2 elements, right? It would be possible, but it feels a bit strange to return 2 elements, while astuple() would return 3. But maybe it's ok for the sake of simplicity and backward compatibility. |
Follow-up questions if we use a data class:
|
Would be good to link where EDIT 1 Looks like it is mentioned on the spec doc https://spec.graphql.org/draft/#sec-Response-Format Based on a quick read, I think the idea of using dataclass and provide a workaround to unpack it as 2-element tuple is the way to go as this |
Also make ExecutionResult a class instead of a NamedTuple, but do it as backward compatible as possible. Replicates graphql/graphql-js@fb042fc
@KingDarBoja, yes that's the right location and passage in the specs. I have converted it to a class now that can be unpacked and compared as a 2-tuple and a dict. I did not use a dataclass decorator, since the methods had to be created manually anyway to achieve that backward compatibility. Also dataclasses do not support slots when they have default elements. After this change. the full test suite still passed without any adaptation. |
In GraphQL.js > 15.1.0 the
ExecutionResult
now has an optionalextensions
field, and I wonder how this should be best implemented in Python.So far,
ExtensionResult
has been a named tuple with the two fieldsdata
anderror
. Should we now:extensions
to the named tuple?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
or assignments with unpacking like
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 doSo 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.
The text was updated successfully, but these errors were encountered: