Skip to content

Commit

Permalink
Merge pull request #2299 from graphcommerce-org/feature/GCOM-1383-con…
Browse files Browse the repository at this point in the history
…firm-email

Forward compatibility functionality so we can implement 2.4.7 features without having them available in the schema
  • Loading branch information
paales authored Jun 21, 2024
2 parents df7adae + 2aa8764 commit 41068f6
Show file tree
Hide file tree
Showing 40 changed files with 624 additions and 60 deletions.
5 changes: 5 additions & 0 deletions .changeset/purple-crabs-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/next-config": patch
---

Solve an issue where an env variable wouldn't be coerced to a Number if a Config.graphqls value is defined as an Int/Float
5 changes: 5 additions & 0 deletions .changeset/swift-fireants-hear.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@graphcommerce/magento-graphql": patch
---

Added a magentoVersion configuration value to be able to differentiate features based on the Magento version
6 changes: 6 additions & 0 deletions docs/framework/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ GraphQL Magento endpoint.
Examples:
- https://magento2.test/graphql

#### magentoVersion: number (required)

Version of the Magento backend.

Values: 245, 246, 247 for Magento 2.4.5, 2.4.6, 2.4.7 respectively.

#### storefront: [GraphCommerceStorefrontConfig](#GraphCommerceStorefrontConfig)[] (required)

