Skip to content

Commit 71c9165

Browse files
committed
revert api-client-core changes - implementation lives in @gadgetinc/connection
1 parent df7596b commit 71c9165

File tree

4 files changed

+1
-158
lines changed

4 files changed

+1
-158
lines changed

packages/api-client-core/spec/operationBuilders.spec.ts

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
backgroundActionResultOperation,
44
cancelBackgroundActionOperation,
55
enqueueActionOperation,
6-
enqueueShopifyGraphqlOperation,
76
findManyOperation,
87
findOneByFieldOperation,
98
findOneOperation,
@@ -1297,98 +1296,6 @@ describe("operation builders", () => {
12971296
}
12981297
`);
12991298
});
1300-
1301-
test("enqueueActionOperation with shopifyShop option", () => {
1302-
expect(enqueueActionOperation("createWidget", {}, undefined, { shopifyShop: "987654321" })).toMatchInlineSnapshot(`
1303-
{
1304-
"query": "mutation enqueueCreateWidget($backgroundOptions: EnqueueBackgroundActionOptions) {
1305-
background {
1306-
createWidget(backgroundOptions: $backgroundOptions) {
1307-
success
1308-
errors {
1309-
message
1310-
code
1311-
}
1312-
backgroundAction {
1313-
id
1314-
}
1315-
}
1316-
}
1317-
}",
1318-
"variables": {
1319-
"backgroundOptions": {
1320-
"shopifyShop": "987654321",
1321-
},
1322-
},
1323-
}
1324-
`);
1325-
});
1326-
});
1327-
1328-
describe("enqueueShopifyGraphqlOperation", () => {
1329-
test("enqueueShopifyGraphqlOperation should build a mutation query for enqueuing a Shopify GraphQL operation", () => {
1330-
expect(enqueueShopifyGraphqlOperation("shop-123", { query: "query { shop { name } }", variables: {} })).toMatchInlineSnapshot(`
1331-
{
1332-
"query": "mutation enqueueShopifyGraphql($shopId: String!, $query: String!, $variables: JSONObject, $backgroundOptions: EnqueueBackgroundActionOptions) {
1333-
background {
1334-
shopifyGraphql(shopId: $shopId, query: $query, variables: $variables, backgroundOptions: $backgroundOptions) {
1335-
success
1336-
errors {
1337-
message
1338-
code
1339-
}
1340-
backgroundAction {
1341-
id
1342-
}
1343-
}
1344-
}
1345-
}",
1346-
"variables": {
1347-
"backgroundOptions": null,
1348-
"query": "query { shop { name } }",
1349-
"shopId": "shop-123",
1350-
"variables": {},
1351-
},
1352-
}
1353-
`);
1354-
});
1355-
1356-
test("enqueueShopifyGraphqlOperation with options", () => {
1357-
expect(
1358-
enqueueShopifyGraphqlOperation(
1359-
"shop-123",
1360-
{
1361-
query:
1362-
'mutation { updateProduct(id: \\"gid://shopify/Product/123\\", product: { title: \\"New Title\\" }) { product { id title } } }',
1363-
},
1364-
{ startAt: "2024-01-01T00:00:00Z" }
1365-
)
1366-
).toMatchInlineSnapshot(`
1367-
{
1368-
"query": "mutation enqueueShopifyGraphql($shopId: String!, $query: String!, $variables: JSONObject, $backgroundOptions: EnqueueBackgroundActionOptions) {
1369-
background {
1370-
shopifyGraphql(shopId: $shopId, query: $query, variables: $variables, backgroundOptions: $backgroundOptions) {
1371-
success
1372-
errors {
1373-
message
1374-
code
1375-
}
1376-
backgroundAction {
1377-
id
1378-
}
1379-
}
1380-
}
1381-
}",
1382-
"variables": {
1383-
"backgroundOptions": {
1384-
"startAt": "2024-01-01T00:00:00Z",
1385-
},
1386-
"query": "mutation { updateProduct(id: \\"gid://shopify/Product/123\\", product: { title: \\"New Title\\" }) { product { id title } } }",
1387-
"shopId": "shop-123",
1388-
},
1389-
}
1390-
`);
1391-
});
13921299
});
13931300

13941301
describe("backgroundActionResultOperation", () => {

packages/api-client-core/src/operationBuilders.ts

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,6 @@ export const graphqlizeBackgroundOptions = (options?: EnqueueBackgroundActionOpt
304304
if (!options) return null;
305305

306306
const obj = { ...options };
307-
308307
if (typeof obj.retries == "number") {
309308
obj.retries = {
310309
retryCount: obj.retries,
@@ -322,7 +321,7 @@ export const graphqlizeBackgroundOptions = (options?: EnqueueBackgroundActionOpt
322321
}
323322

324323
for (const key of Object.keys(obj)) {
325-
if (["id", "retries", "queue", "priority", "startAt", "shopifyShop"].includes(key)) continue;
324+
if (["id", "retries", "queue", "priority", "startAt"].includes(key)) continue;
326325
delete obj[key];
327326
}
328327

@@ -369,44 +368,6 @@ export const enqueueActionOperation = (
369368
});
370369
};
371370

372-
export const enqueueShopifyGraphqlOperation = (
373-
shopId: string,
374-
variables: { query: string; variables?: Record<string, any> },
375-
options?: EnqueueBackgroundActionOptions<any> | null
376-
) => {
377-
const fields: BuilderFieldSelection = {
378-
shopifyGraphql: Call(
379-
{
380-
shopId: Var({ type: "String!", value: shopId }),
381-
query: Var({ type: "String!", value: variables.query }),
382-
variables: Var({ type: "JSONObject", value: variables.variables }),
383-
backgroundOptions: Var({
384-
type: "EnqueueBackgroundActionOptions",
385-
value: graphqlizeBackgroundOptions(options),
386-
}),
387-
},
388-
{
389-
success: true,
390-
errors: {
391-
message: true,
392-
code: true,
393-
},
394-
backgroundAction: {
395-
id: true,
396-
},
397-
}
398-
),
399-
};
400-
401-
return compileWithVariableValues({
402-
type: "mutation",
403-
name: "enqueueShopifyGraphql",
404-
fields: {
405-
background: fields,
406-
},
407-
});
408-
};
409-
410371
export const cancelBackgroundActionOperation = (id: string) => {
411372
const fields = {
412373
cancel: Call(

packages/api-client-core/src/operationRunners.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
backgroundActionResultOperation,
2222
cancelBackgroundActionOperation,
2323
enqueueActionOperation,
24-
enqueueShopifyGraphqlOperation,
2524
findManyOperation,
2625
findOneByFieldOperation,
2726
findOneOperation,
@@ -404,22 +403,6 @@ export async function enqueueActionRunner<SchemaT, Action extends AnyActionFunct
404403
variables: Action["variablesType"],
405404
options: EnqueueBackgroundActionOptions<Action> = {}
406405
): Promise<Result | Result[]> {
407-
if ((action as any).type === "shopifyGraphql") {
408-
const shopifyShop = (action as any).shopifyShop;
409-
if (!shopifyShop) {
410-
throw new Error(
411-
"Cannot enqueue shopifyGraphql without a current shop. Make sure to call connections.shopify.setCurrentShop() first or access graphql from a request with shop context."
412-
);
413-
}
414-
415-
const plan = enqueueShopifyGraphqlOperation(shopifyShop, variables as any, options);
416-
const response = await connection.currentClient.mutation(plan.query, plan.variables, options).toPromise();
417-
const dataPath = ["background", "shopifyGraphql"];
418-
419-
const result = assertMutationSuccess(response, dataPath);
420-
return new BackgroundActionHandle(connection, action, result.backgroundAction.id) as Result;
421-
}
422-
423406
const normalizedVariableValues = action.isBulk
424407
? disambiguateBulkActionVariables(action, variables)
425408
: disambiguateActionVariables(action, variables);

packages/api-client-core/src/types.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -878,14 +878,6 @@ export type EnqueueBackgroundActionOptions<Action extends AnyActionFunction> = {
878878
* startAt: new Date(new Date().getTime() + 60 * 1000)
879879
*/
880880
startAt?: Date | string;
881-
882-
/**
883-
* The Shopify shop to enqueue the background action for. If not passed, the action will not be rate limited.
884-
*
885-
* @example
886-
* shopifyShop: "82277368081"
887-
*/
888-
shopifyShop?: string;
889881
} & Partial<OperationContext>;
890882

891883
export type ActionFunctionOptions<Action extends AnyActionFunction> = Action extends ActionFunction<infer Options, any, any, any, any>

0 commit comments

Comments
 (0)