The @daffodil/driver/magento package configures the integration between your storefront and Magento 2/MageOS ecommerce platforms.
@daffodil/driver/magento provides fundamental configurations that other Daffodil packages use to interact with Magento-like platforms. Under the hood, this package configures the Apollo GraphQL client to query the Magento GraphQL API.
@daffodil/product via provideDaffMagentoCacheableOperationTypePolicies and PossibleTypes for Apollo's InMemoryCache.DaffDriverHttpClientCacheServiceInterfaceYou can easily configure CORS for Magento 2 using the graycoreio/magento2-cors package with the following configuration in your env.php:
<?php
return [
...otherConfig,
'system' => [
'default' => [
'web' => [
'graphql' => [
'cors_max_age' => 86400,
'cors_allow_credentials' => 1,
'cors_allowed_methods' => 'POST, OPTIONS, GET',
'cors_expose_headers' => 'X-Magento-Cache-Id',
'cors_allowed_headers' =>
'Content-Currency, Store, X-Magento-Cache-Id, X-Captcha, Content-Type, Authorization, DNT, TE',
// Daffodil
'cors_allowed_origins' => 'https://your-storefront-url.com,http://localhost:4200'
// Any
'cors_allowed_origins' => '*'
]
]
]
]
];
You can also configure CORS using Fastly, Varnish, Nginx, or any other tool that modifies HTTP responses.
However, you probably do not want/need CORS in production. While convenient during development, CORS introduces significant performance and security risks in production. Kristof Ringleff from Fooman explains why you should avoid CORS in production in detail. It's worth your time to make sure that you have understood this.
If you receive errors about GraphQL not being available, ensure that:
/graphql endpoint is accessiblegraycoreio/magento2-cors