-
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
[Breaking]: architectural change to omit draft model __typename
creation
#478
Conversation
🦋 Changeset detectedLatest commit: 483b152 The changes in this PR will be included in the next version bump. This PR includes changesets to release 34 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 |
__typename
creation__typename
creation
@@ -17,12 +17,8 @@ export type TDivisionDraftBuilder = TBuilder<TDivisionDraft>; | |||
export type TCreateCompanyDraftBuilder = () => TCompanyDraftBuilder; | |||
export type TCreateDivisionDraftBuilder = () => TDivisionDraftBuilder; | |||
//BusinessUnitDraftGraphql is only scaffolding at this time | |||
export type TCompanyDraftGraphql = TCompanyDraft & { | |||
__typename: 'BusinessUnitDraft'; |
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.
For most of the models in this PR (save for Reference
, KeyReference
, and LocalizedString
), this was the relevant change. Remove __typename
from types.ts
, the generator, and ensure the type was safe all the way down to tests
…e and other draft __typenames, update snapshots
… draft __typenames, update snapshots
@@ -0,0 +1,28 @@ | |||
# 2. Exclude `__typename` from Draft GraphQL Models |
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.
Highlighting the ADR here for others to review 🔍
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.
🏩 The changes look very sane. I value taking the time taken for this approach! Especially the ADR addition.
The main question I guess now: breaking or not. I would rather be safe and make it a breaking release. WDYT? Consumers can still add a typename to drafts by adding __typename('foo')
I suppose?
Definitely comfortable labeling this as a breaking release considering the number of presets and files it touches. How do I go about doing that? To be honest consumers will likely have some difficulty tacking |
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.
Approving the approach, the documentation and the effort put into this! Many thanks ❤️
I won't be reviewing every single change though, I trust your abilities 😉
__typename
creation__typename
creation
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.
Super duper. So proud how far test-data came from a small idea to things falling into place.
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.
This is a huge improvement 👏
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 for such a massive work
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.
Awesome job Jai!
Summary
This PR makes sweeping changes to draft models, and introduces a proposed ADR we can agree on going forward.
The problem
Note that the changes in this PR only apply to draft models, not base models.
While
__typename
is technically part of the GraphQL schema for draft/input types, using it in practice has proven challenging. When we build draft GraphQL models and attempt to directly submit them as variables via the CoCo API, we are met with400
errors, because we build__typename
on many draft models internally.This has led to our team having to shim
omitDeep
functions in our sample data creation resolvers to strip__typename
, and casting to appropriate types, which is neither type safe nor ideal. I suspect that some consumers using draft models will have to do the same.Proposed solution
@ByronDWall had done great work trying to solve this here, however that raised questions about the very purpose of draft models.
We learned that models were originally designed without drafts, but as testing necessitated mocking requests, drafts were split out to represent input types (and as many of you know, GraphQL drafts may deviate wildly from their base REST representations, so splitting them out proved very maintainable).
Therefore, we're setting the precedent here that draft GraphQL models should adhere to their preferred utilitarian shape (which excludes
__typename
), rather than their strict schema representation. After all, this is a test data repository, and our form should follow function.There was one lingering problem with this:
Reference
,KeyReference
, andLocalizedString
did not have draft representations, and always included__typename
when built for GraphQL. They essentially had a "dual use case". If we allowed them to be built as-is, our live API requests would still fail.Therefore, they have been extended to include their respective
*Draft
representations (which exclude__typename
), and all points of implementation in draft models have been edited to use them.Further, we have removed
__typename
from those draft models that built it.Tests and snapshots have been updated accordingly.
TL;DR
Draft GraphQL models no longer have
__typename
. Please indicate if this will have downstream complications for your team. We are considering this a breaking change