Skip to content

Update fulfillment constraints to use the new target #620

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

Open
wants to merge 1 commit into
base: update-function-templates-2025-07
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
864 changes: 650 additions & 214 deletions order-routing/javascript/fulfillment-constraints/default/schema.graphql

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
api_version = "2025-01"
api_version = "2025-07"

[[extensions]]
name = "t:name"
Expand All @@ -8,7 +8,7 @@ type = "function"
description = "t:description"

[[extensions.targeting]]
target = "purchase.fulfillment-constraint-rule.run"
target = "cart.fulfillment-constraints.generate.run"
input_query = "src/run.graphql"
export = "run"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

/**
* @typedef {import("../generated/api").RunInput} RunInput
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
* @typedef {import("../generated/api").CartFulfillmentConstraintsGenerateRunResult} CartFulfillmentConstraintsGenerateRunResult
*/

/**
* @type {FunctionRunResult}
* @type {CartFulfillmentConstraintsGenerateRunResult}
*/
const NO_CHANGES = {
operations: [],
};

/**
* @param {RunInput} input
* @returns {FunctionRunResult}
* @returns {CartFulfillmentConstraintsGenerateRunResult}
*/
export function run(input) {
const configuration = JSON.parse(
Expand All @@ -27,16 +27,16 @@ export function run(input) {
{%- elsif flavor contains "typescript" -%}
import type {
RunInput,
FunctionRunResult,
CartFulfillmentConstraintsGenerateRunResult,
} from "../generated/api";

const NO_CHANGES: FunctionRunResult = {
const NO_CHANGES: CartFulfillmentConstraintsGenerateRunResult = {
operations: [],
};

type Configuration = {};

export function run(input: RunInput): FunctionRunResult {
export function run(input: RunInput): CartFulfillmentConstraintsGenerateRunResult {
const configuration: Configuration = JSON.parse(
input?.fulfillmentConstraintRule?.metafield?.value ?? "{}"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describe, it, expect } from 'vitest';
import { run } from './run';

/**
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
* @typedef {import("../generated/api").CartFulfillmentConstraintsGenerateRunResult} CartFulfillmentConstraintsGenerateRunResult
*/

describe('fulfillment constraint rule function', () => {
Expand All @@ -23,15 +23,15 @@ describe('fulfillment constraint rule function', () => {
metafield: null
}
});
const expected = /** @type {FunctionRunResult} */ ({ operations: [] });
const expected = /** @type {CartFulfillmentConstraintsGenerateRunResult} */ ({ operations: [] });

expect(result).toEqual(expected);
});
});
{%- elsif flavor contains "typescript" -%}
import { describe, it, expect } from 'vitest';
import { run } from './run';
import { FunctionRunResult } from '../generated/api';
import { CartFulfillmentConstraintsGenerateRunResult } from '../generated/api';

describe('fulfillment constraint rule function', () => {
it('returns no operations without configuration', () => {
Expand All @@ -50,7 +50,7 @@ describe('fulfillment constraint rule function', () => {
metafield: null
}
});
const expected: FunctionRunResult = { operations: [] };
const expected: CartFulfillmentConstraintsGenerateRunResult = { operations: [] };

expect(result).toEqual(expected);
});
Expand Down
Loading