This guide describes how to upgrade your GraphCommerce project files and its dependencies, while keeping your customizations.
In package.json, find your version:
// Example from package.json
{
"dependencies": {
//...
"@graphcommerce/next-ui": "6.1.0"
//...
}
}
Download a fresh copy of the repository:
git clone -b main https://github.com/graphcommerce-org/graphcommerce.git
Navigate to the /upgrade directory you've just created. Run the following
command, but replace OLD_VERSION
with your version of
@graphcommerce/next-ui
:
git diff -w --relative=examples/magento-graphcms "@graphcommerce/next-ui@OLD_VERSION" examples/magento-graphcms ':!examples/magento-graphcms/CHANGELOG.md' > changes.patch
Move the changes.patch
file from the /upgrade directory to the root of your
project.
Apply the patch to your project (It's recommended to apply changes on a new branch):
git apply --reject --ignore-whitespace --exclude=README.md changes.patch
If running the upgrade steps results in a package.json.rej
file and the diff
is large, it can be easier to manually update the package.json
file.
Compare your local /package.json with the example's
/upgrade/examples/magento-graphcms/package.json
you just downloaded and:
dependencies
with the example's dependencies
. Keep any
additional installed local dependencies and
remove PSP's your backend
doesn't support.devDependencies
with the example's devDependencies
resolutions
with the example's resolutions
After updating the package.json file, run the following to install the latest packages:
rm yarn.lock && yarn
Remove lock and install the dependenciesyarn codegen
Converts all .graphql files to typescript filesyarn dev
Run the appWhen you run git apply ...
(step 5), git will try and apply all the diffs from
the patch file to your project files. When applying a diff fails, a
reject ↗
.rej
file will be created for each file that could not be upgraded.
It can very well be that some files can't be updated automatically, because of modifications you made. The CLI will show you the location of these files, as well as the number of hunks:
Applying patch pages/_app.tsx with 2 rejects...
Rejected hunk #1.
Rejected hunk #2.
The suggested changes have to be reviewed manually (a diff tool can provide insight, but won't be able to apply diffs). Manually apply the suggested changes you want. Discard the .rej files of the suggested changes you don't want. Before you commit, make sure to delete all the .rej files:
find . -type f -name '*.rej' -delete
After resolving the diff issues, manually process upgrade instructions:
Run and validate your local environment:
yarn codegen
should run without errorsyarn tsc:lint
should run without errorsyarn dev
should run without errors