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

Refactor data fetching #1920

Open
wants to merge 23 commits into
base: canary
Choose a base branch
from
Open

Refactor data fetching #1920

wants to merge 23 commits into from

Conversation

paales
Copy link
Member

@paales paales commented May 4, 2023

Refactor the data fetching store to achieve a better abstraction.

Introduce enhanceStaticProps(original), enhanceServiceSideProps(original), enhanceStaticProps(original) functions which wrap the nextjs' default getStaticProps, getServerSideProps and getStaticPaths functions respectively.

This allows us to do quite a few things:

The enhance* methods leverage node.js' AsyncLocalStorage functionality to wrap all function calls in a storefrontContext. Which allows users to use storefrontConfig() without passing any arguments.

This means that we do not need to initialize the graphqlSsrClient() and graphqlSharedClient() with any arguments. Which in turn allows us to abstract away these methods to graphqlQuery(query, options) and graphqlQueryPassToClient(query, options) and move them to the library (because the extensibility is handled by plugins now #1915)

Other notable changes:

  • Created a split in packages for shared components and server only components where most packages will have a secondary /server export. e.g.: @graphcommerce/magento-product/server for methods are are meant to be only run on the server. (we might use import 'server-only' in these packages if nextjs supports it for the pages directory)

  • Removed legacyProductRoute configuration + removed the pages/product/* files + removed the ProductPage query. We're now fully migrated to the recent p/[url] route.

@changeset-bot
Copy link

changeset-bot bot commented May 4, 2023

⚠️ No Changeset found

Latest commit: 05f4d74

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

@vercel
Copy link

vercel bot commented May 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
graphcommerce ✅ Ready (Inspect) Visit Preview May 11, 2023 1:22pm

# Conflicts:
#	examples/magento-graphcms/pages/404.tsx
#	examples/magento-graphcms/pages/search/index.tsx
#	packages/graphql-mesh/package.json
#	packages/graphql/package.json
#	packages/magento-category/package.json
#	packages/magento-search/package.json
#	packages/magento-store/package.json
#	packages/next-ui/package.json
#	packagesDev/eslint-config/package.json
#	yarn.lock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant