@capixjs/transport-graphql 0.1.0-alpha.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/LICENSE +21 -0
- package/README.md +107 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/schema-builder.d.ts +16 -0
- package/dist/schema-builder.d.ts.map +1 -0
- package/dist/schema-builder.js +200 -0
- package/dist/schema-builder.js.map +1 -0
- package/dist/transport.d.ts +22 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +102 -0
- package/dist/transport.js.map +1 -0
- package/package.json +48 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Capix 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,107 @@
|
|
|
1
|
+
# @capixjs/transport-graphql
|
|
2
|
+
|
|
3
|
+
GraphQL transport for [Capix](https://github.com/capix/capix). Serves a spec-compliant GraphQL endpoint and an optional GraphiQL playground from your Capix capability registry.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @capixjs/core @capixjs/transport-graphql zod
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { createServer } from '@capixjs/core';
|
|
15
|
+
import { graphqlTransport } from '@capixjs/transport-graphql';
|
|
16
|
+
import { buildContext, capabilities } from './capabilities.js';
|
|
17
|
+
|
|
18
|
+
createServer({
|
|
19
|
+
context: buildContext,
|
|
20
|
+
capabilities,
|
|
21
|
+
transports: [
|
|
22
|
+
graphqlTransport({ port: 4000 }),
|
|
23
|
+
],
|
|
24
|
+
}).start();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
GraphQL endpoint: `http://localhost:4000/graphql`
|
|
28
|
+
Playground: `http://localhost:4000/graphql/playground`
|
|
29
|
+
|
|
30
|
+
## Schema mapping
|
|
31
|
+
|
|
32
|
+
Capability registries are mapped to a GraphQL schema automatically:
|
|
33
|
+
|
|
34
|
+
| Capix | GraphQL |
|
|
35
|
+
|-------|---------|
|
|
36
|
+
| `intent: 'query'` | `Query` field |
|
|
37
|
+
| All other intents | `Mutation` field |
|
|
38
|
+
| `users.getUser` | `users_getUser` field |
|
|
39
|
+
| `z.string()` input | `String!` arg |
|
|
40
|
+
| `z.number()` input | `Float!` arg |
|
|
41
|
+
| `z.boolean()` input | `Boolean!` arg |
|
|
42
|
+
| `.output(schema)` | Named output type |
|
|
43
|
+
| No `.output()` | `JSON` scalar |
|
|
44
|
+
| `z.coerce.number().default(N)` | Optional `Float` arg |
|
|
45
|
+
|
|
46
|
+
## Querying
|
|
47
|
+
|
|
48
|
+
```graphql
|
|
49
|
+
# Named output type (capability uses .output())
|
|
50
|
+
{ users_getUser(id: "1") { id name email } }
|
|
51
|
+
|
|
52
|
+
# JSON scalar (no .output() — entire object returned as-is)
|
|
53
|
+
{ system_ping }
|
|
54
|
+
|
|
55
|
+
# Variables work for all argument types
|
|
56
|
+
query GetUser($id: String!) {
|
|
57
|
+
users_getUser(id: $id) { id name }
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Options
|
|
62
|
+
|
|
63
|
+
| Option | Type | Default | Description |
|
|
64
|
+
|--------|------|---------|-------------|
|
|
65
|
+
| `port` | `number` | — | Port to listen on |
|
|
66
|
+
| `host` | `string` | `'0.0.0.0'` | Host to bind to |
|
|
67
|
+
| `path` | `string` | `'/graphql'` | GraphQL endpoint path |
|
|
68
|
+
| `playground` | `boolean` | `true` | Serve GraphiQL at `{path}/playground` |
|
|
69
|
+
| `capabilities` | `GroupTree` | server default | Per-transport capability registry |
|
|
70
|
+
|
|
71
|
+
## Per-transport capabilities
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
createServer({
|
|
75
|
+
context: buildContext,
|
|
76
|
+
transports: [
|
|
77
|
+
graphqlTransport({
|
|
78
|
+
port: 4000,
|
|
79
|
+
capabilities: { users: { list, get } }, // only these capabilities on GraphQL
|
|
80
|
+
}),
|
|
81
|
+
],
|
|
82
|
+
});
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Auth header forwarding
|
|
86
|
+
|
|
87
|
+
The GraphQL transport forwards `Authorization` and other request headers to `buildContext` unchanged. Use `getHeader(req, 'authorization')` inside your context builder to read them:
|
|
88
|
+
|
|
89
|
+
```ts
|
|
90
|
+
import { defineContext, getHeader } from '@capixjs/core';
|
|
91
|
+
|
|
92
|
+
const buildContext = defineContext(async (req) => ({
|
|
93
|
+
requestId: crypto.randomUUID(),
|
|
94
|
+
user: await verifyToken(getHeader(req, 'authorization')),
|
|
95
|
+
}));
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Limitations
|
|
99
|
+
|
|
100
|
+
- **No subscriptions**: the GraphQL transport is request/response only. For real-time updates, use `wsTransport` with an event bus alongside the GraphQL transport.
|
|
101
|
+
- **`z.lazy` falls back to JSON scalar**: recursive schemas defined with `z.lazy()` cannot be statically typed in the generated GraphQL schema and are represented as the `JSON` scalar.
|
|
102
|
+
- **No file uploads**: multipart file uploads are not supported in the GraphQL transport. Use the REST transport for file upload capabilities.
|
|
103
|
+
- **No batching**: the transport handles one operation per request.
|
|
104
|
+
|
|
105
|
+
## License
|
|
106
|
+
|
|
107
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAElD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* schema-builder.ts — Converts a Capix registry into a GraphQL schema.
|
|
3
|
+
*
|
|
4
|
+
* Rules:
|
|
5
|
+
* - intent: 'query' → Query field
|
|
6
|
+
* - all other intents → Mutation field
|
|
7
|
+
* - Dot-path names become underscore-separated field names (users.getUser → users_getUser)
|
|
8
|
+
* - Zod input schema fields → individual GraphQL args
|
|
9
|
+
* - Zod output schema → named GraphQL output type; absent → JSONScalar
|
|
10
|
+
* - Type cache prevents duplicate type definitions across fields
|
|
11
|
+
*/
|
|
12
|
+
import { GraphQLSchema, GraphQLScalarType } from 'graphql';
|
|
13
|
+
import type { CapabilityRegistry, InvokeFn } from '@capixjs/core';
|
|
14
|
+
export declare const JSONScalar: GraphQLScalarType<unknown, unknown>;
|
|
15
|
+
export declare function buildGraphQLSchema(registry: CapabilityRegistry, invoke: InvokeFn): GraphQLSchema;
|
|
16
|
+
//# sourceMappingURL=schema-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-builder.d.ts","sourceRoot":"","sources":["../src/schema-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,aAAa,EAQb,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAEjB,OAAO,KAAK,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAElE,eAAO,MAAM,UAAU,qCAerB,CAAC;AAoIH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,MAAM,EAAE,QAAQ,GAAG,aAAa,CA2DhG"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* schema-builder.ts — Converts a Capix registry into a GraphQL schema.
|
|
3
|
+
*
|
|
4
|
+
* Rules:
|
|
5
|
+
* - intent: 'query' → Query field
|
|
6
|
+
* - all other intents → Mutation field
|
|
7
|
+
* - Dot-path names become underscore-separated field names (users.getUser → users_getUser)
|
|
8
|
+
* - Zod input schema fields → individual GraphQL args
|
|
9
|
+
* - Zod output schema → named GraphQL output type; absent → JSONScalar
|
|
10
|
+
* - Type cache prevents duplicate type definitions across fields
|
|
11
|
+
*/
|
|
12
|
+
import { GraphQLSchema, GraphQLObjectType, GraphQLInputObjectType, GraphQLString, GraphQLFloat, GraphQLBoolean, GraphQLList, GraphQLNonNull, GraphQLScalarType, GraphQLEnumType, Kind, } from 'graphql';
|
|
13
|
+
export const JSONScalar = new GraphQLScalarType({
|
|
14
|
+
name: 'JSON',
|
|
15
|
+
description: 'Arbitrary JSON value',
|
|
16
|
+
serialize: (v) => v,
|
|
17
|
+
parseValue: (v) => v,
|
|
18
|
+
parseLiteral: (ast) => {
|
|
19
|
+
switch (ast.kind) {
|
|
20
|
+
case Kind.INT: return parseInt(ast.value, 10);
|
|
21
|
+
case Kind.FLOAT: return parseFloat(ast.value);
|
|
22
|
+
case Kind.STRING: return ast.value;
|
|
23
|
+
case Kind.BOOLEAN: return ast.value;
|
|
24
|
+
case Kind.NULL: return null;
|
|
25
|
+
default: return null;
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
function zodDef(schema) {
|
|
30
|
+
return schema?._def ?? {};
|
|
31
|
+
}
|
|
32
|
+
function resolveShape(d) {
|
|
33
|
+
return typeof d.shape === 'function' ? d.shape() : (d.shape ?? {});
|
|
34
|
+
}
|
|
35
|
+
function zodToGqlOutput(schema, typeName, cache) {
|
|
36
|
+
const d = zodDef(schema);
|
|
37
|
+
switch (d.typeName) {
|
|
38
|
+
case 'ZodString': return new GraphQLNonNull(GraphQLString);
|
|
39
|
+
case 'ZodNumber': return new GraphQLNonNull(GraphQLFloat);
|
|
40
|
+
case 'ZodBoolean': return new GraphQLNonNull(GraphQLBoolean);
|
|
41
|
+
case 'ZodDefault': {
|
|
42
|
+
// Unwrap default — value is optional in GraphQL (no NonNull)
|
|
43
|
+
const inner = zodToGqlOutput(d.innerType, typeName, cache);
|
|
44
|
+
return inner instanceof GraphQLNonNull ? inner.ofType : inner;
|
|
45
|
+
}
|
|
46
|
+
case 'ZodEffects':
|
|
47
|
+
// z.coerce.* and z.preprocess() — unwrap to inner schema
|
|
48
|
+
return zodToGqlOutput(d.schema, typeName, cache);
|
|
49
|
+
case 'ZodOptional':
|
|
50
|
+
case 'ZodNullable': {
|
|
51
|
+
const inner = zodToGqlOutput(d.innerType, typeName, cache);
|
|
52
|
+
return inner instanceof GraphQLNonNull ? inner.ofType : inner;
|
|
53
|
+
}
|
|
54
|
+
case 'ZodArray': {
|
|
55
|
+
const inner = zodToGqlOutput(d.type, `${typeName}Item`, cache);
|
|
56
|
+
return new GraphQLNonNull(new GraphQLList(inner));
|
|
57
|
+
}
|
|
58
|
+
case 'ZodObject': {
|
|
59
|
+
const cached = cache.get(typeName);
|
|
60
|
+
if (cached)
|
|
61
|
+
return new GraphQLNonNull(cached);
|
|
62
|
+
const shape = resolveShape(d);
|
|
63
|
+
const objectType = new GraphQLObjectType({
|
|
64
|
+
name: typeName,
|
|
65
|
+
fields: () => {
|
|
66
|
+
const fields = {};
|
|
67
|
+
for (const [key, val] of Object.entries(shape)) {
|
|
68
|
+
fields[key] = { type: zodToGqlOutput(val, `${typeName}_${key}`, cache) };
|
|
69
|
+
}
|
|
70
|
+
return fields;
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
cache.set(typeName, objectType);
|
|
74
|
+
return new GraphQLNonNull(objectType);
|
|
75
|
+
}
|
|
76
|
+
case 'ZodEnum': {
|
|
77
|
+
const valList = d.values ?? [];
|
|
78
|
+
const enumValues = {};
|
|
79
|
+
for (const v of valList)
|
|
80
|
+
enumValues[String(v)] = { value: String(v) };
|
|
81
|
+
return new GraphQLNonNull(new GraphQLEnumType({ name: typeName, values: enumValues }));
|
|
82
|
+
}
|
|
83
|
+
case 'ZodAny':
|
|
84
|
+
case 'ZodUnknown':
|
|
85
|
+
default:
|
|
86
|
+
return JSONScalar;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function zodToGqlInput(schema, typeName, cache) {
|
|
90
|
+
const d = zodDef(schema);
|
|
91
|
+
switch (d.typeName) {
|
|
92
|
+
case 'ZodString': return new GraphQLNonNull(GraphQLString);
|
|
93
|
+
case 'ZodNumber': return new GraphQLNonNull(GraphQLFloat);
|
|
94
|
+
case 'ZodBoolean': return new GraphQLNonNull(GraphQLBoolean);
|
|
95
|
+
case 'ZodDefault': {
|
|
96
|
+
// Unwrap default — field is optional in GraphQL (no NonNull)
|
|
97
|
+
const inner = zodToGqlInput(d.innerType, typeName, cache);
|
|
98
|
+
return inner instanceof GraphQLNonNull ? inner.ofType : inner;
|
|
99
|
+
}
|
|
100
|
+
case 'ZodEffects':
|
|
101
|
+
// z.coerce.* and z.preprocess() — unwrap to inner schema
|
|
102
|
+
return zodToGqlInput(d.schema, typeName, cache);
|
|
103
|
+
case 'ZodOptional':
|
|
104
|
+
case 'ZodNullable': {
|
|
105
|
+
const inner = zodToGqlInput(d.innerType, typeName, cache);
|
|
106
|
+
return inner instanceof GraphQLNonNull ? inner.ofType : inner;
|
|
107
|
+
}
|
|
108
|
+
case 'ZodArray': {
|
|
109
|
+
const inner = zodToGqlInput(d.type, `${typeName}Item`, cache);
|
|
110
|
+
return new GraphQLNonNull(new GraphQLList(inner));
|
|
111
|
+
}
|
|
112
|
+
case 'ZodObject': {
|
|
113
|
+
const cached = cache.get(typeName);
|
|
114
|
+
if (cached)
|
|
115
|
+
return new GraphQLNonNull(cached);
|
|
116
|
+
const shape = resolveShape(d);
|
|
117
|
+
const inputType = new GraphQLInputObjectType({
|
|
118
|
+
name: typeName,
|
|
119
|
+
fields: () => {
|
|
120
|
+
const fields = {};
|
|
121
|
+
for (const [key, val] of Object.entries(shape)) {
|
|
122
|
+
fields[key] = { type: zodToGqlInput(val, `${typeName}_${key}`, cache) };
|
|
123
|
+
}
|
|
124
|
+
return fields;
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
cache.set(typeName, inputType);
|
|
128
|
+
return new GraphQLNonNull(inputType);
|
|
129
|
+
}
|
|
130
|
+
case 'ZodEnum': {
|
|
131
|
+
const valList = d.values ?? [];
|
|
132
|
+
const enumValues = {};
|
|
133
|
+
for (const v of valList)
|
|
134
|
+
enumValues[String(v)] = { value: String(v) };
|
|
135
|
+
return new GraphQLNonNull(new GraphQLEnumType({ name: `${typeName}Enum`, values: enumValues }));
|
|
136
|
+
}
|
|
137
|
+
case 'ZodAny':
|
|
138
|
+
case 'ZodUnknown':
|
|
139
|
+
default:
|
|
140
|
+
return JSONScalar;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function toTypeName(dotPath) {
|
|
144
|
+
return dotPath.split(/[._]/).map((p) => p.charAt(0).toUpperCase() + p.slice(1)).join('');
|
|
145
|
+
}
|
|
146
|
+
export function buildGraphQLSchema(registry, invoke) {
|
|
147
|
+
const outputCache = new Map();
|
|
148
|
+
const inputCache = new Map();
|
|
149
|
+
const queryFields = {};
|
|
150
|
+
const mutationFields = {};
|
|
151
|
+
for (const [name, cap] of registry) {
|
|
152
|
+
const fnName = name.replaceAll('.', '_');
|
|
153
|
+
const typeName = toTypeName(name);
|
|
154
|
+
const args = {};
|
|
155
|
+
if (cap.inputSchema !== null) {
|
|
156
|
+
const shape = resolveShape(zodDef(cap.inputSchema));
|
|
157
|
+
for (const [key, val] of Object.entries(shape)) {
|
|
158
|
+
args[key] = { type: zodToGqlInput(val, `${typeName}_${key}Input`, inputCache) };
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const returnType = cap.outputSchema !== null
|
|
162
|
+
? zodToGqlOutput(cap.outputSchema, `${typeName}Output`, outputCache)
|
|
163
|
+
: JSONScalar;
|
|
164
|
+
const field = {
|
|
165
|
+
type: returnType,
|
|
166
|
+
args,
|
|
167
|
+
resolve: async (_root, resolvedArgs, context) => {
|
|
168
|
+
const signal = AbortSignal.timeout(30_000);
|
|
169
|
+
const response = await invoke({
|
|
170
|
+
capability: name,
|
|
171
|
+
input: resolvedArgs,
|
|
172
|
+
headers: context?.headers ?? {},
|
|
173
|
+
signal,
|
|
174
|
+
});
|
|
175
|
+
if (!response.ok) {
|
|
176
|
+
const { error, message } = response.error;
|
|
177
|
+
throw new Error(`${error}: ${message}`);
|
|
178
|
+
}
|
|
179
|
+
return response.data;
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
if (cap.intent === 'query') {
|
|
183
|
+
queryFields[fnName] = field;
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
mutationFields[fnName] = field;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
// GraphQL requires at least one field in Query
|
|
190
|
+
if (Object.keys(queryFields).length === 0) {
|
|
191
|
+
queryFields['_empty'] = { type: GraphQLString, resolve: () => 'empty' };
|
|
192
|
+
}
|
|
193
|
+
return new GraphQLSchema({
|
|
194
|
+
query: new GraphQLObjectType({ name: 'Query', fields: queryFields }),
|
|
195
|
+
...(Object.keys(mutationFields).length > 0
|
|
196
|
+
? { mutation: new GraphQLObjectType({ name: 'Mutation', fields: mutationFields }) }
|
|
197
|
+
: {}),
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=schema-builder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-builder.js","sourceRoot":"","sources":["../src/schema-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EACL,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,YAAY,EACZ,cAAc,EACd,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,eAAe,EACf,IAAI,GACL,MAAM,SAAS,CAAC;AAIjB,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,iBAAiB,CAAC;IAC9C,IAAI,EAAE,MAAM;IACZ,WAAW,EAAE,sBAAsB;IACnC,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACnB,UAAU,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACpB,YAAY,EAAE,CAAC,GAAG,EAAE,EAAE;QACpB,QAAQ,GAAG,CAAC,IAAI,EAAE,CAAC;YACjB,KAAK,IAAI,CAAC,GAAG,CAAC,CAAK,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,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
/**
|
|
2
|
+
* transport.ts — GraphQL transport using graphql-http (spec-compliant).
|
|
3
|
+
*
|
|
4
|
+
* Serves a GraphQL endpoint and an optional GraphiQL playground.
|
|
5
|
+
* Forwards request headers to capability resolvers via context.
|
|
6
|
+
*/
|
|
7
|
+
import type { GroupTree, TransportWithCapabilities } from '@capixjs/core';
|
|
8
|
+
export type GraphQLTransportOptions = {
|
|
9
|
+
readonly port: number;
|
|
10
|
+
readonly host?: string;
|
|
11
|
+
/** URL path for the GraphQL endpoint. Default: '/graphql' */
|
|
12
|
+
readonly path?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Serve a GraphiQL playground at `{path}/playground`. Default: true.
|
|
15
|
+
* Set to false to disable in production.
|
|
16
|
+
*/
|
|
17
|
+
readonly playground?: boolean;
|
|
18
|
+
/** Capability registry for this transport only. Overrides the server-level default. */
|
|
19
|
+
readonly capabilities?: GroupTree;
|
|
20
|
+
};
|
|
21
|
+
export declare function graphqlTransport(options: GraphQLTransportOptions): TransportWithCapabilities;
|
|
22
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAqC,SAAS,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE7G,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,uFAAuF;IACvF,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,CAAC;CACnC,CAAC;AA2BF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,yBAAyB,CA2E5F"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* transport.ts — GraphQL transport using graphql-http (spec-compliant).
|
|
3
|
+
*
|
|
4
|
+
* Serves a GraphQL endpoint and an optional GraphiQL playground.
|
|
5
|
+
* Forwards request headers to capability resolvers via context.
|
|
6
|
+
*/
|
|
7
|
+
import * as http from 'node:http';
|
|
8
|
+
import { createHandler } from 'graphql-http/lib/use/node';
|
|
9
|
+
import { buildGraphQLSchema } from './schema-builder.js';
|
|
10
|
+
function playgroundHtml(endpoint) {
|
|
11
|
+
return `<!DOCTYPE html>
|
|
12
|
+
<html>
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="utf-8" />
|
|
15
|
+
<title>Capix GraphQL Playground</title>
|
|
16
|
+
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
|
|
17
|
+
<style>body { margin: 0; } #graphiql { height: 100vh; }</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<div id="graphiql"></div>
|
|
21
|
+
<script src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
|
22
|
+
<script src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
|
23
|
+
<script src="https://unpkg.com/graphiql/graphiql.min.js"></script>
|
|
24
|
+
<script>
|
|
25
|
+
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
|
|
26
|
+
root.render(React.createElement(GraphiQL, {
|
|
27
|
+
fetcher: GraphiQL.createFetcher({ url: '${endpoint}' }),
|
|
28
|
+
defaultEditorToolsVisibility: true,
|
|
29
|
+
}));
|
|
30
|
+
</script>
|
|
31
|
+
</body>
|
|
32
|
+
</html>`;
|
|
33
|
+
}
|
|
34
|
+
export function graphqlTransport(options) {
|
|
35
|
+
let server = null;
|
|
36
|
+
const gqlPath = options.path ?? '/graphql';
|
|
37
|
+
const playPath = `${gqlPath}/playground`;
|
|
38
|
+
const showPlayground = options.playground !== false;
|
|
39
|
+
return {
|
|
40
|
+
...(options.capabilities !== undefined ? { _capabilities: options.capabilities } : {}),
|
|
41
|
+
async mount(invoke, mountOptions) {
|
|
42
|
+
const schema = buildGraphQLSchema(mountOptions.registry, invoke);
|
|
43
|
+
const gqlHandler = createHandler({
|
|
44
|
+
schema,
|
|
45
|
+
context: (req) => {
|
|
46
|
+
const rawHeaders = req.raw.headers;
|
|
47
|
+
const headers = {};
|
|
48
|
+
for (const [key, val] of Object.entries(rawHeaders)) {
|
|
49
|
+
if (val !== undefined) {
|
|
50
|
+
headers[key] = Array.isArray(val) ? val.join(', ') : val;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return { headers };
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
function httpHandler(req, res) {
|
|
57
|
+
const url = req.url ?? '/';
|
|
58
|
+
const pathname = url.split('?')[0] ?? '';
|
|
59
|
+
if (showPlayground && pathname === playPath) {
|
|
60
|
+
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
|
|
61
|
+
res.end(playgroundHtml(gqlPath));
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (pathname === gqlPath || pathname === `${gqlPath}/`) {
|
|
65
|
+
gqlHandler(req, res).catch((err) => {
|
|
66
|
+
console.error('[capix:graphql] Handler error:', err);
|
|
67
|
+
if (!res.headersSent) {
|
|
68
|
+
res.writeHead(500);
|
|
69
|
+
res.end('Internal error');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
res.writeHead(404);
|
|
75
|
+
res.end();
|
|
76
|
+
}
|
|
77
|
+
console.log('\nCapix GraphQL transport starting...');
|
|
78
|
+
console.log(` ✓ GraphQL http://localhost:${options.port}${gqlPath}`);
|
|
79
|
+
if (showPlayground) {
|
|
80
|
+
console.log(` ✓ Playground http://localhost:${options.port}${playPath}`);
|
|
81
|
+
}
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
server = http.createServer(httpHandler);
|
|
84
|
+
server.on('error', reject);
|
|
85
|
+
server.listen(options.port, options.host ?? '0.0.0.0', () => resolve());
|
|
86
|
+
});
|
|
87
|
+
},
|
|
88
|
+
async unmount() {
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
if (!server)
|
|
91
|
+
return resolve();
|
|
92
|
+
server.close((err) => {
|
|
93
|
+
if (err)
|
|
94
|
+
reject(err);
|
|
95
|
+
else
|
|
96
|
+
resolve();
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAiBzD,SAAS,cAAc,CAAC,QAAgB;IACtC,OAAO;;;;;;;;;;;;;;;;gDAgBuC,QAAQ;;;;;QAKhD,CAAC;AACT,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAgC;IAC/D,IAAI,MAAM,GAAuB,IAAI,CAAC;IAEtC,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC;IAC3C,MAAM,QAAQ,GAAG,GAAG,OAAO,aAAa,CAAC;IACzC,MAAM,cAAc,GAAG,OAAO,CAAC,UAAU,KAAK,KAAK,CAAC;IAEpD,OAAO;QACL,GAAG,CAAC,OAAO,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAEtF,KAAK,CAAC,KAAK,CAAC,MAAgB,EAAE,YAA0B;YAC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AC,GAAG,EAAE,EAAE;oBACnB,IAAI,GAAG;wBAAE,MAAM,CAAC,GAAG,CAAC,CAAC;;wBAChB,OAAO,EAAE,CAAC;gBACjB,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@capixjs/transport-graphql",
|
|
3
|
+
"version": "0.1.0-alpha.1",
|
|
4
|
+
"description": "Capix GraphQL transport",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"!dist/**/*.test.*",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"keywords": [
|
|
21
|
+
"capix",
|
|
22
|
+
"graphql",
|
|
23
|
+
"transport",
|
|
24
|
+
"typescript"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"test": "vitest run",
|
|
32
|
+
"typecheck": "tsc --noEmit"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"graphql": "^16.0.0",
|
|
36
|
+
"graphql-http": "^1.22.0"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"@capixjs/core": ">=0.1.0-0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"@types/node": "^20.0.0",
|
|
43
|
+
"typescript": "^5.5.0",
|
|
44
|
+
"vitest": "^1.6.0",
|
|
45
|
+
"zod": "^3.23.0",
|
|
46
|
+
"@capixjs/core": "workspace:*"
|
|
47
|
+
}
|
|
48
|
+
}
|