@unchainedshop/cockpit-api 2.4.0 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.ts CHANGED
@@ -14,7 +14,7 @@ import { type LocalizeOptions } from "./methods/localize.ts";
14
14
  * Cockpit API Client interface
15
15
  */
16
16
  export interface CockpitAPIClient {
17
- graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown>): Promise<T | null>;
17
+ graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown>, operationName?: string): Promise<T | null>;
18
18
  getContentItem<T = unknown>(options: ContentItemQueryOptions): Promise<T | null>;
19
19
  getContentItems<T = CockpitContentItem>(model: string, options?: ContentListQueryOptions): Promise<CockpitListResponse<T> | null>;
20
20
  /**
@@ -4,6 +4,6 @@
4
4
  import { type DocumentNode } from "graphql";
5
5
  import type { MethodContext } from "./content.ts";
6
6
  export interface GraphQLMethods {
7
- graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown>): Promise<T | null>;
7
+ graphQL<T = unknown>(document: DocumentNode, variables?: Record<string, unknown>, operationName?: string): Promise<T | null>;
8
8
  }
9
9
  export declare function createGraphQLMethods(ctx: MethodContext): GraphQLMethods;
@@ -1,13 +1,18 @@
1
1
  /**
2
2
  * GraphQL API method
3
3
  */
4
- import { print } from "graphql";
4
+ import { print, getOperationAST } from "graphql";
5
5
  export function createGraphQLMethods(ctx) {
6
6
  return {
7
- async graphQL(document, variables) {
7
+ async graphQL(document, variables, operationName) {
8
8
  const query = print(document);
9
+ const resolvedOperationName = operationName ?? getOperationAST(document)?.name?.value;
9
10
  const endpoint = ctx.url.graphqlEndpoint();
10
- return ctx.http.post(endpoint, { query, variables });
11
+ return ctx.http.post(endpoint, {
12
+ query,
13
+ variables,
14
+ operationName: resolvedOperationName,
15
+ });
11
16
  },
12
17
  };
13
18
  }
@@ -36,6 +36,7 @@ export interface MakeCockpitSchemaOptions {
36
36
  export interface ExecutorRequest {
37
37
  document: DocumentNode;
38
38
  variables?: Record<string, unknown>;
39
+ operationName?: string;
39
40
  context?: CockpitExecutorContext;
40
41
  }
41
42
  /**
@@ -72,7 +72,7 @@ export function createRemoteExecutor(options = {}) {
72
72
  pendingClients.delete(key);
73
73
  }
74
74
  }
75
- return async ({ document, variables, context }) => {
75
+ return async ({ document, variables, operationName, context, }) => {
76
76
  // Extract tenant from context
77
77
  const tenant = extractTenant
78
78
  ? extractTenant(context)
@@ -80,6 +80,6 @@ export function createRemoteExecutor(options = {}) {
80
80
  // Get or create pooled client
81
81
  const cockpit = await getOrCreateClient(tenant);
82
82
  // Execute GraphQL query
83
- return cockpit.graphQL(document, variables);
83
+ return cockpit.graphQL(document, variables, operationName);
84
84
  };
85
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unchainedshop/cockpit-api",
3
- "version": "2.4.0",
3
+ "version": "2.4.1",
4
4
  "description": "A package to interact with the Cockpit CMS API, including functionalities to handle GraphQL requests and various CMS content manipulations.",
5
5
  "main": "dist/index.js",
6
6
  "homepage": "https://unchained.shop",
@@ -50,8 +50,8 @@
50
50
  "node": ">=20"
51
51
  },
52
52
  "dependencies": {
53
- "@unchainedshop/logger": "^4.6.0",
54
- "lru-cache": "^11.2.4"
53
+ "@unchainedshop/logger": "^4.6.2",
54
+ "lru-cache": "^11.2.6"
55
55
  },
56
56
  "types": "dist/index.d.ts",
57
57
  "peerDependencies": {
@@ -68,13 +68,13 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@eslint/js": "^9.39.2",
71
- "@types/node": "^24.10.7",
71
+ "@types/node": "^25.3.1",
72
72
  "eslint": "^9.39.2",
73
73
  "eslint-config-prettier": "^10.1.8",
74
- "eslint-plugin-prettier": "^5.5.4",
75
- "graphql": "^16.12.0",
76
- "prettier": "^3.7.4",
74
+ "eslint-plugin-prettier": "^5.5.5",
75
+ "graphql": "^16.13.0",
76
+ "prettier": "^3.8.1",
77
77
  "typescript": "^5.9.3",
78
- "typescript-eslint": "^8.52.0"
78
+ "typescript-eslint": "^8.56.1"
79
79
  }
80
80
  }