Skip to content

Commit 7fbd371

Browse files
authored
Merge pull request #596 from Shopify/dc-local-pickup
Update local pickup examples
2 parents 7afda8a + 3fa4bdb commit 7fbd371

File tree

9 files changed

+120
-93
lines changed

9 files changed

+120
-93
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "{{name}}",
3+
"description": "{{name}}"
4+
}

order-routing/javascript/local-pickup-delivery-option-generators/default/package.json.liquid

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@
1111
},
1212
"codegen": {
1313
"schema": "schema.graphql",
14-
"documents": "input.graphql",
14+
"documents": "src/*.graphql",
1515
"generates": {
1616
"./generated/api.ts": {
1717
"plugins": [
1818
"typescript",
1919
"typescript-operations"
2020
]
2121
}
22+
},
23+
"config": {
24+
"omitOperationSuffix": true
2225
}
2326
},
2427
"devDependencies": {
Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
1-
name = "{{name}}"
2-
type = "local_pickup_delivery_option_generator"
3-
{% if uid %}uid = "{{ uid }}"{% endif %}
41
api_version = "unstable"
52

6-
[build]
7-
command = ""
8-
path = "dist/function.wasm"
3+
[[extensions]]
4+
name = "t:name"
5+
handle = "{{handle}}"
6+
type = "function"
7+
{% if uid %}uid = "{{ uid }}"{% endif %}
8+
9+
[[extensions.targeting]]
10+
target = "purchase.local-pickup-delivery-option-generator.run"
11+
input_query = "src/run.graphql"
12+
export = "run"
13+
14+
[extensions.build]
15+
command = ""
16+
path = "dist/function.wasm"
17+
18+
[extensions.ui.paths]
19+
create = "/"
20+
details = "/"
Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1 @@
1-
{%- if flavor contains "vanilla-js" -%}
2-
// @ts-check
3-
4-
/**
5-
* @typedef {import("../generated/api").InputQuery} InputQuery
6-
* @typedef {import("../generated/api").FunctionResult} FunctionResult
7-
*/
8-
9-
/**
10-
* @type {FunctionResult}
11-
*/
12-
const DELIVERY_OPTION = {
13-
operations: [
14-
{
15-
add: {
16-
title: "Main St.",
17-
cost: 1.99,
18-
pickupLocation: {
19-
locationHandle: "2578303",
20-
pickupInstruction: "Usually ready in 24 hours."
21-
}
22-
}
23-
}
24-
],
25-
};
26-
27-
export default /**
28-
* @param {InputQuery} input
29-
* @returns {FunctionResult}
30-
*/
31-
(input) => {
32-
const configuration = JSON.parse(
33-
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
34-
);
35-
36-
return DELIVERY_OPTION;
37-
};
38-
{%- elsif flavor contains "typescript" -%}
39-
import {
40-
InputQuery,
41-
FunctionResult,
42-
} from "../generated/api";
43-
44-
const DELIVERY_OPTION: FunctionResult = {
45-
operations: [
46-
{
47-
add: {
48-
title: "Main St.",
49-
cost: 1.99,
50-
pickupLocation: {
51-
locationHandle: "2578303",
52-
pickupInstruction: "Usually ready in 24 hours."
53-
}
54-
}
55-
}
56-
],
57-
};
58-
59-
type Configuration = {};
60-
61-
export default (input: InputQuery): FunctionResult => {
62-
const configuration: Configuration = JSON.parse(
63-
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
64-
);
65-
return DELIVERY_OPTION;
66-
};
67-
{%- endif -%}
1+
export * from './run';

order-routing/javascript/local-pickup-delivery-option-generators/default/input.graphql.liquid renamed to order-routing/javascript/local-pickup-delivery-option-generators/default/src/run.graphql.liquid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
query Input {
1+
query RunInput {
22
cart {
33
lines {
44
id
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{%- if flavor contains "vanilla-js" -%}
2+
// @ts-check
3+
4+
/**
5+
* @typedef {import("../generated/api").RunInput} RunInput
6+
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
7+
*/
8+
9+
/**
10+
* @param {RunInput} input
11+
* @returns {FunctionRunResult}
12+
*/
13+
export function run(input) {
14+
const configuration = JSON.parse(
15+
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
16+
);
17+
18+
return {
19+
operations: [
20+
{
21+
add: {
22+
title: "Main St.",
23+
cost: 1.99,
24+
pickupLocation: {
25+
locationHandle: "2578303",
26+
pickupInstruction: "Usually ready in 24 hours."
27+
}
28+
}
29+
}
30+
],
31+
};
32+
}
33+
{%- elsif flavor contains "typescript" -%}
34+
import {
35+
RunInput,
36+
FunctionRunResult,
37+
} from "../generated/api";
38+
39+
type Configuration = {};
40+
41+
export function run(input: RunInput): FunctionRunResult {
42+
const configuration: Configuration = JSON.parse(
43+
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
44+
);
45+
46+
return {
47+
operations: [
48+
{
49+
add: {
50+
title: "Main St.",
51+
cost: 1.99,
52+
pickupLocation: {
53+
locationHandle: "2578303",
54+
pickupInstruction: "Usually ready in 24 hours."
55+
}
56+
}
57+
}
58+
],
59+
};
60+
}
61+
{%- endif -%}

order-routing/javascript/local-pickup-delivery-option-generators/default/src/index.test.liquid renamed to order-routing/javascript/local-pickup-delivery-option-generators/default/src/run.test.liquid

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{%- if flavor contains "vanilla-js" -%}
22
import { describe, it, expect } from 'vitest';
3-
import deliveryOptionGenerator from './index';
3+
import { run } from './run';
44

55
/**
6-
* @typedef {import("../generated/api").FunctionResult} FunctionResult
6+
* @typedef {import("../generated/api").RunInput} RunInput
7+
* @typedef {import("../generated/api").FunctionRunResult} FunctionRunResult
78
*/
89

910
describe('local pickup delivery option generator function', () => {
1011
it('returns a delivery option', () => {
11-
const result = deliveryOptionGenerator({
12+
const result = run({
1213
cart: {
1314
lines: [
1415
{
@@ -43,7 +44,7 @@ describe('local pickup delivery option generator function', () => {
4344
metafield: null
4445
}
4546
});
46-
const expected = /** @type {FunctionResult} */ ({
47+
const expected = /** @type {FunctionRunResult} */ ({
4748
operations: [
4849
{
4950
add: {
@@ -63,12 +64,12 @@ describe('local pickup delivery option generator function', () => {
6364
});
6465
{%- elsif flavor contains "typescript" -%}
6566
import { describe, it, expect } from 'vitest';
66-
import deliveryOptionGenerator from './index';
67-
import { FunctionResult } from '../generated/api';
67+
import { run } from './run';
68+
import { RunInput, FunctionRunResult } from '../generated/api';
6869

6970
describe('local pickup delivery option generator function', () => {
7071
it('returns a delivery option', () => {
71-
const result = deliveryOptionGenerator({
72+
const result = run({
7273
cart: {
7374
lines: [
7475
{
@@ -103,7 +104,7 @@ describe('local pickup delivery option generator function', () => {
103104
metafield: null
104105
}
105106
});
106-
const expected: FunctionResult = {
107+
const expected: FunctionRunResult = {
107108
operations: [
108109
{
109110
add: {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "{{name}}",
3+
"description": "{{name}}"
4+
}
Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
name = "{{name}}"
2-
type = "local_pickup_delivery_option_generator"
3-
{% if uid %}uid = "{{ uid }}"{% endif %}
41
api_version = "unstable"
52

6-
[build]
7-
command = "cargo build --target=wasm32-wasip1 --release"
8-
path = "target/wasm32-wasip1/release/{{name | replace: " ", "-" | downcase}}.wasm"
9-
watch = [ "src/**/*.rs" ]
3+
[[extensions]]
4+
name = "t:name"
5+
handle = "{{handle}}"
6+
type = "function"
7+
{% if uid %}uid = "{{ uid }}"{% endif %}
8+
9+
[[extensions.targeting]]
10+
target = "purchase.local-pickup-delivery-option-generator.run"
11+
input_query = "src/run.graphql"
12+
export = "run"
13+
14+
[extensions.build]
15+
command = "cargo build --target=wasm32-wasip1 --release"
16+
path = "target/wasm32-wasip1/release/{{handle | replace: " ", "-" | downcase}}.wasm"
17+
watch = [ "src/**/*.rs" ]
1018

11-
[ui.paths]
12-
create = "/"
13-
details = "/"
19+
[extensions.ui.paths]
20+
create = "/"
21+
details = "/"

0 commit comments

Comments
 (0)