fix(graphql): override nodetype tostrings for display #856
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #853
I found this simple workaround for the way that GraphQL treats enum values. Rather than creating some duplication within our internal GraphQL module that re-encodes all of the NodeType enums to their Kind strings, I simply add an override on the
toString()
method for all of the NodeType implementations that simply returns theKind
. GraphQL usestoString()
to serialize thenodeType
enum field, which displays the enum member's name by default, so this override is simple and effective and doesn't duplicate definitions.To test:
Query
http :8181/api/beta/graphql query=@graphql/root-node-query.graphql
Query
http :8181/api/v2.1/discovery
Compare the results of the
kind
/nodeType
fields of nodes, before and after this patch. Before you should see ex.REALM
/Realm
, whereas after they will both agree onRealm
.