-
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
PANGOLIN-3185 - New package for model: State
#440
Conversation
|
State
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 a lot for contributing! 🙌
In general the structure looks good but I noticed some minor things that should we improved.
export type TStateGraphql = TState & { | ||
__typename: 'State'; | ||
}; |
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 GraphQL type is a bit more complicated.
For example we prefer to use nameAllLocales
instead of name
, etc.
You can take Channel
as an example:
test-data/models/channel/src/types.ts
Lines 19 to 35 in d6ca721
export type TChannelGraphql = Omit< | |
TChannel, | |
// In GraphQL, we prefer to use `nameAllLocales` instead of `name`. | |
| 'name' | |
// In GraphQL, we prefer to use `descriptionAllLocales` instead of `description`. | |
| 'description' | |
// In GraphQL, the object shape is different. | |
| 'createdBy' | |
// In GraphQL, the object shape is different. | |
| 'lastModifiedBy' | |
> & { | |
__typename: 'Channel'; | |
createdBy: TClientLoggingGraphql; | |
lastModifiedBy: TClientLoggingGraphql; | |
nameAllLocales?: TLocalizedStringGraphql | null; | |
descriptionAllLocales?: TLocalizedStringGraphql | null; | |
}; |
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.
const generator = Generator<TStateDraft>({ | ||
fields: { | ||
key: fake((f) => f.lorem.slug(2)), | ||
type: 'LineItemState', |
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.
Shouldn't this be randomly generated as well?
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.
I'm assuming you're referring to type
? We ran into some fun issues with that conflicting with roles depending on what each were set at so setting it to LineItemState
prevented that.
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.
@jmcreasman This is one of the many topics that should still be ironed out for when usage picks up.
The general idea w/in the generators is that we kick out as much realistic data here as possible (there are gray areas).
The LineItemState
is very specific to our use case, so here we can def let it randomize. We can either create a simple change-history-data
preset, or you can override it w/in the state-creat.ts
resource file (e.g: const stateDraft = StateDraft.random() .type('LineItemState') .buildRest<TStateDraft>()
;)
@@ -0,0 +1,5 @@ | |||
import State from '../../builder'; | |||
|
|||
const withTypeLineItemState = () => State().type('LineItemState'); |
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.
didn't you say that this type corresponds with a specific role?
also, please don't forget to add a spec for this
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.
It does, it corresponds to role of return
which is what we set roles
to already. Unless we need to randomize roles
too? But I don't think that was mentioned in any of the feed back.
- pushed up the test -
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 the sake of symmetry, lets just randomize all fields, then create a preset to target the type & role combo platter.
d321a37
to
fec1765
Compare
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 also taking a stab at the graphql, you got it in a good place for the next person. It's def a bit more complex if you're not actively using it. A++
This PR consists of a new State folder with the following models: State/StateDraft