New major release changes #965
Pinned
patzick
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
After extensive testing and feedback, we're in the final stage of the major release. This is the updated content of #471, and now we're in the polishing stage, which will be a major bump for most of the packages.
In the down below, we're heaving the set of features:
Overriding composables
Composables are one of the main features of the Composable Frontends. They are responsible for the logic of the application. We're introducing a new way of extending and overriding composables. With the new changes, you can:
useCart
will replaceuseCart
inuseAddToCart
composable. This gives maximum flexibility but also the responsibility - you can make things and break things, so be careful.Product
type inuseProduct
composable and across the whole application. This is a big step towards customisation and flexibility.Steps for migration
@shopware-pwa/composables-next
→ search for it in code and removetype
imports likeNotification
BoxLayout
DisplayMode
etc., update imports in the following pattern: exampleimport type { BoxLayout, DisplayMode } from "@shopware-pwa/composables-next";
package.json
- change package"@shopware-pwa/api-client"
to new API client"@shopware/api-client"
. Remove the old package.nuxt.config.ts
in nuxt configshopwareEndpoint
now needs to point exactly to the store API. Thanks to this whole URL could also be available behind a proxy. Example change:shopwareEndpoint: "https://demo-frontends.shopware.store/",
→shopwareEndpoint: "https://demo-frontends.shopware.store/store-api/",
nuxt.config.ts
- remove@shopware-pwa/cms-base
frommodules
arraynuxt.config.ts
- add nuxt layers of composables and cms - add lineextends: ["@shopware-pwa/composables-next/nuxt-layer", "@shopware-pwa/cms-base"],
Adaptation of the new API Client
The new API Client package is in the updated shape. All usages of the old client has been replaced.
With the new package, you can:
Steps for migration
@shopware-pwa/api-client
in your codeapiInstance
toapiClient
fromuseShopwareContext
. Example:const { apiInstance } = useShopwareContext();
→const { apiClient } = useShopwareContext();
@shopware-pwa/api-client
. With the code auto-completion, it should be very straightforward:so for example, fetching wishlist products from
becomes:
@shopware-pwa/api-client
Another examples
Newsletter confirmation:
into:
Handwritten requests via
invokeGet example:
into
remember - we always have your back with type support
also with all the parameters required (and optional) in request
Error handling
With the new API client Error handling is also improved. You can log errors with descriptive messages and also see more informational Errors.
The old way of handling API client errors was similar to this:
the new way checks the instance of the error and helps you with the types
you can also console that error while developing so you’d get a clear error message. More info → https://www.npmjs.com/package/@shopware/api-client#error-handling
Overriding types
In order to have full control over your types we provided a possibility to override them. This is especially useful when you want to add some custom fields to the schema, change the type of the field, or there is some error in the OpenAPI schema, and you need to make a quick fix.
in the root of your project, add
shopware.d.ts
file:Read on how to write custom types in the documentation of
showpare/api-gen
package.Server routes changes
In vue-demo store, we added a sitemap builder. This also requires adjustments for the new API client.
apiBuilder.ts
frominto
into
Remove dependency from
@shopware-pwa/types
Types are becoming yours to have. For specific versions, overrides. Current types are changed under the hood and deprecated. It should all still work for your project, but these are the recommended steps of migration:
@shopware-pwa/types
import type { Schemas } from "#shopware";
and then replace used entity. Example transitions:you have full auto-completion for all the schema types from your API instance:
Pure Vite application
This step is for someone who uses pure Vite application, without Nuxt modules, etc.
@shopware-pwa/api-client
to@shopware/api-client
apiClient.ts
file with your API client definition, for examplemain.ts
fileimports.d.ts
file with contentadd
shopware.d.ts
file with content from ## Overriding typesedit the vite config file, add
resolve.alias
config:tsconfig.json
file addcompilerOptions.paths
:Troubleshooting
apiClient
hasany
typewhen facing this problem, your IDE probably didn’t refresh the types properly. You can help a bit by restarting TypeScript and Vue Server. Just hit cmd+shift+p in VS code and pick the Restart TS Server option.
apiClient
is not completing my typesdo the same as
apiClient has any type
if that didn’t help - add
shopware.d.ts
file and restart ts server againno type support and code completion
If previous steps didn't work - in
tsconfig.json
, check thatmoduleResolution
is set tonode
(before it was bundler). This can cause a problem with the exported Types (see) for the new API Client. We'll investigate this topic more in the futureWhat's next?
Track the release progress in the milestone as it will be updated in upcoming days with the polishing PRs.
Beta Was this translation helpful? Give feedback.
All reactions