All storefront configuration for the project
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/dist/bin/mesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async function cleanup() {
}
const main = async () => {
const conf = (await (0, findConfig_1.findConfig)({}));
const graphCommerce = (0, next_config_1.loadConfig)(root);
// We're configuring a custom fetch function
conf.customFetch = require.resolve('@graphcommerce/graphql-mesh/customFetch');
conf.serve = { ...conf.serve, endpoint: '/api/graphql' };
Expand All @@ -72,8 +73,13 @@ const main = async () => {
conf.additionalTypeDefs.push('**/*.graphqls');
const deps = (0, next_config_1.resolveDependenciesSync)();
const packages = [...deps.values()].filter((p) => p !== '.');
const mV = graphCommerce.magentoVersion ?? 246;
(0, next_config_1.packageRoots)(packages).forEach((r) => {
conf.additionalTypeDefs.push(`${r}/**/*.graphqls`);
const alsoScan = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254]
.filter((v) => v > mV)
.map((v) => `${r}/schema-${v}/**/*.graphqls`);
conf.additionalTypeDefs.push(`${r}/*/schema/**/*.graphqls`);
conf.additionalTypeDefs.push(...alsoScan);
});
if (!conf.serve)
conf.serve = {};
Expand All @@ -87,7 +93,7 @@ const main = async () => {
},
},
];
const yamlString = (0, next_config_1.replaceConfigInString)(yaml_1.default.stringify(conf), (0, next_config_1.loadConfig)(root));
const yamlString = (0, next_config_1.replaceConfigInString)(yaml_1.default.stringify(conf), graphCommerce);
await node_fs_1.promises.writeFile(tmpMeshLocation, yamlString);
// Reexport the mesh to is can be used by packages
await node_fs_1.promises.writeFile(`${meshDir}/.mesh.ts`, `export * from '${relativePath.split(node_path_1.default.sep).join('/')}.mesh'`, { encoding: 'utf8' });
Expand Down
13 changes: 10 additions & 3 deletions packages/cli/src/bin/mesh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { promises as fs } from 'node:fs'
import path from 'node:path'
import { exit } from 'node:process'
import {
isMonorepo,
loadConfig,
packageRoots,
replaceConfigInString,
Expand Down Expand Up @@ -52,6 +51,7 @@ async function cleanup() {

const main = async () => {
const conf = (await findConfig({})) as YamlConfig.Config
const graphCommerce = loadConfig(root)

// We're configuring a custom fetch function
conf.customFetch = require.resolve('@graphcommerce/graphql-mesh/customFetch')
Expand Down Expand Up @@ -83,8 +83,15 @@ const main = async () => {

const deps = resolveDependenciesSync()
const packages = [...deps.values()].filter((p) => p !== '.')

const mV = graphCommerce.magentoVersion ?? 246
packageRoots(packages).forEach((r) => {
conf.additionalTypeDefs.push(`${r}/**/*.graphqls`)
const alsoScan = [245, 246, 247, 248, 249, 250, 251, 252, 253, 254]
.filter((v) => v > mV)
.map((v) => `${r}/schema-${v}/**/*.graphqls`)

conf.additionalTypeDefs.push(`${r}/*/schema/**/*.graphqls`)
conf.additionalTypeDefs.push(...alsoScan)
})

if (!conf.serve) conf.serve = {}
Expand All @@ -99,7 +106,7 @@ const main = async () => {
},
]

const yamlString = replaceConfigInString(yaml.stringify(conf), loadConfig(root))
const yamlString = replaceConfigInString(yaml.stringify(conf), graphCommerce)
await fs.writeFile(tmpMeshLocation, yamlString)

// Reexport the mesh to is can be used by packages
Expand Down
7 changes: 7 additions & 0 deletions packages/magento-graphql/Config.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ extend input GraphCommerceConfig {
- https://magento2.test/graphql
"""
magentoEndpoint: String!

"""
Version of the Magento backend.
Values: 245, 246, 247 for Magento 2.4.5, 2.4.6, 2.4.7 respectively.
"""
magentoVersion: Int!
}

extend input GraphCommerceStorefrontConfig {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
input CartAddressInput {
vat_id: String
}

interface CartAddressInteface {
vat_id: String
}

type ShippingCartAddress implements CartAddressInterface {
vat_id: String
}

type BillingCartAddress {
vat_id: String
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type Mutation {
"""
Delete customer account
"""
deleteCustomer: Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
interface OrderItemInterface {
"""
The selected gift message for the order item
"""
gift_message: GiftMessage
}

type OrderItem {
"""
The selected gift message for the order item
"""
gift_message: GiftMessage
}

type BundleOrderItem {
"""
The selected gift message for the order item
"""
gift_message: GiftMessage
}

type DownloadableOrderItem {
"""
The selected gift message for the order item
"""
gift_message: GiftMessage
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type SelectedShippingMethod {
price_excl_tax: Money
price_incl_tax: Money
}
71 changes: 71 additions & 0 deletions packages/magento-graphql/schema-247/Cart-itemsV2.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
type CartItems {
"""
An array of products that have been added to the cart.
"""
items: [CartItemInterface]!
"""
Metadata for pagination rendering.
"""
page_info: SearchResultPageInfo
"""
The number of returned cart items.
"""
total_count: Int!
}

"""
Specifies the field to use for sorting quote items
"""
enum SortQuoteItemsEnum {
ITEM_ID
CREATED_AT
UPDATED_AT
PRODUCT_ID
SKU
NAME
DESCRIPTION
WEIGHT
QTY
PRICE
BASE_PRICE
CUSTOM_PRICE
DISCOUNT_PERCENT
DISCOUNT_AMOUNT
BASE_DISCOUNT_AMOUNT
TAX_PERCENT
TAX_AMOUNT
BASE_TAX_AMOUNT
ROW_TOTAL
BASE_ROW_TOTAL
ROW_TOTAL_WITH_DISCOUNT
ROW_WEIGHT
PRODUCT_TYPE
BASE_TAX_BEFORE_DISCOUNT
TAX_BEFORE_DISCOUNT
ORIGINAL_CUSTOM_PRICE
PRICE_INC_TAX
BASE_PRICE_INC_TAX
ROW_TOTAL_INC_TAX
BASE_ROW_TOTAL_INC_TAX
DISCOUNT_TAX_COMPENSATION_AMOUNT
BASE_DISCOUNT_TAX_COMPENSATION_AMOUNT
FREE_SHIPPING
}

"""
Specifies the field to use for sorting quote items
"""
input QuoteItemsSortInput {
"""
Specifies the quote items field to sort by
"""
field: SortQuoteItemsEnum!
"""
Specifies the order of quote items' sorting
"""
order: SortEnum!
}

type Cart {
itemsV2(pageSize: Int = 20, currentPage: Int = 1, sort: QuoteItemsSortInput): CartItems
}
56 changes: 56 additions & 0 deletions packages/magento-graphql/schema-247/CartAddress.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
input CartAddressInput {
"""
The customer's fax number.
"""
fax: String
"""
The middle name of the person associated with the billing/shipping address.
"""
middlename: String
"""
An honorific, such as Dr., Mr., or Mrs.
"""
prefix: String
"""
A value such as Sr., Jr., or III.
"""
suffix: String
}

type BillingCartAdress {
"""
The customer's fax number.
"""
fax: String
"""
The middle name of the person associated with the billing/shipping address.
"""
middlename: String
"""
An honorific, such as Dr., Mr., or Mrs.
"""
prefix: String
"""
A value such as Sr., Jr., or III.
"""
suffix: String
}

type ShippingCartAddress {
"""
The customer's fax number.
"""
fax: String
"""
The middle name of the person associated with the billing/shipping address.
"""
middlename: String
"""
An honorific, such as Dr., Mr., or Mrs.
"""
prefix: String
"""
A value such as Sr., Jr., or III.
"""
suffix: String
}
48 changes: 48 additions & 0 deletions packages/magento-graphql/schema-247/CustomAttributesV2.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
"""
Specifies the value for attribute.
"""
input AttributeValueInput {
"""
The code of the attribute.
"""
attribute_code: String!
"""
An array containing selected options for a select or multiselect attribute.
"""
selected_options: [AttributeInputSelectedOption]
"""
The value assigned to the attribute.
"""
value: String
}

"""
Specifies selected option for a select or multiselect attribute value.
"""
input AttributeInputSelectedOption {
"""
The attribute option value.
"""
value: String!
}

input CustomerCreateInput {
"""
The customer's custom attributes.
"""
custom_attributes: [AttributeValueInput]
}

input CustomerUpdateInput {
"""
The customer's custom attributes.
"""
custom_attributes: [AttributeValueInput]
}

input CustomerAddressInput {
"""
Custom attributes assigned to the customer address.
"""
custom_attributesV2: [AttributeValueInput]
}
34 changes: 34 additions & 0 deletions packages/magento-graphql/schema-247/Mutation-cancelOrder.graphqls
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Defines the order to cancel.
"""
input CancelOrderInput {
"""
Order ID.
"""
order_id: ID!
"""
Cancellation reason.
"""
reason: String!
}

"""
Contains the updated customer order and error message if any.
"""
type CancelOrderOutput {
"""
Error encountered while cancelling the order.
"""
error: String
"""
Updated customer order.
"""
order: CustomerOrder
}

type Mutation {
"""
Cancel the specified customer order.
"""
cancelOrder(input: CancelOrderInput!): CancelOrderOutput
}
Loading

0 comments on commit 41068f6

Please sign in to comment.