@cubicecho/graphql-mdns-discovery 0.0.0-stage → 0.1.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 +21 -0
- package/README.md +132 -2
- package/dist/client/discover.d.ts +62 -0
- package/dist/client/discover.js +64 -0
- package/dist/core/consts.d.ts +6 -0
- package/dist/core/consts.js +6 -0
- package/dist/document/graphql-services.d.ts +200 -0
- package/dist/document/graphql-services.js +179 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +18 -0
- package/dist/mdns/advertise.d.ts +60 -0
- package/dist/mdns/advertise.js +33 -0
- package/dist/mdns/browse.d.ts +38 -0
- package/dist/mdns/browse.js +44 -0
- package/dist/mdns/txt-record.d.ts +33 -0
- package/dist/mdns/txt-record.js +47 -0
- package/dist/mdns/watch-services.d.ts +60 -0
- package/dist/mdns/watch-services.js +59 -0
- package/dist/mdns.d.ts +14 -0
- package/dist/mdns.js +14 -0
- package/dist/serve/graphql-discovery-middleware.d.ts +48 -0
- package/dist/serve/graphql-discovery-middleware.js +56 -0
- package/llms.txt +81 -0
- package/package.json +80 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Benjamin Van Treese
|
|
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
CHANGED
|
@@ -1,3 +1,133 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @cubicecho/graphql-mdns-discovery
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Advertise and discover GraphQL APIs.
|
|
4
|
+
|
|
5
|
+
A host lists its GraphQL APIs in a public document at `/.well-known/graphql-services.json`. Each entry
|
|
6
|
+
gives the API's endpoint, its subscription transport, where to download its SDL, and the headers a client
|
|
7
|
+
must supply (never their values). On a LAN the host also announces itself as a `_graphql._tcp` mDNS
|
|
8
|
+
service, so a client such as Symphony finds upstreams without anyone typing in URLs.
|
|
9
|
+
|
|
10
|
+
It is the GraphQL counterpart of [`@cubicecho/mcp-discovery`](https://github.com/cubicecho/mcp-discovery),
|
|
11
|
+
and both are built on [`@cubicecho/discovery-core`](https://github.com/cubicecho/discovery-core). An app
|
|
12
|
+
that serves both an MCP endpoint (graphql-mcp) and a GraphQL API can use both packages at once. See
|
|
13
|
+
"Using it beside mcp-discovery" below.
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @cubicecho/graphql-mdns-discovery zod
|
|
17
|
+
npm install bonjour-service # only for ./mdns
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick start: be found on the LAN
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { hostname } from 'node:os';
|
|
24
|
+
import { graphqlDiscoveryMiddleware, hostSlug } from '@cubicecho/graphql-mdns-discovery';
|
|
25
|
+
import { advertiseGraphql } from '@cubicecho/graphql-mdns-discovery/mdns';
|
|
26
|
+
|
|
27
|
+
app.use(
|
|
28
|
+
graphqlDiscoveryMiddleware(() => [
|
|
29
|
+
{
|
|
30
|
+
path: '/graphql', // the default
|
|
31
|
+
service: ({ origin }) => ({
|
|
32
|
+
name: `io.github.cubicecho.ethos.${hostSlug(hostname())}/api`,
|
|
33
|
+
title: 'Ethos',
|
|
34
|
+
version: '2.1.0',
|
|
35
|
+
// endpoint is filled in from `path` and the origin the request reached.
|
|
36
|
+
subscriptions: { url: `${origin}/graphql/ws`, protocol: 'graphql-ws' },
|
|
37
|
+
headers: [{ name: 'Authorization', isRequired: true, isSecret: true }],
|
|
38
|
+
introspection: true,
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
]),
|
|
42
|
+
);
|
|
43
|
+
app.listen(3000, '0.0.0.0', async () => {
|
|
44
|
+
const advertisement = await advertiseGraphql({ name: 'Ethos on nas', port: 3000 });
|
|
45
|
+
process.on('SIGTERM', () => advertisement.stop());
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Mount the middleware before any auth guard, since the document is public. Listen on the LAN, not only
|
|
50
|
+
on localhost, and advertise after `listen`. `createGraphqlAdvertiser({ isWanted, options, log })` keeps
|
|
51
|
+
the announcement in step with a setting that can change at runtime.
|
|
52
|
+
|
|
53
|
+
## Finding APIs
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
import { discoverGraphql } from '@cubicecho/graphql-mdns-discovery';
|
|
57
|
+
import { watchGraphqlServices } from '@cubicecho/graphql-mdns-discovery/mdns';
|
|
58
|
+
|
|
59
|
+
// One host you already know:
|
|
60
|
+
const { services, failures } = await discoverGraphql('http://nas.local:3000');
|
|
61
|
+
|
|
62
|
+
// Everything on the LAN, as it comes and goes:
|
|
63
|
+
const watch = await watchGraphqlServices({
|
|
64
|
+
onUp: ({ key, service, connection }) => {
|
|
65
|
+
// connection.url, connection.subscriptions, connection.schemaUrl are absolute;
|
|
66
|
+
// connection.requiredHeaders lists what the user must supply, e.g. ["Authorization"].
|
|
67
|
+
},
|
|
68
|
+
onDown: ({ key }) => {},
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
A bad entry lands in `failures` and the rest still come back. Every fetch is bounded in time and size
|
|
73
|
+
(`FETCH_DEFAULTS`). The watcher re-reads each host's document every `refreshMs` (5 min). Anything on the LAN
|
|
74
|
+
can advertise and the document is unauthenticated, so what to connect to is the watcher's policy. A
|
|
75
|
+
process that also advertises sees itself.
|
|
76
|
+
|
|
77
|
+
## The document
|
|
78
|
+
|
|
79
|
+
```json
|
|
80
|
+
{
|
|
81
|
+
"specVersion": "1.0",
|
|
82
|
+
"services": [
|
|
83
|
+
{
|
|
84
|
+
"name": "io.github.cubicecho.ethos.nas/api",
|
|
85
|
+
"title": "Ethos",
|
|
86
|
+
"version": "2.1.0",
|
|
87
|
+
"endpoint": { "url": "http://192.168.1.20:3000/graphql", "methods": ["POST"] },
|
|
88
|
+
"subscriptions": { "url": "http://192.168.1.20:3000/graphql/ws", "protocol": "graphql-ws" },
|
|
89
|
+
"headers": [{ "name": "Authorization", "isRequired": true, "isSecret": true }],
|
|
90
|
+
"introspection": true,
|
|
91
|
+
"schemaUrl": "/graphql/schema.graphql",
|
|
92
|
+
"_meta": { "io.github.cubicecho.symphony/role": "unified" }
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
It is served as `application/vnd.cubicecho.graphql-services+json` with open CORS, `Cache-Control: public,
|
|
99
|
+
max-age=3600`, an `ETag` and `304`. URLs can be absolute or paths on the document's host. Readers accept any
|
|
100
|
+
1.x `specVersion` and keep fields they don't know. Don't put tokens, private hosts or per-user data in it.
|
|
101
|
+
|
|
102
|
+
## mDNS
|
|
103
|
+
|
|
104
|
+
Service type `_graphql._tcp`, instance name = the app's display name, port = its HTTP port.
|
|
105
|
+
|
|
106
|
+
| TXT key | Example | Meaning |
|
|
107
|
+
| --- | --- | --- |
|
|
108
|
+
| `txtvers` | `1` | Version of this TXT layout |
|
|
109
|
+
| `path` | `/graphql` | The main endpoint |
|
|
110
|
+
| `doc` | `/.well-known/graphql-services.json` | The services document |
|
|
111
|
+
| `tls` | `1` | Present when the host is HTTPS |
|
|
112
|
+
|
|
113
|
+
mDNS needs multicast, which Docker's default bridge network drops, so a container that advertises needs
|
|
114
|
+
`network_mode: host`.
|
|
115
|
+
|
|
116
|
+
## Using it beside mcp-discovery
|
|
117
|
+
|
|
118
|
+
| | mcp-discovery | graphql-mdns-discovery |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| Service type | `_mcp._tcp` | `_graphql._tcp` |
|
|
121
|
+
| HTTP paths | `/.well-known/ai-catalog.json`, `*/server-card` | `/.well-known/graphql-services.json` |
|
|
122
|
+
| Advertise / watch | `advertise`, `watchServers` | `advertiseGraphql`, `watchGraphqlServices` |
|
|
123
|
+
| mDNS responder | shared through discovery-core | shared through discovery-core |
|
|
124
|
+
|
|
125
|
+
- Mount both middlewares, in either order. Each answers only its own paths and passes everything else on.
|
|
126
|
+
- Advertise both, even under the same instance name and port. Each watcher sees only its own type.
|
|
127
|
+
- Stop either one alone. The other stays resolvable: the shared responder puts back the host address
|
|
128
|
+
records that bonjour-service would otherwise withdraw for both.
|
|
129
|
+
- Import from both without aliasing. The only names both export are the shared ones from discovery-core
|
|
130
|
+
(the errors, `hostSlug`, the defaults), and those are the same objects, so `instanceof` works across them.
|
|
131
|
+
- Give each its own setting in your app (e.g. `MCP_MDNS` and `GRAPHQL_MDNS`). Neither package reads env.
|
|
132
|
+
|
|
133
|
+
`tests/coexistence.test.ts` checks all of this, over real multicast when not in CI.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a host's GraphQL services document, bounded in time and size, with each service checked on its own.
|
|
3
|
+
*/
|
|
4
|
+
import { DiscoveryError, type FetchOptions, type FetchSettings } from '@cubicecho/discovery-core';
|
|
5
|
+
import { type GraphqlService, type GraphqlServiceConnection, type GraphqlServicesEnvelope } from '../document/graphql-services.ts';
|
|
6
|
+
/** A service found in a document, with how to reach it. */
|
|
7
|
+
export interface DiscoveredGraphqlService {
|
|
8
|
+
service: GraphqlService;
|
|
9
|
+
connection: GraphqlServiceConnection;
|
|
10
|
+
}
|
|
11
|
+
/** A document entry that could not be read. */
|
|
12
|
+
export interface GraphqlDiscoveryFailure {
|
|
13
|
+
/** Its position in `services`. */
|
|
14
|
+
index: number;
|
|
15
|
+
error: DiscoveryError;
|
|
16
|
+
}
|
|
17
|
+
/** What a read of one document found. */
|
|
18
|
+
export interface GraphqlDiscovery {
|
|
19
|
+
documentUrl: string;
|
|
20
|
+
/** The document as read; its services are the raw entries. */
|
|
21
|
+
document: GraphqlServicesEnvelope;
|
|
22
|
+
/** Every service that was read, in document order. */
|
|
23
|
+
services: DiscoveredGraphqlService[];
|
|
24
|
+
/** Every entry that failed, in document order. */
|
|
25
|
+
failures: GraphqlDiscoveryFailure[];
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Fetches a GraphQL services document and checks its envelope.
|
|
29
|
+
*
|
|
30
|
+
* @param url - The document's URL.
|
|
31
|
+
* @param [overrides] - Fetch settings to change.
|
|
32
|
+
* @param [options] - Abort signal and fetch implementation.
|
|
33
|
+
* @returns The envelope; its services are not yet checked.
|
|
34
|
+
* @throws {@link DocumentFetchError} If it could not be fetched.
|
|
35
|
+
* @throws {@link InvalidDocumentError} If it is not a 1.x document.
|
|
36
|
+
*/
|
|
37
|
+
export declare function fetchGraphqlServicesDocument(url: string, overrides?: Partial<FetchSettings>, options?: FetchOptions): Promise<GraphqlServicesEnvelope>;
|
|
38
|
+
/**
|
|
39
|
+
* Discovers the GraphQL APIs a document lists, wherever it is served (e.g. an mDNS host's `documentUrl`).
|
|
40
|
+
*
|
|
41
|
+
* @param documentUrl - The document's URL; relative URLs in it resolve against this.
|
|
42
|
+
* @param [overrides] - Fetch settings to change.
|
|
43
|
+
* @param [options] - Abort signal and fetch implementation.
|
|
44
|
+
* @returns The document, the services read from it, and the entries that failed.
|
|
45
|
+
* @throws {@link DocumentFetchError} If the document itself could not be fetched.
|
|
46
|
+
* @throws {@link InvalidDocumentError} If it is not a 1.x document.
|
|
47
|
+
*
|
|
48
|
+
* @remarks
|
|
49
|
+
* A document is advisory: check what it claims against the live endpoint before relying on it.
|
|
50
|
+
*/
|
|
51
|
+
export declare function discoverGraphqlDocument(documentUrl: string, overrides?: Partial<FetchSettings>, options?: FetchOptions): Promise<GraphqlDiscovery>;
|
|
52
|
+
/**
|
|
53
|
+
* Discovers the GraphQL APIs a host advertises, from its `/.well-known/graphql-services.json`.
|
|
54
|
+
*
|
|
55
|
+
* @param origin - The host, e.g. `http://nas.local:3000`; any path on it is ignored.
|
|
56
|
+
* @param [overrides] - Fetch settings to change.
|
|
57
|
+
* @param [options] - Abort signal and fetch implementation.
|
|
58
|
+
* @returns The document, the services read from it, and the entries that failed.
|
|
59
|
+
* @throws {@link DocumentFetchError} If the document itself could not be fetched.
|
|
60
|
+
* @throws {@link InvalidDocumentError} If it is not a 1.x document.
|
|
61
|
+
*/
|
|
62
|
+
export declare function discoverGraphql(origin: string, overrides?: Partial<FetchSettings>, options?: FetchOptions): Promise<GraphqlDiscovery>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a host's GraphQL services document, bounded in time and size, with each service checked on its own.
|
|
3
|
+
*/
|
|
4
|
+
import { DiscoveryError, fetchJson } from '@cubicecho/discovery-core';
|
|
5
|
+
import { GRAPHQL_SERVICES_MEDIA_TYPE, GRAPHQL_SERVICES_WELL_KNOWN_PATH } from '../core/consts.js';
|
|
6
|
+
import { graphqlServiceConnection, parseGraphqlService, parseGraphqlServicesEnvelope, } from '../document/graphql-services.js';
|
|
7
|
+
/**
|
|
8
|
+
* Fetches a GraphQL services document and checks its envelope.
|
|
9
|
+
*
|
|
10
|
+
* @param url - The document's URL.
|
|
11
|
+
* @param [overrides] - Fetch settings to change.
|
|
12
|
+
* @param [options] - Abort signal and fetch implementation.
|
|
13
|
+
* @returns The envelope; its services are not yet checked.
|
|
14
|
+
* @throws {@link DocumentFetchError} If it could not be fetched.
|
|
15
|
+
* @throws {@link InvalidDocumentError} If it is not a 1.x document.
|
|
16
|
+
*/
|
|
17
|
+
export async function fetchGraphqlServicesDocument(url, overrides = {}, options = {}) {
|
|
18
|
+
return parseGraphqlServicesEnvelope(await fetchJson(url, GRAPHQL_SERVICES_MEDIA_TYPE, overrides, options), url);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Discovers the GraphQL APIs a document lists, wherever it is served (e.g. an mDNS host's `documentUrl`).
|
|
22
|
+
*
|
|
23
|
+
* @param documentUrl - The document's URL; relative URLs in it resolve against this.
|
|
24
|
+
* @param [overrides] - Fetch settings to change.
|
|
25
|
+
* @param [options] - Abort signal and fetch implementation.
|
|
26
|
+
* @returns The document, the services read from it, and the entries that failed.
|
|
27
|
+
* @throws {@link DocumentFetchError} If the document itself could not be fetched.
|
|
28
|
+
* @throws {@link InvalidDocumentError} If it is not a 1.x document.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* A document is advisory: check what it claims against the live endpoint before relying on it.
|
|
32
|
+
*/
|
|
33
|
+
export async function discoverGraphqlDocument(documentUrl, overrides = {}, options = {}) {
|
|
34
|
+
const document = await fetchGraphqlServicesDocument(documentUrl, overrides, options);
|
|
35
|
+
const services = [];
|
|
36
|
+
const failures = [];
|
|
37
|
+
document.services.forEach((entry, index) => {
|
|
38
|
+
try {
|
|
39
|
+
const service = parseGraphqlService(entry, `${documentUrl} services[${index}]`);
|
|
40
|
+
services.push({ service, connection: graphqlServiceConnection(service, documentUrl) });
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error instanceof DiscoveryError) {
|
|
44
|
+
failures.push({ index, error });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
throw error;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return { documentUrl, document, services, failures };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Discovers the GraphQL APIs a host advertises, from its `/.well-known/graphql-services.json`.
|
|
54
|
+
*
|
|
55
|
+
* @param origin - The host, e.g. `http://nas.local:3000`; any path on it is ignored.
|
|
56
|
+
* @param [overrides] - Fetch settings to change.
|
|
57
|
+
* @param [options] - Abort signal and fetch implementation.
|
|
58
|
+
* @returns The document, the services read from it, and the entries that failed.
|
|
59
|
+
* @throws {@link DocumentFetchError} If the document itself could not be fetched.
|
|
60
|
+
* @throws {@link InvalidDocumentError} If it is not a 1.x document.
|
|
61
|
+
*/
|
|
62
|
+
export function discoverGraphql(origin, overrides = {}, options = {}) {
|
|
63
|
+
return discoverGraphqlDocument(new URL(GRAPHQL_SERVICES_WELL_KNOWN_PATH, origin).href, overrides, options);
|
|
64
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Media type of a GraphQL services document. */
|
|
2
|
+
export declare const GRAPHQL_SERVICES_MEDIA_TYPE = "application/vnd.cubicecho.graphql-services+json";
|
|
3
|
+
/** Where a host serves its GraphQL services document (RFC 8615). It never overlaps mcp-discovery's paths. */
|
|
4
|
+
export declare const GRAPHQL_SERVICES_WELL_KNOWN_PATH = "/.well-known/graphql-services.json";
|
|
5
|
+
/** The endpoint path assumed when an mDNS record names none, and advertised when none is given. */
|
|
6
|
+
export declare const DEFAULT_GRAPHQL_PATH = "/graphql";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Media type of a GraphQL services document. */
|
|
2
|
+
export const GRAPHQL_SERVICES_MEDIA_TYPE = 'application/vnd.cubicecho.graphql-services+json';
|
|
3
|
+
/** Where a host serves its GraphQL services document (RFC 8615). It never overlaps mcp-discovery's paths. */
|
|
4
|
+
export const GRAPHQL_SERVICES_WELL_KNOWN_PATH = '/.well-known/graphql-services.json';
|
|
5
|
+
/** The endpoint path assumed when an mDNS record names none, and advertised when none is given. */
|
|
6
|
+
export const DEFAULT_GRAPHQL_PATH = '/graphql';
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The GraphQL services document: what a host lists at `/.well-known/graphql-services.json`.
|
|
3
|
+
*
|
|
4
|
+
* There is no standard for advertising a GraphQL API, so the layout is this package's, versioned by
|
|
5
|
+
* `specVersion`. It follows the same rules as an MCP Server Card: it is public, it never carries credentials,
|
|
6
|
+
* it declares headers a client must supply without their values, and readers keep fields they don't know.
|
|
7
|
+
*/
|
|
8
|
+
import { z } from 'zod';
|
|
9
|
+
/** The `specVersion` this package writes. */
|
|
10
|
+
export declare const GRAPHQL_SERVICES_SPEC_VERSION = "1.0";
|
|
11
|
+
/** The HTTP methods a GraphQL endpoint can take queries on. */
|
|
12
|
+
export declare const GraphqlMethod: {
|
|
13
|
+
readonly Post: 'POST';
|
|
14
|
+
readonly Get: 'GET';
|
|
15
|
+
};
|
|
16
|
+
export type GraphqlMethod = (typeof GraphqlMethod)[keyof typeof GraphqlMethod];
|
|
17
|
+
/** The subscription transports a service can offer. */
|
|
18
|
+
export declare const SubscriptionProtocol: {
|
|
19
|
+
readonly GraphqlWs: 'graphql-ws';
|
|
20
|
+
readonly GraphqlSse: 'graphql-sse';
|
|
21
|
+
};
|
|
22
|
+
export type SubscriptionProtocol = (typeof SubscriptionProtocol)[keyof typeof SubscriptionProtocol];
|
|
23
|
+
/** A header a client sends with every request; the value is never in the document. */
|
|
24
|
+
export declare const graphqlHeaderSchema: z.ZodObject<{
|
|
25
|
+
name: z.ZodString;
|
|
26
|
+
description: z.ZodOptional<z.ZodString>;
|
|
27
|
+
isRequired: z.ZodOptional<z.ZodBoolean>;
|
|
28
|
+
isSecret: z.ZodOptional<z.ZodBoolean>;
|
|
29
|
+
}, z.core.$loose>;
|
|
30
|
+
/** A header a client sends with every request; never its value. */
|
|
31
|
+
export type GraphqlHeader = z.infer<typeof graphqlHeaderSchema>;
|
|
32
|
+
/** Where queries and mutations go. */
|
|
33
|
+
export declare const graphqlEndpointSchema: z.ZodObject<{
|
|
34
|
+
url: z.ZodString;
|
|
35
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
36
|
+
readonly Post: 'POST';
|
|
37
|
+
readonly Get: 'GET';
|
|
38
|
+
}>>>;
|
|
39
|
+
}, z.core.$loose>;
|
|
40
|
+
/** Where a service takes queries and mutations. */
|
|
41
|
+
export type GraphqlEndpoint = z.infer<typeof graphqlEndpointSchema>;
|
|
42
|
+
/** Where subscriptions go, and over which protocol. */
|
|
43
|
+
export declare const graphqlSubscriptionsSchema: z.ZodObject<{
|
|
44
|
+
url: z.ZodString;
|
|
45
|
+
protocol: z.ZodEnum<{
|
|
46
|
+
readonly GraphqlWs: 'graphql-ws';
|
|
47
|
+
readonly GraphqlSse: 'graphql-sse';
|
|
48
|
+
}>;
|
|
49
|
+
}, z.core.$loose>;
|
|
50
|
+
/** Where a service takes subscriptions, and over which protocol. */
|
|
51
|
+
export type GraphqlSubscriptions = z.infer<typeof graphqlSubscriptionsSchema>;
|
|
52
|
+
/** One GraphQL API a host serves. */
|
|
53
|
+
export declare const graphqlServiceSchema: z.ZodObject<{
|
|
54
|
+
name: z.ZodString;
|
|
55
|
+
title: z.ZodOptional<z.ZodString>;
|
|
56
|
+
description: z.ZodOptional<z.ZodString>;
|
|
57
|
+
version: z.ZodOptional<z.ZodString>;
|
|
58
|
+
endpoint: z.ZodObject<{
|
|
59
|
+
url: z.ZodString;
|
|
60
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
61
|
+
readonly Post: 'POST';
|
|
62
|
+
readonly Get: 'GET';
|
|
63
|
+
}>>>;
|
|
64
|
+
}, z.core.$loose>;
|
|
65
|
+
subscriptions: z.ZodOptional<z.ZodObject<{
|
|
66
|
+
url: z.ZodString;
|
|
67
|
+
protocol: z.ZodEnum<{
|
|
68
|
+
readonly GraphqlWs: 'graphql-ws';
|
|
69
|
+
readonly GraphqlSse: 'graphql-sse';
|
|
70
|
+
}>;
|
|
71
|
+
}, z.core.$loose>>;
|
|
72
|
+
headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
73
|
+
name: z.ZodString;
|
|
74
|
+
description: z.ZodOptional<z.ZodString>;
|
|
75
|
+
isRequired: z.ZodOptional<z.ZodBoolean>;
|
|
76
|
+
isSecret: z.ZodOptional<z.ZodBoolean>;
|
|
77
|
+
}, z.core.$loose>>>;
|
|
78
|
+
introspection: z.ZodOptional<z.ZodBoolean>;
|
|
79
|
+
schemaUrl: z.ZodOptional<z.ZodString>;
|
|
80
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
81
|
+
}, z.core.$loose>;
|
|
82
|
+
/** One GraphQL API a host serves. */
|
|
83
|
+
export type GraphqlService = z.infer<typeof graphqlServiceSchema>;
|
|
84
|
+
/** What `createGraphqlService` takes. */
|
|
85
|
+
export type GraphqlServiceFields = z.input<typeof graphqlServiceSchema>;
|
|
86
|
+
/** A service whose endpoint may still be left out. */
|
|
87
|
+
declare const graphqlServiceDraftSchema: z.ZodObject<{
|
|
88
|
+
name: z.ZodString;
|
|
89
|
+
title: z.ZodOptional<z.ZodString>;
|
|
90
|
+
description: z.ZodOptional<z.ZodString>;
|
|
91
|
+
version: z.ZodOptional<z.ZodString>;
|
|
92
|
+
endpoint: z.ZodOptional<z.ZodObject<{
|
|
93
|
+
url: z.ZodString;
|
|
94
|
+
methods: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
95
|
+
readonly Post: 'POST';
|
|
96
|
+
readonly Get: 'GET';
|
|
97
|
+
}>>>;
|
|
98
|
+
}, z.core.$loose>>;
|
|
99
|
+
subscriptions: z.ZodOptional<z.ZodObject<{
|
|
100
|
+
url: z.ZodString;
|
|
101
|
+
protocol: z.ZodEnum<{
|
|
102
|
+
readonly GraphqlWs: 'graphql-ws';
|
|
103
|
+
readonly GraphqlSse: 'graphql-sse';
|
|
104
|
+
}>;
|
|
105
|
+
}, z.core.$loose>>;
|
|
106
|
+
headers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
107
|
+
name: z.ZodString;
|
|
108
|
+
description: z.ZodOptional<z.ZodString>;
|
|
109
|
+
isRequired: z.ZodOptional<z.ZodBoolean>;
|
|
110
|
+
isSecret: z.ZodOptional<z.ZodBoolean>;
|
|
111
|
+
}, z.core.$loose>>>;
|
|
112
|
+
introspection: z.ZodOptional<z.ZodBoolean>;
|
|
113
|
+
schemaUrl: z.ZodOptional<z.ZodString>;
|
|
114
|
+
_meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
115
|
+
}, z.core.$loose>;
|
|
116
|
+
/** A service as a middleware's builder returns it: the endpoint may be left out, and is then the advertised path. */
|
|
117
|
+
export type GraphqlServiceDraft = z.input<typeof graphqlServiceDraftSchema>;
|
|
118
|
+
/**
|
|
119
|
+
* The envelope of a GraphQL services document.
|
|
120
|
+
*
|
|
121
|
+
* @remarks
|
|
122
|
+
* Its services are read one by one (`parseGraphqlService`), so one bad entry doesn't hide the rest.
|
|
123
|
+
*/
|
|
124
|
+
export declare const graphqlServicesDocumentSchema: z.ZodObject<{
|
|
125
|
+
specVersion: z.ZodString;
|
|
126
|
+
services: z.ZodArray<z.ZodUnknown>;
|
|
127
|
+
}, z.core.$loose>;
|
|
128
|
+
/** A document as read from the network: the envelope valid, the services not yet checked. */
|
|
129
|
+
export type GraphqlServicesEnvelope = z.infer<typeof graphqlServicesDocumentSchema>;
|
|
130
|
+
/** A GraphQL services document with every service valid, as a host builds it. */
|
|
131
|
+
export type GraphqlServicesDocument = Omit<GraphqlServicesEnvelope, 'services'> & {
|
|
132
|
+
services: GraphqlService[];
|
|
133
|
+
};
|
|
134
|
+
/**
|
|
135
|
+
* Validates one service from a document.
|
|
136
|
+
*
|
|
137
|
+
* @param value - The parsed JSON.
|
|
138
|
+
* @param source - Where it came from, for the message.
|
|
139
|
+
* @returns The service.
|
|
140
|
+
* @throws {@link InvalidDocumentError} If it does not match, listing each issue.
|
|
141
|
+
*/
|
|
142
|
+
export declare function parseGraphqlService(value: unknown, source: string): GraphqlService;
|
|
143
|
+
/**
|
|
144
|
+
* Validates a document's envelope, leaving its services to be read one by one.
|
|
145
|
+
*
|
|
146
|
+
* @param value - The parsed JSON.
|
|
147
|
+
* @param source - Where it came from, for the message.
|
|
148
|
+
* @returns The envelope.
|
|
149
|
+
* @throws {@link InvalidDocumentError} If it is not a 1.x document.
|
|
150
|
+
*/
|
|
151
|
+
export declare function parseGraphqlServicesEnvelope(value: unknown, source: string): GraphqlServicesEnvelope;
|
|
152
|
+
/**
|
|
153
|
+
* Validates a whole document, every service included.
|
|
154
|
+
*
|
|
155
|
+
* @param value - The parsed JSON.
|
|
156
|
+
* @param source - Where it came from, for the message.
|
|
157
|
+
* @returns The document.
|
|
158
|
+
* @throws {@link InvalidDocumentError} If the envelope or any service does not match.
|
|
159
|
+
*/
|
|
160
|
+
export declare function parseGraphqlServicesDocument(value: unknown, source: string): GraphqlServicesDocument;
|
|
161
|
+
/**
|
|
162
|
+
* Builds one service, validating it.
|
|
163
|
+
*
|
|
164
|
+
* @param fields - The service.
|
|
165
|
+
* @returns The service.
|
|
166
|
+
* @throws {@link InvalidDocumentError} If it is not valid, so a bad service fails where it is built.
|
|
167
|
+
*/
|
|
168
|
+
export declare function createGraphqlService(fields: GraphqlServiceFields): GraphqlService;
|
|
169
|
+
/**
|
|
170
|
+
* Builds a GraphQL services document, adding its `specVersion` and validating the result.
|
|
171
|
+
*
|
|
172
|
+
* @param services - The services the host lists.
|
|
173
|
+
* @returns The document.
|
|
174
|
+
* @throws {@link InvalidDocumentError} If a service is not valid.
|
|
175
|
+
*/
|
|
176
|
+
export declare function createGraphqlServicesDocument(services: GraphqlServiceFields[]): GraphqlServicesDocument;
|
|
177
|
+
/** How to reach a service: absolute URLs, and the headers the caller must supply. */
|
|
178
|
+
export interface GraphqlServiceConnection {
|
|
179
|
+
/** The endpoint for queries and mutations. */
|
|
180
|
+
url: string;
|
|
181
|
+
/** Where subscriptions go, or null when the service offers none. */
|
|
182
|
+
subscriptions: {
|
|
183
|
+
url: string;
|
|
184
|
+
protocol: SubscriptionProtocol;
|
|
185
|
+
} | null;
|
|
186
|
+
/** Where the SDL can be downloaded, or null. */
|
|
187
|
+
schemaUrl: string | null;
|
|
188
|
+
/** Names of headers the service requires, e.g. `Authorization`. Empty when none. */
|
|
189
|
+
requiredHeaders: string[];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* How to connect to a service, with every URL made absolute.
|
|
193
|
+
*
|
|
194
|
+
* @param service - A validated service.
|
|
195
|
+
* @param documentUrl - Where the document was read from; relative URLs resolve against it.
|
|
196
|
+
* @returns The connection.
|
|
197
|
+
* @throws {@link InvalidDocumentError} If a URL does not resolve.
|
|
198
|
+
*/
|
|
199
|
+
export declare function graphqlServiceConnection(service: GraphqlService, documentUrl: string): GraphqlServiceConnection;
|
|
200
|
+
export {};
|