Skip to content
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

Merged
merged 10 commits into from
Dec 6, 2023

Conversation

jmcreasman
Copy link
Contributor

@jmcreasman jmcreasman commented Nov 30, 2023

This PR consists of a new State folder with the following models: State/StateDraft

Copy link

changeset-bot bot commented Nov 30, 2023

⚠️ No Changeset found

Latest commit: fec1765

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@jmcreasman jmcreasman changed the title Pangolin 3185 state model PANGOLIN-3185 - New package for model: State Dec 1, 2023
@jmcreasman jmcreasman changed the title PANGOLIN-3185 - New package for model: State PANGOLIN-3185 - New package for model: State Dec 1, 2023
@jmcreasman jmcreasman marked this pull request as ready for review December 1, 2023 18:58
Copy link
Member

@emmenko emmenko left a 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.

models/state/src/generator.ts Outdated Show resolved Hide resolved
models/state/src/transformers.ts Outdated Show resolved Hide resolved
Comment on lines +7 to +9
export type TStateGraphql = TState & {
__typename: 'State';
};
Copy link
Member

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:

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;
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also technically there is transitions and transitionsRef.
image

I would keep using transitions, no need to implement transitionsRef.

However, the transitions field in the Rest definition is a list of references that can be expanded, but in GraphQL it's a list of State objects.

const generator = Generator<TStateDraft>({
fields: {
key: fake((f) => f.lorem.slug(2)),
type: 'LineItemState',
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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');
Copy link
Contributor

@valoriecarli valoriecarli Dec 5, 2023

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

Copy link
Contributor Author

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 -

Copy link
Contributor

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.

@jmcreasman jmcreasman force-pushed the PANGOLIN-3185-state-model branch from d321a37 to fec1765 Compare December 6, 2023 21:48
@valoriecarli valoriecarli self-requested a review December 6, 2023 21:55
Copy link
Contributor

@valoriecarli valoriecarli left a 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++

@valoriecarli valoriecarli merged commit 35ef55b into main Dec 6, 2023
3 checks passed
@valoriecarli valoriecarli deleted the PANGOLIN-3185-state-model branch December 6, 2023 22:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants