Skip to content

Commit

Permalink
Cleanup local pickup examples
Browse files Browse the repository at this point in the history
  • Loading branch information
davejcameron committed Jan 28, 2025
1 parent aa7b3db commit 33d6b99
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "{{name}}",
"description": "{{name}}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@
},
"codegen": {
"schema": "schema.graphql",
"documents": "input.graphql",
"documents": "src/*.graphql",
"generates": {
"./generated/api.ts": {
"plugins": [
"typescript",
"typescript-operations"
]
}
},
"config": {
"omitOperationSuffix": true
}
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
name = "{{name}}"
type = "local_pickup_delivery_option_generator"
{% if uid %}uid = "{{ uid }}"{% endif %}
api_version = "unstable"

[build]
command = ""
path = "dist/function.wasm"
[[extensions]]
name = "t:name"
handle = "{{handle}}"
type = "function"
{% if uid %}uid = "{{ uid }}"{% endif %}

[[extensions.targeting]]
target = "purchase.local-pickup-delivery-option-generator.run"
input_query = "src/run.graphql"
export = "run"

[extensions.build]
command = ""
path = "dist/function.wasm"

[extensions.ui.paths]
create = "/"
details = "/"
Original file line number Diff line number Diff line change
@@ -1,67 +1 @@
{%- if flavor contains "vanilla-js" -%}
// @ts-check

/**
* @typedef {import("../generated/api").InputQuery} InputQuery
* @typedef {import("../generated/api").FunctionResult} FunctionResult
*/

/**
* @type {FunctionResult}
*/
const DELIVERY_OPTION = {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};

export default /**
* @param {InputQuery} input
* @returns {FunctionResult}
*/
(input) => {
const configuration = JSON.parse(
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
);

return DELIVERY_OPTION;
};
{%- elsif flavor contains "typescript" -%}
import {
InputQuery,
FunctionResult,
} from "../generated/api";

const DELIVERY_OPTION: FunctionResult = {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};

type Configuration = {};

export default (input: InputQuery): FunctionResult => {
const configuration: Configuration = JSON.parse(
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
);
return DELIVERY_OPTION;
};
{%- endif -%}
export * from './run';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
query Input {
query RunInput {
cart {
lines {
id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{%- if flavor contains "vanilla-js" -%}
// @ts-check

/**
* @typedef {import("../generated/api").InputQuery} InputQuery
* @typedef {import("../generated/api").FunctionResult} FunctionResult
*/

/**
* @type {FunctionResult}
*/
const DELIVERY_OPTION = {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};

export default /**
* @param {InputQuery} input
* @returns {FunctionResult}
*/
(input) => {
const configuration = JSON.parse(
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
);

return DELIVERY_OPTION;
};
{%- elsif flavor contains "typescript" -%}
import {
InputQuery,
FunctionResult,
} from "../generated/api";

const DELIVERY_OPTION: FunctionResult = {
operations: [
{
add: {
title: "Main St.",
cost: 1.99,
pickupLocation: {
locationHandle: "2578303",
pickupInstruction: "Usually ready in 24 hours."
}
}
}
],
};

type Configuration = {};

export default (input: InputQuery): FunctionResult => {
const configuration: Configuration = JSON.parse(
input?.deliveryOptionGenerator?.metafield?.value ?? "{}"
);
return DELIVERY_OPTION;
};
{%- endif -%}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{%- if flavor contains "vanilla-js" -%}
import { describe, it, expect } from 'vitest';
import deliveryOptionGenerator from './index';
import deliveryOptionGenerator from './run';

/**
* @typedef {import("../generated/api").FunctionResult} FunctionResult
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "{{name}}",
"description": "{{name}}"
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
name = "{{name}}"
type = "local_pickup_delivery_option_generator"
{% if uid %}uid = "{{ uid }}"{% endif %}
api_version = "unstable"

[build]
command = "cargo build --target=wasm32-wasip1 --release"
path = "target/wasm32-wasip1/release/{{name | replace: " ", "-" | downcase}}.wasm"
watch = [ "src/**/*.rs" ]
[[extensions]]
name = "t:name"
handle = "{{handle}}"
type = "function"
{% if uid %}uid = "{{ uid }}"{% endif %}

[[extensions.targeting]]
target = "purchase.local-pickup-delivery-option-generator.run"
input_query = "src/run.graphql"
export = "run"

[extensions.build]
command = "cargo build --target=wasm32-wasip1 --release"
path = "target/wasm32-wasip1/release/{{handle | replace: " ", "-" | downcase}}.wasm"
watch = [ "src/**/*.rs" ]

[ui.paths]
create = "/"
details = "/"
[extensions.ui.paths]
create = "/"
details = "/"

0 comments on commit 33d6b99

Please sign in to comment.