@tangen/graphql 0.0.0-stage → 0.1.25
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/config.d.ts +21 -0
- package/dist/depth-limit.d.ts +17 -0
- package/dist/extensions.d.ts +37 -0
- package/dist/filter.d.ts +13 -0
- package/dist/graphiql.d.ts +13 -0
- package/dist/index.d.ts +59 -0
- package/dist/index.js +1277 -0
- package/dist/loaders.d.ts +30 -0
- package/dist/naming.d.ts +11 -0
- package/dist/permissions.d.ts +21 -0
- package/dist/resolvers.d.ts +87 -0
- package/dist/scalars.d.ts +15 -0
- package/dist/schema-builder.d.ts +51 -0
- package/dist/subscriptions.d.ts +82 -0
- package/package.json +48 -4
- package/README.md +0 -3
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Name: config.ts
|
|
3
|
+
* Purpose: Resolves the GraphQL config for a workspace×env — env override
|
|
4
|
+
* wins over the workspace config; everything defaults OFF.
|
|
5
|
+
* GraphiQL/introspection default sensibly by environment.
|
|
6
|
+
*
|
|
7
|
+
* Author: Raghunath J
|
|
8
|
+
* License: MIT
|
|
9
|
+
*
|
|
10
|
+
* Dependencies/Notes: @tangen/types only.
|
|
11
|
+
*/
|
|
12
|
+
import type { WorkspaceProject } from '@tangen/types';
|
|
13
|
+
export interface ResolvedGraphqlConfig {
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
graphiql: boolean;
|
|
16
|
+
introspection: boolean;
|
|
17
|
+
maxDepth: number;
|
|
18
|
+
mutations: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** project.graphql > disabled. `isDev` (a development deployment) decides the GraphiQL default. */
|
|
21
|
+
export declare function resolveGraphqlConfig(project: WorkspaceProject | undefined, isDev?: boolean): ResolvedGraphqlConfig;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DocumentNode, ValidationRule } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* Builds the validation rule for a resolved `maxDepth`.
|
|
4
|
+
* @param maxDepth - Deepest operation allowed; values below 1 disable the rule.
|
|
5
|
+
* @returns A graphql ValidationRule reporting one error per over-deep operation.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createMaxDepthRule(maxDepth: number): ValidationRule;
|
|
8
|
+
/**
|
|
9
|
+
* The depth of a document as the rule above would charge it: the deepest
|
|
10
|
+
* operation, measured the same way. Exists so the API's Gateway can hold a
|
|
11
|
+
* ceiling ABOVE the rule (M6 of tasks/plan-gateway.md) without a schema in
|
|
12
|
+
* hand - nesting is a property of the document alone.
|
|
13
|
+
* @param source - The query text, or an already parsed document.
|
|
14
|
+
* @returns Depth in levels, or null when the text does not parse (the
|
|
15
|
+
* normal execution path reports the syntax error).
|
|
16
|
+
*/
|
|
17
|
+
export declare function measureQueryDepth(source: string | DocumentNode): number | null;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Name: extensions.ts
|
|
3
|
+
* Purpose: `graphql.types@1` (Extension Kernel K8.4,
|
|
4
|
+
* tasks/plan-extension-kernel.md; plan-framework-extensibility §33).
|
|
5
|
+
* An extension extends the generated schema with SDL - its own
|
|
6
|
+
* types, fields on Query and Mutation, computed fields on content
|
|
7
|
+
* types - and supplies resolvers for exactly what it added. A
|
|
8
|
+
* resolver runs with the extension's ctx the request hands over
|
|
9
|
+
* (`context.extensionCtx(id)`: the API binds it to the caller's
|
|
10
|
+
* execution, so access is the caller's ∩ the extension's grants),
|
|
11
|
+
* never with raw access. A contribution that fails - SDL that does
|
|
12
|
+
* not parse, a type core already defines, a resolver for a field
|
|
13
|
+
* the extension did not add - is dropped with a warning and the
|
|
14
|
+
* schema keeps serving without it.
|
|
15
|
+
*
|
|
16
|
+
* Author: Raghunath J
|
|
17
|
+
* License: MIT
|
|
18
|
+
*/
|
|
19
|
+
import { type GraphQLSchema, type GraphQLFieldResolver } from 'graphql';
|
|
20
|
+
export interface GraphqlContribution {
|
|
21
|
+
extensionId: string;
|
|
22
|
+
/** SDL: new types, `extend type Query { ... }`, `extend type Mutation { ... }`, `extend type <ContentType> { ... }`. */
|
|
23
|
+
sdl: string;
|
|
24
|
+
/** Resolvers for the fields the SDL added, by type then field; each receives `context.ctx`, the extension's ctx. */
|
|
25
|
+
resolvers?: Record<string, Record<string, GraphQLFieldResolver<unknown, GraphqlExtensionContext>>>;
|
|
26
|
+
}
|
|
27
|
+
/** What a contributed resolver sees: the request context plus the extension's own ctx under `ctx`. */
|
|
28
|
+
export interface GraphqlExtensionContext {
|
|
29
|
+
/** Present on a request the API built: the extension's ctx bound to the caller; null when the extension cannot run for this caller. */
|
|
30
|
+
extensionCtx?: (extensionId: string) => Promise<unknown | null>;
|
|
31
|
+
ctx: unknown;
|
|
32
|
+
[key: string]: unknown;
|
|
33
|
+
}
|
|
34
|
+
export interface ApplyGraphqlContributionsOptions {
|
|
35
|
+
warn?: (message: string) => void;
|
|
36
|
+
}
|
|
37
|
+
export declare function applyGraphqlContributions(schema: GraphQLSchema, items: readonly GraphqlContribution[], opts?: ApplyGraphqlContributionsOptions): GraphQLSchema;
|
package/dist/filter.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Name: filter.ts
|
|
3
|
+
* Purpose: Translates a generated GraphQL WhereInput value into the
|
|
4
|
+
* platform's QueryFilter DSL (the same one REST accepts) — field
|
|
5
|
+
* operator maps plus recursive _and/_or groups. Values only; no
|
|
6
|
+
* field is invented that the caller didn't supply.
|
|
7
|
+
*
|
|
8
|
+
* Author: Raghunath J
|
|
9
|
+
* License: MIT
|
|
10
|
+
*/
|
|
11
|
+
import type { QueryFilter } from '@tangen/types';
|
|
12
|
+
/** WhereInput → QueryFilter. Empty/undefined ⇒ {}. */
|
|
13
|
+
export declare function whereToFilter(where: Record<string, unknown> | null | undefined): QueryFilter;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Name: graphiql.ts
|
|
3
|
+
* Purpose: A self-contained GraphiQL-lite explorer for GET /graphql in dev.
|
|
4
|
+
* Deliberately dependency-free and CSP-safe: no external CDN, no
|
|
5
|
+
* remote fonts/scripts — just an inline editor that POSTs to the
|
|
6
|
+
* same endpoint and pretty-prints the result. Enough to explore
|
|
7
|
+
* the generated schema without shipping the full GraphiQL bundle.
|
|
8
|
+
*
|
|
9
|
+
* Author: Raghunath J
|
|
10
|
+
* License: MIT
|
|
11
|
+
*/
|
|
12
|
+
/** Renders the explorer HTML pointed at `endpoint` (same-origin). */
|
|
13
|
+
export declare function graphiqlHTML(endpoint: string): string;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Name: index.ts
|
|
3
|
+
* Purpose: @tangen/graphql — the GraphQL API for Tangen CMS as an
|
|
4
|
+
* independent, optionally-installed package. The GraphQL schema is
|
|
5
|
+
* GENERATED from the content SchemaDefinition (G1+); this entry
|
|
6
|
+
* exposes config resolution, the execute helper, and (for G0) a
|
|
7
|
+
* minimal ping schema so the API mount is real before generation
|
|
8
|
+
* lands.
|
|
9
|
+
*
|
|
10
|
+
* Author: Raghunath J
|
|
11
|
+
* License: MIT
|
|
12
|
+
*
|
|
13
|
+
* Dependencies/Notes: Depends only on @tangen/types + graphql.
|
|
14
|
+
*/
|
|
15
|
+
import { GraphQLSchema, type ExecutionResult } from 'graphql';
|
|
16
|
+
export { resolveGraphqlConfig, type ResolvedGraphqlConfig } from './config';
|
|
17
|
+
export { createMaxDepthRule, measureQueryDepth } from './depth-limit';
|
|
18
|
+
export { buildContentSchema, type BuildSchemaOptions } from './schema-builder';
|
|
19
|
+
export { GraphQLJSON, GraphQLDateTime } from './scalars';
|
|
20
|
+
export { createResolvers, createRequestContext, type ResolverHooks, type GraphqlRequestContext } from './resolvers';
|
|
21
|
+
export { whereToFilter } from './filter';
|
|
22
|
+
export { canReadType, canWriteType, canReadDraftsType, canPublishTypeObjects } from './permissions';
|
|
23
|
+
export { createBatchLoaders, type BatchLoaders } from './loaders';
|
|
24
|
+
export { graphiqlHTML } from './graphiql';
|
|
25
|
+
export { buildSubscriptionType, subscriptionTopic, prepareSubscription, type RealtimeSubscriber, type RealtimeEventLike, type PreparedSubscription, } from './subscriptions';
|
|
26
|
+
export { subscribe as subscribeGraphql, type ExecutionResult as GraphqlExecutionResult } from 'graphql';
|
|
27
|
+
export { printSchema as printSchemaSDL } from 'graphql';
|
|
28
|
+
export * as naming from './naming';
|
|
29
|
+
export interface ExecuteGraphqlArgs {
|
|
30
|
+
schema: GraphQLSchema;
|
|
31
|
+
source: string;
|
|
32
|
+
variableValues?: Record<string, unknown> | null;
|
|
33
|
+
operationName?: string | null;
|
|
34
|
+
contextValue?: unknown;
|
|
35
|
+
rootValue?: unknown;
|
|
36
|
+
/** When false, __schema/__type queries are rejected (production lockdown). */
|
|
37
|
+
introspection?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Deepest selection-set nesting allowed. Omit (or pass < 1) to keep the
|
|
40
|
+
* pre-CF-2 contract of no depth limit at all; the API mount always passes
|
|
41
|
+
* the resolved `graphql.maxDepth`.
|
|
42
|
+
*/
|
|
43
|
+
maxDepth?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Runs one operation. Never throws for query-level problems — parse,
|
|
47
|
+
* validation, and resolver errors all come back in `errors` so the HTTP
|
|
48
|
+
* mount can return a 200 GraphQL envelope (the GraphQL convention). With
|
|
49
|
+
* `introspection: false`, introspection queries are refused at validation.
|
|
50
|
+
* A subscription operation is refused here by name (Realtime R5): it runs
|
|
51
|
+
* over the realtime WebSocket, never over a request.
|
|
52
|
+
*/
|
|
53
|
+
export declare function executeGraphql(args: ExecuteGraphqlArgs): Promise<ExecutionResult>;
|
|
54
|
+
/**
|
|
55
|
+
* A trivial schema (`{ ping }`) — the G0 placeholder that proves the mount
|
|
56
|
+
* end to end before the generated schema (G1) replaces it.
|
|
57
|
+
*/
|
|
58
|
+
export declare function pingSchema(): GraphQLSchema;
|
|
59
|
+
export { applyGraphqlContributions, type GraphqlContribution, type GraphqlExtensionContext } from './extensions';
|