-
Notifications
You must be signed in to change notification settings - Fork 2
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
FCT 598: Omit __typename
field when building graphql draft models
#474
Conversation
…oddels when isGraphqlDraft option is passed to transformer
🦋 Changeset detectedLatest commit: 5a234a9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Is there any use-case for providing the draft I'm thinking about the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. This is really not ideal! Wondering if instead of leaking a "magic" boolean into the root type of model, we could add a removeFields
to any draft model here. It's a bit more work but then better located maybe?
@tdeekens Im certainly not against it, but I will have to look into how that would work a little more to understand it completely from my end |
Thanks. I'd value that. We'd mainly add a |
@tdeekens We already have a follow-up pr planned that will update types for drafts and do much of what you are asking, but the approach you are suggesting will not remove Deleting nested fields with |
@tdeekens This makes me wonder if there's value in typing |
Yes. That would be another more native option to test-data. If we prevent it from being added at all that solve the root cause nicely. |
Honest question - if we set the expectation that draft GraphQL entities never have Seems to me that if we don't build We could definitely audit instances of |
That won't work. It would be needed the latest for Apollo and it's client-side cache. So there, given we mock with msw, the typename is needed.
Overall this is the crux. As per GraphQL spec __typename is only used for Object, Interface, or Union. Not an Input type - what is passed with a mutation. If an Model was only used for an input type in a GraphQL schema. Then we could safely remove it. If however, drafts are also used for "unsaved" entities there is an issue. As in that case it would be a mocked response and flow into e.g Apollo's cache. If drafts are used as responses to GraphQL queries? Does this make sense? |
Toooootally makes sense now given that context, as draft models are effectively input types. So seems like the path forward is to create draft models for all "dual-use-case" models (like |
Yes to my current understanding. For context: we had a time in which a draft was a preset of an entity in which we unset the __typename using eg .__typename(undefined). Still as drafts and regular entities at times are structurally too different we decided to split them in two models. Given that, and the clear input oriented use case of drafts, we might just never specify a typename to be build. Unless of course there are other valid and good reasons to keep it. P.S.: Lets add ADRs to this repo to document decisions. |
When transforming fields for graphql draft models, built fields will add a
__typename
field, which is not a valid field to send in a draft and makes API's very sad and send us a 400.This PR implements an
isGraphqlDraft
option that can be passed to theTransformer
function. When this option is passed, all__typename
fields are removed from the transformed model so that the model can be used directly as a draft.For a more in depth walkthrough and explanation of this code, see this previous PR.