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

Expose parseGid and use it internally #845

Merged
merged 9 commits into from May 9, 2023
Merged

Expose parseGid and use it internally #845

merged 9 commits into from May 9, 2023

Conversation

frehner
Copy link
Contributor

@frehner frehner commented May 2, 2023

WHY are these changes introduced?

Currently we have 2 implementations of parseGid() in separate packages; one of them is a basic implementation, and one is more advanced. On top of that, there's still actually additional work we need to do to be able to parse complex GIDs (see this section on "Parameterized Global IDs" https://shopify.dev/docs/api/usage/gids#parameterized-global-ids) and it would be nice to implement that once and have everywhere updated.

Additionally, there's also a need to use that helper in some work I'm doing for https://github.com/Shopify/hydrogen-internal/issues/36 where I'll need to get the raw Shop ID (not the GID).

Maybe we should also consider parsing any params out of the ID and having them as a separate item in the returned object? For example: https://github.com/Shopify/quilt/blob/42b7dd366d60c0ad0e165e0dd526a4c6a6054046/packages/admin-graphql-api-utilities/src/index.ts#L28-L44

However, if this is actually too much headache, then I don't mind having two implementations. We can just update both at the same time or something. We can still expose parseGid() from hydrogen-react and hydrogen and use it all there, but keep the cli's version as-is.

WHAT is this pull request doing?

Single-sources parseId()

Post-merge steps

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • I've added or updated the documentation

Copy link
Contributor

@cartogram cartogram left a comment

Choose a reason for hiding this comment

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

I agree with this approach over the alternatives we discussed in Slack. Left a few initial comments, let me know when its ready for a closer look 🥇

packages/cli/src/lib/graphql.test.ts Show resolved Hide resolved
packages/hydrogen-react/src/parse-gid.doc.ts Outdated Show resolved Hide resolved
packages/hydrogen-react/src/parse-gid.doc.ts Show resolved Hide resolved
Co-authored-by: Matt Seccafien <matt.seccafien@shopify.com>
@github-actions github-actions bot had a problem deploying to preview May 3, 2023 20:26 Failure
@frehner frehner marked this pull request as ready for review May 3, 2023 20:29
@frehner
Copy link
Contributor Author

frehner commented May 3, 2023

Ok, I don't think we have to change cli's dependence on hydrogen-react from peer to dependency; I just needed to update turbo.json to ensure that hydrogen-react was built before cli-hydrogen could be built.

This is ready to go.

[edit] one moment while I validate docs, actually

@frehner
Copy link
Contributor Author

frehner commented May 3, 2023

Ah dang; tests are failing because cli now needs hydrogen-react to build. So... I can set it up so that hydrogen-react builds before the cli's tests, or we can just not worry about single-sourcing this function for now. (Or other ideas?)

Copy link
Contributor

@lordofthecactus lordofthecactus left a comment

Choose a reason for hiding this comment

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

Happy with this approach ✅

One pending question for me, is how much does this change the bundle size 🤔

.changeset/nervous-bears-look.md Outdated Show resolved Hide resolved
Co-authored-by: Daniel Rios <daniel.riospavia@shopify.com>
@frandiox
Copy link
Contributor

frandiox commented May 8, 2023

Ah dang; tests are failing because cli now needs hydrogen-react to build. So... I can set it up so that hydrogen-react builds before the cli's tests, or we can just not worry about single-sourcing this function for now. (Or other ideas?)

@frehner Maybe the CLI should use its own to avoid hard dependencies? I think we should consider even removing the peerDeps in the CLI that are just for types in virtual-routes (they should be devDeps because they're only useful to us) 🤔

I guess ideally we'd have a "common stuff" package where we import this kind of utility from. Maybe not even published, just a place to import things from and then they get bundled in each package. The final app bundle won't have 2 versions of this because the one in the CLI is not used in-app.

Note that hydrogen and hydrogen-react should use the same, I agree there 100%.

@frehner
Copy link
Contributor Author

frehner commented May 8, 2023

Maybe the CLI should use its own to avoid hard dependencies? I think we should consider even removing the peerDeps in the CLI that are just for types in virtual-routes (they should be devDeps because they're only useful to us) 🤔

Honestly that's kind of the direction I'm leaning towards right now -- just letting the cli have its own version.

As far as peer vs dev deps, I'm not sure I know enough context to understand which we should use; if they're only used for virtual-routes, and the developer never opens/edits virtual-routes on their own, and the TS compiler doesn't complain if the types aren't present for virtual-routes, then devdeps seems more correct.

@frandiox
Copy link
Contributor

frandiox commented May 9, 2023

Honestly that's kind of the direction I'm leaning towards right now -- just letting the cli have its own version.

Ok let's do that then 👍

As far as peer vs dev deps, I'm not sure I know enough context to understand which we should use; if they're only used for virtual-routes, and the developer never opens/edits virtual-routes on their own, and the TS compiler doesn't complain if the types aren't present for virtual-routes, then devdeps seems more correct.

Agree. We can test and change deps in another PR though, no need to block this one.

@frehner frehner merged commit 0a009a3 into 2023-04 May 9, 2023
10 checks passed
@frehner frehner deleted the parse-gid branch May 9, 2023 15:32
@jamalsoueidan
Copy link
Contributor

I wish you exposed parseGid so we can also use it in the project :)

@frandiox
Copy link
Contributor

@jamalsoueidan Yeah it's now exposed. It will be available in the next release 👍

@jamalsoueidan
Copy link
Contributor

Thank you

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.

None yet

5 participants