@comity/graphql-client-fetch 0.9.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Filippo Bovo and contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # @comity/graphql-client-fetch
2
+
3
+ Fetch transport for `@comity/graphql-client`.
4
+
5
+ ---
6
+
7
+ ## Purpose
8
+
9
+ Provides a GraphQL transport implementation that executes operations over HTTP using the Fetch API.
10
+
11
+ ---
12
+
13
+ ## Scope
14
+
15
+ This package:
16
+
17
+ - ✅ implements the GraphQL transport contract
18
+ - ✅ exposes the Fetch transport class
19
+ - ✅ binds to the Fetch API (`fetch`, `globalThis.fetch`, `Response`, `RequestInit`)
20
+
21
+ This package does NOT:
22
+
23
+ - ❌ define GraphQL client contracts
24
+ - ❌ own query building
25
+ - ❌ embed application-specific GraphQL policy
26
+ - ❌ depend on `@comity/http` — the HTTP abstraction and the GraphQL transport abstraction are different boundaries
27
+
28
+ ---
29
+
30
+ ## Public API
31
+
32
+ - `FetchGraphqlTransport` — Fetch API implementation of `GraphqlTransport`
33
+ - `FetchTransportOptions` — transport configuration type
34
+
35
+ No exhaustive reference; see docs for constraints.
36
+
37
+ ---
38
+
39
+ ## Documentation
40
+
41
+ - docs/overview.md
42
+ - docs/conventions.md
43
+
44
+ ---
45
+
46
+ ## Related Packages
47
+
48
+ - @comity/graphql-client — defines the `GraphqlTransport` contract this adapter implements
49
+ - @comity/graphql-client-ws — WebSocket transport adapter
50
+
51
+ ---
52
+
53
+ ## Status
54
+
55
+ Stable
56
+
57
+ _Review Completed: 2026-08-28_
58
+ _Reviewer: Automated Audit Remediation_
59
+ _Compliance Score: 99.5% (Green)_
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchGraphqlTransport = void 0;
4
+ const errors_1 = require("@comity/graphql-client/errors");
5
+ /**
6
+ * A GraphQL transport implementation that uses the fetch API to execute GraphQL requests.
7
+ */
8
+ class FetchGraphqlTransport {
9
+ /** The URL of the GraphQL endpoint. */
10
+ #url;
11
+ /** The fetch function to use for making HTTP requests. */
12
+ #fetchFn;
13
+ /** Additional headers to include in the HTTP requests. */
14
+ #headers;
15
+ /**
16
+ * @param options - The options for configuring the FetchGraphqlTransport.
17
+ */
18
+ constructor(options) {
19
+ this.#url = options.url;
20
+ this.#fetchFn = options.fetch ?? globalThis.fetch;
21
+ this.#headers = options.headers ?? {};
22
+ }
23
+ /**
24
+ * @inheritdoc
25
+ */
26
+ async execute(request) {
27
+ const headers = this.#headers;
28
+ const fetchFn = this.#fetchFn;
29
+ const url = this.#url;
30
+ const response = await fetchFn(url, {
31
+ method: "POST",
32
+ headers: {
33
+ "content-type": "application/json",
34
+ ...headers,
35
+ ...(request.headers ?? {}),
36
+ },
37
+ body: JSON.stringify({
38
+ query: request.query,
39
+ variables: request.variables,
40
+ operationName: request.operationName,
41
+ }),
42
+ });
43
+ if (!response.ok) {
44
+ const details = request.operationName ? { operationName: request.operationName } : undefined;
45
+ throw new errors_1.GraphqlClientError("transport_error", {
46
+ httpStatus: response.status,
47
+ ...(details ? { details } : {}),
48
+ });
49
+ }
50
+ const json = (await response.json());
51
+ const result = {
52
+ ...(json["data"] ? { data: json["data"] } : {}),
53
+ ...(json["errors"] ? { errors: json["errors"] } : {}),
54
+ meta: {
55
+ headers: response.headers,
56
+ httpStatus: response.status,
57
+ ...(json["extensions"]
58
+ ? { extensions: json["extensions"] }
59
+ : {}),
60
+ },
61
+ };
62
+ return result;
63
+ }
64
+ }
65
+ exports.FetchGraphqlTransport = FetchGraphqlTransport;
66
+ //# sourceMappingURL=fetch-transport.js.map
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FetchGraphqlTransport = void 0;
4
+ var fetch_transport_js_1 = require("./fetch-transport.js");
5
+ Object.defineProperty(exports, "FetchGraphqlTransport", { enumerable: true, get: function () { return fetch_transport_js_1.FetchGraphqlTransport; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,62 @@
1
+ import { GraphqlClientError } from "@comity/graphql-client/errors";
2
+ /**
3
+ * A GraphQL transport implementation that uses the fetch API to execute GraphQL requests.
4
+ */
5
+ export class FetchGraphqlTransport {
6
+ /** The URL of the GraphQL endpoint. */
7
+ #url;
8
+ /** The fetch function to use for making HTTP requests. */
9
+ #fetchFn;
10
+ /** Additional headers to include in the HTTP requests. */
11
+ #headers;
12
+ /**
13
+ * @param options - The options for configuring the FetchGraphqlTransport.
14
+ */
15
+ constructor(options) {
16
+ this.#url = options.url;
17
+ this.#fetchFn = options.fetch ?? globalThis.fetch;
18
+ this.#headers = options.headers ?? {};
19
+ }
20
+ /**
21
+ * @inheritdoc
22
+ */
23
+ async execute(request) {
24
+ const headers = this.#headers;
25
+ const fetchFn = this.#fetchFn;
26
+ const url = this.#url;
27
+ const response = await fetchFn(url, {
28
+ method: "POST",
29
+ headers: {
30
+ "content-type": "application/json",
31
+ ...headers,
32
+ ...(request.headers ?? {}),
33
+ },
34
+ body: JSON.stringify({
35
+ query: request.query,
36
+ variables: request.variables,
37
+ operationName: request.operationName,
38
+ }),
39
+ });
40
+ if (!response.ok) {
41
+ const details = request.operationName ? { operationName: request.operationName } : undefined;
42
+ throw new GraphqlClientError("transport_error", {
43
+ httpStatus: response.status,
44
+ ...(details ? { details } : {}),
45
+ });
46
+ }
47
+ const json = (await response.json());
48
+ const result = {
49
+ ...(json["data"] ? { data: json["data"] } : {}),
50
+ ...(json["errors"] ? { errors: json["errors"] } : {}),
51
+ meta: {
52
+ headers: response.headers,
53
+ httpStatus: response.status,
54
+ ...(json["extensions"]
55
+ ? { extensions: json["extensions"] }
56
+ : {}),
57
+ },
58
+ };
59
+ return result;
60
+ }
61
+ }
62
+ //# sourceMappingURL=fetch-transport.js.map
@@ -0,0 +1,2 @@
1
+ export { FetchGraphqlTransport } from "./fetch-transport.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,28 @@
1
+ import type { GraphqlRequest } from "@comity/graphql-client";
2
+ import type { GraphqlResponse } from "@comity/graphql-client";
3
+ import type { GraphqlTransport } from "@comity/graphql-client";
4
+ /**
5
+ * Options for the FetchGraphqlTransport class.
6
+ */
7
+ export interface FetchTransportOptions {
8
+ /** The URL of the GraphQL endpoint. */
9
+ url: string;
10
+ /** The fetch function to use for making HTTP requests. Defaults to the global fetch function. */
11
+ fetch?: typeof fetch;
12
+ /** Additional headers to include in the HTTP requests. */
13
+ headers?: Record<string, string>;
14
+ }
15
+ /**
16
+ * A GraphQL transport implementation that uses the fetch API to execute GraphQL requests.
17
+ */
18
+ export declare class FetchGraphqlTransport implements GraphqlTransport {
19
+ #private;
20
+ /**
21
+ * @param options - The options for configuring the FetchGraphqlTransport.
22
+ */
23
+ constructor(options: FetchTransportOptions);
24
+ /**
25
+ * @inheritdoc
26
+ */
27
+ execute<T>(request: GraphqlRequest): Promise<GraphqlResponse<T>>;
28
+ }
@@ -0,0 +1,2 @@
1
+ export type { FetchTransportOptions } from "./fetch-transport.js";
2
+ export { FetchGraphqlTransport } from "./fetch-transport.js";
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@comity/graphql-client-fetch",
3
+ "version": "0.9.0",
4
+ "description": "Fetch GraphQL transport adapter for Comity framework",
5
+ "type": "module",
6
+ "private": false,
7
+ "author": "Filippo Bovo <hello@filippobovo.com>",
8
+ "license": "MIT",
9
+ "comity": {
10
+ "layer": "technology-adapter",
11
+ "implements": "@comity/graphql-client"
12
+ },
13
+ "homepage": "https://github.com/comityjs/framework#readme",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/comityjs/framework.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/comityjs/framework/issues"
20
+ },
21
+ "engines": {
22
+ "node": ">=24.0.0"
23
+ },
24
+ "keywords": [
25
+ "comity",
26
+ "comityjs",
27
+ "adapter",
28
+ "fetch",
29
+ "framework",
30
+ "graphql",
31
+ "typescript"
32
+ ],
33
+ "files": [
34
+ "./dist",
35
+ "!./dist/**/*.map"
36
+ ],
37
+ "main": "./dist/cjs/index.js",
38
+ "module": "./dist/esm/index.js",
39
+ "types": "./dist/types/index.d.ts",
40
+ "exports": {
41
+ ".": {
42
+ "import": {
43
+ "types": "./dist/types/index.d.ts",
44
+ "default": "./dist/esm/index.js"
45
+ },
46
+ "require": {
47
+ "types": "./dist/types/index.d.ts",
48
+ "default": "./dist/cjs/index.js"
49
+ }
50
+ },
51
+ "./package.json": "./package.json"
52
+ },
53
+ "publishConfig": {
54
+ "registry": "https://registry.npmjs.org",
55
+ "access": "public"
56
+ },
57
+ "sideEffects": false,
58
+ "peerDependencies": {
59
+ "@comity/graphql-client": "0.9.0"
60
+ },
61
+ "dependencies": {
62
+ "@comity/graphql-client": "0.9.0"
63
+ },
64
+ "devDependencies": {
65
+ "@types/node": "^24.13.4",
66
+ "typescript": "^5.9.3"
67
+ },
68
+ "scripts": {
69
+ "build": "node ../../scripts/build.mjs",
70
+ "dev": "node ../../scripts/build.mjs --watch",
71
+ "test": "vitest run --coverage",
72
+ "type-check": "tsc -p tsconfig.json --noEmit",
73
+ "lint": "eslint --ext .ts src"
74
+ }
75
+ }