@znight/graphql 0.3.0 → 0.4.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/README.md +40 -2
- package/dist/compiler.d.mts +21 -1
- package/dist/compiler.mjs +116 -15
- package/dist/compiler.mjs.map +1 -1
- package/dist/{driver-Cnze8Oyr.d.mts → driver-DgbpFj4-.d.mts} +10 -3
- package/dist/index.d.mts +16 -3
- package/dist/index.mjs +1 -1
- package/dist/names-BlzDM5cF.mjs.map +1 -1
- package/dist/{plugin-q4oz7d6s.mjs → plugin-BssB7wtn.mjs} +29 -5
- package/dist/plugin-BssB7wtn.mjs.map +1 -0
- package/dist/testing.d.mts +1 -1
- package/dist/testing.mjs +1 -1
- package/dist/yoga.d.mts +1 -1
- package/package.json +8 -8
- package/src/compiler/analyze.ts +27 -0
- package/src/compiler/data.ts +20 -1
- package/src/compiler/generate.ts +137 -19
- package/src/metadata.ts +20 -4
- package/src/pipeline.ts +72 -9
- package/src/plugin.ts +2 -0
- package/src/types.ts +10 -2
- package/dist/plugin-q4oz7d6s.mjs.map +0 -1
|
@@ -178,9 +178,16 @@ interface GraphQLContext {
|
|
|
178
178
|
*/
|
|
179
179
|
loader(token: Token): BatchLoader<unknown, unknown>;
|
|
180
180
|
}
|
|
181
|
+
declare module "@znight/core" {
|
|
182
|
+
/** Custom parameter decorators (`createParamDecorator`) resolve GraphQL parameters from the {@link ResolverContext}. */
|
|
183
|
+
interface ParamContexts {
|
|
184
|
+
graphql: ResolverContext;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
181
187
|
/**
|
|
182
|
-
* What a {@link GraphQLGuard} receives for one resolver call (§5.9)
|
|
183
|
-
* `RouteMetaCarrier` of `@znight/http`, so route
|
|
188
|
+
* What a {@link GraphQLGuard} receives for one resolver call (§5.9), and the context of custom
|
|
189
|
+
* parameter resolvers (RFC 0010). It satisfies the `RouteMetaCarrier` of `@znight/http`, so route
|
|
190
|
+
* decorators read it: `Roles.get(ctx)`.
|
|
184
191
|
*/
|
|
185
192
|
interface ResolverContext<TParent = unknown, TArgs extends GraphQLArgs = GraphQLArgs> extends RouteMetaCarrier {
|
|
186
193
|
/** Effective metadata of the field (method decisions over class decisions) and its schema coordinate. */
|
|
@@ -440,4 +447,4 @@ interface GraphQLDriver {
|
|
|
440
447
|
stop?(): void | Promise<void>;
|
|
441
448
|
}
|
|
442
449
|
export { ScalarDefinition as A, GraphQLResultMapperClass as C, LoaderOptions as D, LoaderKey as E, GraphQLErrorCodeValue as M, GraphQLException as N, LoaderValue as O, GraphQLExceptionOptions as P, GraphQLResultMapper as S, GraphQLTransport as T, GraphQLErrorMapper as _, EngineExecuteOptions as a, GraphQLGuardClass as b, GraphQLRequest as c, orderByKeys as d, BatchLoad as f, GraphQLContext as g, GraphQLArgs as h, GraphQLDriverRoutesContext as i, GraphQLErrorCode as j, ResolverContext as k, GraphQLResultStream as l, BatchLoader as m, GraphQLDriverContext as n, GraphQLEngine as o, BatchLoadClass as p, GraphQLDriverRoute as r, GraphQLEngineSettings as s, GraphQLDriver as t, OrderByKeysOptions as u, GraphQLErrorMapperClass as v, GraphQLResultTypes as w, GraphQLOperationKind as x, GraphQLGuard as y };
|
|
443
|
-
//# sourceMappingURL=driver-
|
|
450
|
+
//# sourceMappingURL=driver-DgbpFj4-.d.mts.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as ScalarDefinition, C as GraphQLResultMapperClass, D as LoaderOptions, E as LoaderKey, M as GraphQLErrorCodeValue, N as GraphQLException, O as LoaderValue, P as GraphQLExceptionOptions, S as GraphQLResultMapper, T as GraphQLTransport, _ as GraphQLErrorMapper, a as EngineExecuteOptions, b as GraphQLGuardClass, c as GraphQLRequest, d as orderByKeys, f as BatchLoad, g as GraphQLContext, h as GraphQLArgs, i as GraphQLDriverRoutesContext, j as GraphQLErrorCode, k as ResolverContext, l as GraphQLResultStream, m as BatchLoader, n as GraphQLDriverContext, o as GraphQLEngine, p as BatchLoadClass, r as GraphQLDriverRoute, s as GraphQLEngineSettings, t as GraphQLDriver, u as OrderByKeysOptions, v as GraphQLErrorMapperClass, w as GraphQLResultTypes, x as GraphQLOperationKind, y as GraphQLGuard } from "./driver-
|
|
1
|
+
import { A as ScalarDefinition, C as GraphQLResultMapperClass, D as LoaderOptions, E as LoaderKey, M as GraphQLErrorCodeValue, N as GraphQLException, O as LoaderValue, P as GraphQLExceptionOptions, S as GraphQLResultMapper, T as GraphQLTransport, _ as GraphQLErrorMapper, a as EngineExecuteOptions, b as GraphQLGuardClass, c as GraphQLRequest, d as orderByKeys, f as BatchLoad, g as GraphQLContext, h as GraphQLArgs, i as GraphQLDriverRoutesContext, j as GraphQLErrorCode, k as ResolverContext, l as GraphQLResultStream, m as BatchLoader, n as GraphQLDriverContext, o as GraphQLEngine, p as BatchLoadClass, r as GraphQLDriverRoute, s as GraphQLEngineSettings, t as GraphQLDriver, u as OrderByKeysOptions, v as GraphQLErrorMapperClass, w as GraphQLResultTypes, x as GraphQLOperationKind, y as GraphQLGuard } from "./driver-DgbpFj4-.mjs";
|
|
2
2
|
import { ClassMarker, MethodMarker, ParameterMarker, Plugin, PluginContext, PluginOptions, PluginRootsContext, ProviderKey, Scope, Token, TypedToken, ZnightError } from "@znight/core";
|
|
3
3
|
import { ByteSize, GuardRef, HttpRouteGroupDefinition, InferSchemaOutput, PluginHttpRoutes, PluginHttpRoutesContext, PluginRoute, RouteMetaEntry, StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1 } from "@znight/http";
|
|
4
4
|
import { FormattedExecutionResult, GraphQLResolveInfo, GraphQLScalarType, GraphQLSchema } from "graphql";
|
|
@@ -450,11 +450,24 @@ interface GraphQLResolverBinding {
|
|
|
450
450
|
readonly meta: Readonly<Record<string, unknown>>;
|
|
451
451
|
/** Informational: loader provider tokens the method injects. */
|
|
452
452
|
readonly loaders?: readonly Token[];
|
|
453
|
+
/**
|
|
454
|
+
* The method has custom parameters (`createParamDecorator`, RFC 0010): the pipeline passes the
|
|
455
|
+
* field's `ResolverContext` to `invoke` (`f`). Absent otherwise.
|
|
456
|
+
*/
|
|
457
|
+
readonly context?: true;
|
|
458
|
+
/**
|
|
459
|
+
* Provider classes resolving custom parameters (`ParamResolver`), in order of first use: the
|
|
460
|
+
* pipeline resolves them in the operation scope and passes the instances to `invoke` (`x`).
|
|
461
|
+
* Absent when there is none.
|
|
462
|
+
*/
|
|
463
|
+
readonly paramResolvers?: readonly Token[];
|
|
453
464
|
/**
|
|
454
465
|
* Calls the method: maps the graphql-js arguments to the method parameters (§7.3). Synchronous
|
|
455
|
-
* unless an argument is validated with a Standard Schema
|
|
466
|
+
* unless an argument is validated with a Standard Schema or a custom parameter resolver returns a
|
|
467
|
+
* promise. `field` and `resolvers` are passed only to methods with custom parameters (declared as
|
|
468
|
+
* a method so that a generated invoke requiring them is accepted).
|
|
456
469
|
*/
|
|
457
|
-
|
|
470
|
+
invoke(resolver: any, parent: unknown, args: GraphQLArgs, context: GraphQLContext, info: GraphQLResolveInfo, field?: ResolverContext, resolvers?: any): unknown;
|
|
458
471
|
}
|
|
459
472
|
declare module "@znight/core" {
|
|
460
473
|
interface ZnightExtensionsMetadata {
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { f as GraphQLErrorCode, l as GraphQLTokens, p as GraphQLException } from "./http-BWcayUtH.mjs";
|
|
2
|
-
import { a as PubSub, i as MemoryPubSub, o as orderByKeys, t as GraphQLPlugin } from "./plugin-
|
|
2
|
+
import { a as PubSub, i as MemoryPubSub, o as orderByKeys, t as GraphQLPlugin } from "./plugin-BssB7wtn.mjs";
|
|
3
3
|
import { l as GRAPHQL_METADATA_VERSION } from "./names-BlzDM5cF.mjs";
|
|
4
4
|
import { isThenable, toIssueDetail } from "@znight/http";
|
|
5
5
|
// src/decorators.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"names-BlzDM5cF.mjs","names":[],"sources":["../src/metadata.ts","../src/type-ref.ts","../src/names.ts"],"sourcesContent":["/**\n * GraphQL section of the generated metadata (`__ZNIGHT_METADATA__.extensions.graphql`, RFC 0005\n * §7), produced by the `@znight/graphql/compiler` extension and consumed by `GraphQLPlugin`, which\n * validates it at boot (ZNIGHT066), because metadata can be hand-written.\n *\n * Data, not code, except `invoke` (one arrow per resolver) and the scalar implementations imported\n * from user code. The SDL printer (`sdl.ts`) reads the same shape without its functions.\n *\n * Import-free: types, type-only imports and one constant, shared by the compiler extension and the\n * runtime.\n */\nimport type { Token } from '@znight/core'\nimport type { HttpRouteGroupDefinition } from '@znight/http'\nimport type { GraphQLResolveInfo, GraphQLScalarType } from 'graphql'\nimport type { GraphQLArgs, GraphQLContext, ScalarDefinition } from './types.ts'\n\n/** Format version of `metadata.extensions.graphql` (another version is ZNIGHT066 at boot). */\nexport const GRAPHQL_METADATA_VERSION = 1\n\n/** The schema of the application. The section is omitted when the application has no resolver. */\nexport interface GraphQLMetadata {\n /** {@link GRAPHQL_METADATA_VERSION}. */\n readonly version: number\n /** First 16 hexadecimal characters of the SHA-256 of the SDL (`printSdl`): logs, caches. */\n readonly schemaHash: string\n readonly roots: GraphQLRootTypes\n /** Every named type except the graphql-js specified scalars, sorted by name (code-unit order). */\n readonly types: readonly GraphQLTypeDefinition[]\n /**\n * Route decorator groups used on resolvers that must be known at runtime (required, or holding\n * several keys), by group name: the shape of `extensions.http.groups` (RFC 0001).\n */\n readonly groups?: Readonly<Record<string, HttpRouteGroupDefinition>>\n}\n\n/** Names of the root operation types (`Query`, `Mutation`, `Subscription`). */\nexport interface GraphQLRootTypes {\n readonly query: string\n readonly mutation?: string\n readonly subscription?: string\n}\n\n/** A named type of the schema. */\nexport type GraphQLTypeDefinition =\n | GraphQLObjectTypeDefinition\n | GraphQLInterfaceTypeDefinition\n | GraphQLInputTypeDefinition\n | GraphQLEnumTypeDefinition\n | GraphQLUnionTypeDefinition\n | GraphQLBuiltinScalarDefinition\n | GraphQLCustomScalarDefinition\n\n/** An object type: resolver return types, their fields, the root types. */\nexport interface GraphQLObjectTypeDefinition {\n readonly kind: 'object'\n readonly name: string\n readonly description?: string\n /** Interfaces the type implements (schema-first, RFC 0007), in declaration order. Absent: none. */\n readonly interfaces?: readonly string[]\n /** Declaration order (base members first), then field resolvers by resolver token and source order. */\n readonly fields: readonly GraphQLFieldDefinition[]\n}\n\n/**\n * An interface type (schema-first, RFC 0007; code-first emits none). Its fields have no\n * `resolver`: graphql-js resolves the fields of the concrete object type.\n */\nexport interface GraphQLInterfaceTypeDefinition {\n readonly kind: 'interface'\n readonly name: string\n readonly description?: string\n /** Interfaces the interface implements, in declaration order. Absent: none. */\n readonly interfaces?: readonly string[]\n readonly fields: readonly GraphQLFieldDefinition[]\n /** How the runtime tells the implementing object types apart (`resolveType`). */\n readonly discriminator: GraphQLDiscriminator\n}\n\n/** An input object type. */\nexport interface GraphQLInputTypeDefinition {\n readonly kind: 'input'\n readonly name: string\n readonly description?: string\n readonly fields: readonly GraphQLInputFieldDefinition[]\n}\n\n/** An enum: a TypeScript `enum`, or a named alias of a union of string literals. */\nexport interface GraphQLEnumTypeDefinition {\n readonly kind: 'enum'\n readonly name: string\n readonly description?: string\n /** Declaration order. */\n readonly values: readonly GraphQLEnumValueDefinition[]\n}\n\n/** A union of object types. */\nexport interface GraphQLUnionTypeDefinition {\n readonly kind: 'union'\n readonly name: string\n readonly description?: string\n /** Member type names, sorted. */\n readonly members: readonly string[]\n readonly discriminator: GraphQLDiscriminator\n}\n\n/** A scalar implemented by `@znight/graphql`: `DateTime`, `BigInt` or `JSON` (`names.ts`). */\nexport interface GraphQLBuiltinScalarDefinition {\n readonly kind: 'scalar'\n readonly name: string\n readonly description?: string\n readonly builtin: true\n}\n\n/** A scalar declared with `scalar<T>(name, definition)`: the definition is imported from user code. */\nexport interface GraphQLCustomScalarDefinition {\n readonly kind: 'scalar'\n readonly name: string\n /** Wins over the description of the definition (schema-first: the SDL's). */\n readonly description?: string\n /** Wins over the `specifiedByURL` of the definition (schema-first: the SDL's `@specifiedBy`). */\n readonly specifiedByURL?: string\n /**\n * Schema-first (RFC 0007): `description` and `specifiedByURL` are the SDL's and replace the\n * definition's, also when absent, so that the served schema is the SDL.\n */\n readonly sdl?: true\n /** `ScalarDefinition<T>` of any `T` (its methods are bivariant), or a graphql-js scalar named `name`. */\n readonly scalar: ScalarDefinition<unknown> | GraphQLScalarType\n}\n\n/** A field of an object type. */\nexport interface GraphQLFieldDefinition {\n readonly name: string\n /** Type reference (`'Book!'`, `'[Book!]!'`, `'Int'`), parsed by `type-ref.ts`. */\n readonly type: string\n readonly description?: string\n readonly deprecationReason?: string\n readonly args?: readonly GraphQLArgumentDefinition[]\n /** Absent: the graphql-js default resolver (`parent[name]`). */\n readonly resolver?: GraphQLResolverBinding\n}\n\n/** An argument of a field. */\nexport interface GraphQLArgumentDefinition {\n readonly name: string\n readonly type: string\n readonly description?: string\n readonly deprecationReason?: string\n /**\n * Default value, as an external value: JSON-compatible, enum values by GraphQL name (passed to\n * graphql-js as `default: { value }`). Absent: no default.\n */\n readonly defaultValue?: unknown\n /** The TypeScript type does not accept `null`: a `null` sent by the client becomes `undefined` (§5.4). */\n readonly nullAsUndefined?: true\n}\n\n/** A field of an input object type. */\nexport interface GraphQLInputFieldDefinition extends GraphQLArgumentDefinition {}\n\n/** A value of an enum. */\nexport interface GraphQLEnumValueDefinition {\n /** GraphQL name (the member name, or the literal). */\n readonly name: string\n /** Internal value (the member value, or the literal), what resolvers receive and return. */\n readonly value: string | number\n readonly description?: string\n readonly deprecationReason?: string\n}\n\n/** How the runtime tells the members of a union or the implementations of an interface apart (`resolveType`). */\nexport type GraphQLDiscriminator =\n | {\n readonly by: 'property'\n readonly property: string\n /** Literal value of the property (as a string) → member type name. */\n readonly values: Readonly<Record<string, string>>\n }\n | {\n readonly by: 'class'\n /** Member classes and their type names, subclasses first (`instanceof` order). */\n readonly classes: readonly (readonly [cls: abstract new (...args: never[]) => unknown, name: string])[]\n }\n | { readonly by: 'typename' }\n\n/** Kind of field a resolver method provides. */\nexport type GraphQLResolverOperation = 'query' | 'mutation' | 'subscription' | 'field'\n\n/** The resolver method behind a field. */\nexport interface GraphQLResolverBinding {\n /** Provider token of the resolver class. */\n readonly token: Token\n readonly method: string\n readonly operation: GraphQLResolverOperation\n /** Guard provider tokens: class `@UseGuard` guards, then method ones. */\n readonly guards: readonly Token[]\n /**\n * Effective field metadata (`createRouteDecorator` values, method decisions over class ones, one\n * decision per group). Empty: no metadata, so global guards skip a field resolver (§5.9).\n */\n readonly meta: Readonly<Record<string, unknown>>\n /** Informational: loader provider tokens the method injects. */\n readonly loaders?: readonly Token[]\n /**\n * Calls the method: maps the graphql-js arguments to the method parameters (§7.3). Synchronous\n * unless an argument is validated with a Standard Schema.\n */\n readonly invoke: (\n // biome-ignore lint/suspicious/noExplicitAny: generated invokers receive the concrete resolver class\n resolver: any,\n parent: unknown,\n args: GraphQLArgs,\n context: GraphQLContext,\n info: GraphQLResolveInfo,\n ) => unknown\n}\n\ndeclare module '@znight/core' {\n interface ZnightExtensionsMetadata {\n readonly graphql?: GraphQLMetadata\n }\n}\n","/**\n * GraphQL type references as written in `metadata.extensions.graphql` (`'Book!'`, `'[Book!]!'`,\n * `'[[Int]]'`): parsing and printing.\n *\n * Import-free: shared by the compiler extension (which prints them) and the runtime (which parses\n * them once, at boot, to build the schema). The grammar is the canonical form graphql-js prints\n * (`String(type)`): no whitespace, no comments, names matching `/^[_A-Za-z][_0-9A-Za-z]*$/`.\n */\n\n/** A parsed type reference. */\nexport type GraphQLTypeRef = NamedTypeRef | ListTypeRef\n\n/** A named type (`Book`, `Book!`). */\nexport interface NamedTypeRef {\n readonly kind: 'named'\n readonly name: string\n readonly nonNull: boolean\n}\n\n/** A list type (`[Book]`, `[Book!]!`). */\nexport interface ListTypeRef {\n readonly kind: 'list'\n /** The item type. */\n readonly of: GraphQLTypeRef\n readonly nonNull: boolean\n}\n\n/** Result of one parsing step: the reference and the index after it. */\ninterface Step {\n readonly ref: GraphQLTypeRef\n readonly end: number\n}\n\n/**\n * Parses a type reference. Returns `undefined` when `text` is not a canonical reference, so that\n * callers validating hand-written metadata can collect every problem before failing.\n */\nexport function parseTypeRef(text: string): GraphQLTypeRef | undefined {\n const step = parseAt(text, 0)\n return step !== undefined && step.end === text.length ? step.ref : undefined\n}\n\n/** Prints a type reference in its canonical form (the form graphql-js prints). */\nexport function printTypeRef(ref: GraphQLTypeRef): string {\n const inner = ref.kind === 'named' ? ref.name : `[${printTypeRef(ref.of)}]`\n return ref.nonNull ? `${inner}!` : inner\n}\n\n/** The innermost type name of a reference (`'[Book!]!'` → `'Book'`), `undefined` when malformed. */\nexport function namedTypeOf(ref: string | GraphQLTypeRef): string | undefined {\n let current = typeof ref === 'string' ? parseTypeRef(ref) : ref\n while (current !== undefined && current.kind === 'list') current = current.of\n return current?.name\n}\n\nconst OPEN_BRACKET = 0x5b // [\nconst CLOSE_BRACKET = 0x5d // ]\nconst BANG = 0x21 // !\n\nfunction parseAt(text: string, start: number): Step | undefined {\n let ref: GraphQLTypeRef\n let index: number\n if (text.charCodeAt(start) === OPEN_BRACKET) {\n const item = parseAt(text, start + 1)\n if (item === undefined || text.charCodeAt(item.end) !== CLOSE_BRACKET) return undefined\n index = item.end + 1\n ref = { kind: 'list', of: item.ref, nonNull: false }\n } else {\n index = start\n if (!isNameStart(text.charCodeAt(index))) return undefined\n index++\n while (isNameContinue(text.charCodeAt(index))) index++\n ref = { kind: 'named', name: text.slice(start, index), nonNull: false }\n }\n if (text.charCodeAt(index) === BANG) {\n return { ref: { ...ref, nonNull: true }, end: index + 1 }\n }\n return { ref, end: index }\n}\n\n/** `[_A-Za-z]`. `NaN` (past the end) is never a name character. */\nfunction isNameStart(code: number): boolean {\n return code === 0x5f || (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a)\n}\n\n/** `[_0-9A-Za-z]`. */\nfunction isNameContinue(code: number): boolean {\n return isNameStart(code) || (code >= 0x30 && code <= 0x39)\n}\n","/**\n * GraphQL naming rules and built-in types (RFC 0005 §5.7, §6.4).\n *\n * Import-free: shared by the compiler extension (naming diagnostics, ZNIGHT061) and the runtime\n * (structural validation of `metadata.extensions.graphql` and the built-in scalars, ZNIGHT066).\n */\n\n/** Grammar of a GraphQL name (types, fields, arguments, enum values). */\nexport const GRAPHQL_NAME: RegExp = /^[_A-Za-z][_0-9A-Za-z]*$/\n\n/** `true` when `name` is a GraphQL name that user types may take (not reserved with `__`). */\nexport function isGraphQLName(name: string): boolean {\n return GRAPHQL_NAME.test(name) && !name.startsWith('__')\n}\n\n/** Names an enum value may not take (GraphQL spec §3.9). */\nexport const RESERVED_ENUM_VALUES: ReadonlySet<string> = new Set(['true', 'false', 'null'])\n\n/** Names of the root operation types; user types may not take them (ZNIGHT061). */\nexport const ROOT_TYPE_NAMES: {\n readonly query: 'Query'\n readonly mutation: 'Mutation'\n readonly subscription: 'Subscription'\n} = Object.freeze({ query: 'Query', mutation: 'Mutation', subscription: 'Subscription' })\n\n/** Scalars of the GraphQL specification: always present, never declared in the metadata nor printed. */\nexport const SPECIFIED_SCALARS: ReadonlySet<string> = new Set(['String', 'Int', 'Float', 'Boolean', 'ID'])\n\n/** A scalar `@znight/graphql` implements itself (`kind: 'scalar', builtin: true` in the metadata). */\nexport interface BuiltinScalarInfo {\n /** `@specifiedBy(url:)`. Absent: none. */\n readonly specifiedByURL?: string\n}\n\n/**\n * The scalars `@znight/graphql` implements (§5.7): `DateTime` (`Date`), `BigInt` (`bigint`) and\n * `JSON` (`JSONValue`). They have no description. The runtime builds them with exactly these\n * properties and without `valueToLiteral`, so that graphql-js `printSchema` and `printSdl()` agree.\n */\nexport const BUILTIN_SCALARS: ReadonlyMap<string, BuiltinScalarInfo> = new Map<string, BuiltinScalarInfo>([\n ['BigInt', {}],\n ['DateTime', { specifiedByURL: 'https://datatracker.ietf.org/doc/html/rfc3339' }],\n ['JSON', {}],\n])\n\n/** The default `@deprecated` reason of graphql-js: printed as a bare `@deprecated`. */\nexport const DEFAULT_DEPRECATION_REASON = 'No longer supported'\n"],"mappings":";;AAiBA,MAAa,2BAA2B;;;;;;ACoBxC,SAAgB,aAAa,MAA0C;CACrE,MAAM,OAAO,QAAQ,MAAM,CAAC;CAC5B,OAAO,SAAS,KAAA,KAAa,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,KAAA;AACrE;;AAGA,SAAgB,aAAa,KAA6B;CACxD,MAAM,QAAQ,IAAI,SAAS,UAAU,IAAI,OAAO,IAAI,aAAa,IAAI,EAAE,EAAE;CACzE,OAAO,IAAI,UAAU,GAAG,MAAM,KAAK;AACrC;AASA,MAAM,eAAe;AACrB,MAAM,gBAAgB;AACtB,MAAM,OAAO;AAEb,SAAS,QAAQ,MAAc,OAAiC;CAC9D,IAAI;CACJ,IAAI;CACJ,IAAI,KAAK,WAAW,KAAK,MAAM,cAAc;EAC3C,MAAM,OAAO,QAAQ,MAAM,QAAQ,CAAC;EACpC,IAAI,SAAS,KAAA,KAAa,KAAK,WAAW,KAAK,GAAG,MAAM,eAAe,OAAO,KAAA;EAC9E,QAAQ,KAAK,MAAM;EACnB,MAAM;GAAE,MAAM;GAAQ,IAAI,KAAK;GAAK,SAAS;EAAM;CACrD,OAAO;EACL,QAAQ;EACR,IAAI,CAAC,YAAY,KAAK,WAAW,KAAK,CAAC,GAAG,OAAO,KAAA;EACjD;EACA,OAAO,eAAe,KAAK,WAAW,KAAK,CAAC,GAAG;EAC/C,MAAM;GAAE,MAAM;GAAS,MAAM,KAAK,MAAM,OAAO,KAAK;GAAG,SAAS;EAAM;CACxE;CACA,IAAI,KAAK,WAAW,KAAK,MAAM,MAC7B,OAAO;EAAE,KAAK;GAAE,GAAG;GAAK,SAAS;EAAK;EAAG,KAAK,QAAQ;CAAE;CAE1D,OAAO;EAAE;EAAK,KAAK;CAAM;AAC3B;;AAGA,SAAS,YAAY,MAAuB;CAC1C,OAAO,SAAS,MAAS,QAAQ,MAAQ,QAAQ,MAAU,QAAQ,MAAQ,QAAQ;AACrF;;AAGA,SAAS,eAAe,MAAuB;CAC7C,OAAO,YAAY,IAAI,KAAM,QAAQ,MAAQ,QAAQ;AACvD;;;;;;;;;AChFA,MAAa,eAAuB;;AAGpC,SAAgB,cAAc,MAAuB;CACnD,OAAO,aAAa,KAAK,IAAI,KAAK,CAAC,KAAK,WAAW,IAAI;AACzD;;AAGA,MAAa,uCAA4C,IAAI,IAAI;CAAC;CAAQ;CAAS;AAAM,CAAC;;AAG1F,MAAa,kBAIT,OAAO,OAAO;CAAE,OAAO;CAAS,UAAU;CAAY,cAAc;AAAe,CAAC;;AAGxF,MAAa,oCAAyC,IAAI,IAAI;CAAC;CAAU;CAAO;CAAS;CAAW;AAAI,CAAC;;;;;;AAazG,MAAa,kCAA0D,IAAI,IAA+B;CACxG,CAAC,UAAU,CAAC,CAAC;CACb,CAAC,YAAY,EAAE,gBAAgB,gDAAgD,CAAC;CAChF,CAAC,QAAQ,CAAC,CAAC;AACb,CAAC;;AAGD,MAAa,6BAA6B"}
|
|
1
|
+
{"version":3,"file":"names-BlzDM5cF.mjs","names":[],"sources":["../src/metadata.ts","../src/type-ref.ts","../src/names.ts"],"sourcesContent":["/**\n * GraphQL section of the generated metadata (`__ZNIGHT_METADATA__.extensions.graphql`, RFC 0005\n * §7), produced by the `@znight/graphql/compiler` extension and consumed by `GraphQLPlugin`, which\n * validates it at boot (ZNIGHT066), because metadata can be hand-written.\n *\n * Data, not code, except `invoke` (one arrow per resolver) and the scalar implementations imported\n * from user code. The SDL printer (`sdl.ts`) reads the same shape without its functions.\n *\n * Import-free: types, type-only imports and one constant, shared by the compiler extension and the\n * runtime.\n */\nimport type { Token } from '@znight/core'\nimport type { HttpRouteGroupDefinition } from '@znight/http'\nimport type { GraphQLResolveInfo, GraphQLScalarType } from 'graphql'\nimport type { GraphQLArgs, GraphQLContext, ResolverContext, ScalarDefinition } from './types.ts'\n\n/** Format version of `metadata.extensions.graphql` (another version is ZNIGHT066 at boot). */\nexport const GRAPHQL_METADATA_VERSION = 1\n\n/** The schema of the application. The section is omitted when the application has no resolver. */\nexport interface GraphQLMetadata {\n /** {@link GRAPHQL_METADATA_VERSION}. */\n readonly version: number\n /** First 16 hexadecimal characters of the SHA-256 of the SDL (`printSdl`): logs, caches. */\n readonly schemaHash: string\n readonly roots: GraphQLRootTypes\n /** Every named type except the graphql-js specified scalars, sorted by name (code-unit order). */\n readonly types: readonly GraphQLTypeDefinition[]\n /**\n * Route decorator groups used on resolvers that must be known at runtime (required, or holding\n * several keys), by group name: the shape of `extensions.http.groups` (RFC 0001).\n */\n readonly groups?: Readonly<Record<string, HttpRouteGroupDefinition>>\n}\n\n/** Names of the root operation types (`Query`, `Mutation`, `Subscription`). */\nexport interface GraphQLRootTypes {\n readonly query: string\n readonly mutation?: string\n readonly subscription?: string\n}\n\n/** A named type of the schema. */\nexport type GraphQLTypeDefinition =\n | GraphQLObjectTypeDefinition\n | GraphQLInterfaceTypeDefinition\n | GraphQLInputTypeDefinition\n | GraphQLEnumTypeDefinition\n | GraphQLUnionTypeDefinition\n | GraphQLBuiltinScalarDefinition\n | GraphQLCustomScalarDefinition\n\n/** An object type: resolver return types, their fields, the root types. */\nexport interface GraphQLObjectTypeDefinition {\n readonly kind: 'object'\n readonly name: string\n readonly description?: string\n /** Interfaces the type implements (schema-first, RFC 0007), in declaration order. Absent: none. */\n readonly interfaces?: readonly string[]\n /** Declaration order (base members first), then field resolvers by resolver token and source order. */\n readonly fields: readonly GraphQLFieldDefinition[]\n}\n\n/**\n * An interface type (schema-first, RFC 0007; code-first emits none). Its fields have no\n * `resolver`: graphql-js resolves the fields of the concrete object type.\n */\nexport interface GraphQLInterfaceTypeDefinition {\n readonly kind: 'interface'\n readonly name: string\n readonly description?: string\n /** Interfaces the interface implements, in declaration order. Absent: none. */\n readonly interfaces?: readonly string[]\n readonly fields: readonly GraphQLFieldDefinition[]\n /** How the runtime tells the implementing object types apart (`resolveType`). */\n readonly discriminator: GraphQLDiscriminator\n}\n\n/** An input object type. */\nexport interface GraphQLInputTypeDefinition {\n readonly kind: 'input'\n readonly name: string\n readonly description?: string\n readonly fields: readonly GraphQLInputFieldDefinition[]\n}\n\n/** An enum: a TypeScript `enum`, or a named alias of a union of string literals. */\nexport interface GraphQLEnumTypeDefinition {\n readonly kind: 'enum'\n readonly name: string\n readonly description?: string\n /** Declaration order. */\n readonly values: readonly GraphQLEnumValueDefinition[]\n}\n\n/** A union of object types. */\nexport interface GraphQLUnionTypeDefinition {\n readonly kind: 'union'\n readonly name: string\n readonly description?: string\n /** Member type names, sorted. */\n readonly members: readonly string[]\n readonly discriminator: GraphQLDiscriminator\n}\n\n/** A scalar implemented by `@znight/graphql`: `DateTime`, `BigInt` or `JSON` (`names.ts`). */\nexport interface GraphQLBuiltinScalarDefinition {\n readonly kind: 'scalar'\n readonly name: string\n readonly description?: string\n readonly builtin: true\n}\n\n/** A scalar declared with `scalar<T>(name, definition)`: the definition is imported from user code. */\nexport interface GraphQLCustomScalarDefinition {\n readonly kind: 'scalar'\n readonly name: string\n /** Wins over the description of the definition (schema-first: the SDL's). */\n readonly description?: string\n /** Wins over the `specifiedByURL` of the definition (schema-first: the SDL's `@specifiedBy`). */\n readonly specifiedByURL?: string\n /**\n * Schema-first (RFC 0007): `description` and `specifiedByURL` are the SDL's and replace the\n * definition's, also when absent, so that the served schema is the SDL.\n */\n readonly sdl?: true\n /** `ScalarDefinition<T>` of any `T` (its methods are bivariant), or a graphql-js scalar named `name`. */\n readonly scalar: ScalarDefinition<unknown> | GraphQLScalarType\n}\n\n/** A field of an object type. */\nexport interface GraphQLFieldDefinition {\n readonly name: string\n /** Type reference (`'Book!'`, `'[Book!]!'`, `'Int'`), parsed by `type-ref.ts`. */\n readonly type: string\n readonly description?: string\n readonly deprecationReason?: string\n readonly args?: readonly GraphQLArgumentDefinition[]\n /** Absent: the graphql-js default resolver (`parent[name]`). */\n readonly resolver?: GraphQLResolverBinding\n}\n\n/** An argument of a field. */\nexport interface GraphQLArgumentDefinition {\n readonly name: string\n readonly type: string\n readonly description?: string\n readonly deprecationReason?: string\n /**\n * Default value, as an external value: JSON-compatible, enum values by GraphQL name (passed to\n * graphql-js as `default: { value }`). Absent: no default.\n */\n readonly defaultValue?: unknown\n /** The TypeScript type does not accept `null`: a `null` sent by the client becomes `undefined` (§5.4). */\n readonly nullAsUndefined?: true\n}\n\n/** A field of an input object type. */\nexport interface GraphQLInputFieldDefinition extends GraphQLArgumentDefinition {}\n\n/** A value of an enum. */\nexport interface GraphQLEnumValueDefinition {\n /** GraphQL name (the member name, or the literal). */\n readonly name: string\n /** Internal value (the member value, or the literal), what resolvers receive and return. */\n readonly value: string | number\n readonly description?: string\n readonly deprecationReason?: string\n}\n\n/** How the runtime tells the members of a union or the implementations of an interface apart (`resolveType`). */\nexport type GraphQLDiscriminator =\n | {\n readonly by: 'property'\n readonly property: string\n /** Literal value of the property (as a string) → member type name. */\n readonly values: Readonly<Record<string, string>>\n }\n | {\n readonly by: 'class'\n /** Member classes and their type names, subclasses first (`instanceof` order). */\n readonly classes: readonly (readonly [cls: abstract new (...args: never[]) => unknown, name: string])[]\n }\n | { readonly by: 'typename' }\n\n/** Kind of field a resolver method provides. */\nexport type GraphQLResolverOperation = 'query' | 'mutation' | 'subscription' | 'field'\n\n/** The resolver method behind a field. */\nexport interface GraphQLResolverBinding {\n /** Provider token of the resolver class. */\n readonly token: Token\n readonly method: string\n readonly operation: GraphQLResolverOperation\n /** Guard provider tokens: class `@UseGuard` guards, then method ones. */\n readonly guards: readonly Token[]\n /**\n * Effective field metadata (`createRouteDecorator` values, method decisions over class ones, one\n * decision per group). Empty: no metadata, so global guards skip a field resolver (§5.9).\n */\n readonly meta: Readonly<Record<string, unknown>>\n /** Informational: loader provider tokens the method injects. */\n readonly loaders?: readonly Token[]\n /**\n * The method has custom parameters (`createParamDecorator`, RFC 0010): the pipeline passes the\n * field's `ResolverContext` to `invoke` (`f`). Absent otherwise.\n */\n readonly context?: true\n /**\n * Provider classes resolving custom parameters (`ParamResolver`), in order of first use: the\n * pipeline resolves them in the operation scope and passes the instances to `invoke` (`x`).\n * Absent when there is none.\n */\n readonly paramResolvers?: readonly Token[]\n /**\n * Calls the method: maps the graphql-js arguments to the method parameters (§7.3). Synchronous\n * unless an argument is validated with a Standard Schema or a custom parameter resolver returns a\n * promise. `field` and `resolvers` are passed only to methods with custom parameters (declared as\n * a method so that a generated invoke requiring them is accepted).\n */\n invoke(\n // biome-ignore lint/suspicious/noExplicitAny: generated invokers receive the concrete resolver class\n resolver: any,\n parent: unknown,\n args: GraphQLArgs,\n context: GraphQLContext,\n info: GraphQLResolveInfo,\n field?: ResolverContext,\n // biome-ignore lint/suspicious/noExplicitAny: generated invokers receive the tuple of resolver classes\n resolvers?: any,\n ): unknown\n}\n\ndeclare module '@znight/core' {\n interface ZnightExtensionsMetadata {\n readonly graphql?: GraphQLMetadata\n }\n}\n","/**\n * GraphQL type references as written in `metadata.extensions.graphql` (`'Book!'`, `'[Book!]!'`,\n * `'[[Int]]'`): parsing and printing.\n *\n * Import-free: shared by the compiler extension (which prints them) and the runtime (which parses\n * them once, at boot, to build the schema). The grammar is the canonical form graphql-js prints\n * (`String(type)`): no whitespace, no comments, names matching `/^[_A-Za-z][_0-9A-Za-z]*$/`.\n */\n\n/** A parsed type reference. */\nexport type GraphQLTypeRef = NamedTypeRef | ListTypeRef\n\n/** A named type (`Book`, `Book!`). */\nexport interface NamedTypeRef {\n readonly kind: 'named'\n readonly name: string\n readonly nonNull: boolean\n}\n\n/** A list type (`[Book]`, `[Book!]!`). */\nexport interface ListTypeRef {\n readonly kind: 'list'\n /** The item type. */\n readonly of: GraphQLTypeRef\n readonly nonNull: boolean\n}\n\n/** Result of one parsing step: the reference and the index after it. */\ninterface Step {\n readonly ref: GraphQLTypeRef\n readonly end: number\n}\n\n/**\n * Parses a type reference. Returns `undefined` when `text` is not a canonical reference, so that\n * callers validating hand-written metadata can collect every problem before failing.\n */\nexport function parseTypeRef(text: string): GraphQLTypeRef | undefined {\n const step = parseAt(text, 0)\n return step !== undefined && step.end === text.length ? step.ref : undefined\n}\n\n/** Prints a type reference in its canonical form (the form graphql-js prints). */\nexport function printTypeRef(ref: GraphQLTypeRef): string {\n const inner = ref.kind === 'named' ? ref.name : `[${printTypeRef(ref.of)}]`\n return ref.nonNull ? `${inner}!` : inner\n}\n\n/** The innermost type name of a reference (`'[Book!]!'` → `'Book'`), `undefined` when malformed. */\nexport function namedTypeOf(ref: string | GraphQLTypeRef): string | undefined {\n let current = typeof ref === 'string' ? parseTypeRef(ref) : ref\n while (current !== undefined && current.kind === 'list') current = current.of\n return current?.name\n}\n\nconst OPEN_BRACKET = 0x5b // [\nconst CLOSE_BRACKET = 0x5d // ]\nconst BANG = 0x21 // !\n\nfunction parseAt(text: string, start: number): Step | undefined {\n let ref: GraphQLTypeRef\n let index: number\n if (text.charCodeAt(start) === OPEN_BRACKET) {\n const item = parseAt(text, start + 1)\n if (item === undefined || text.charCodeAt(item.end) !== CLOSE_BRACKET) return undefined\n index = item.end + 1\n ref = { kind: 'list', of: item.ref, nonNull: false }\n } else {\n index = start\n if (!isNameStart(text.charCodeAt(index))) return undefined\n index++\n while (isNameContinue(text.charCodeAt(index))) index++\n ref = { kind: 'named', name: text.slice(start, index), nonNull: false }\n }\n if (text.charCodeAt(index) === BANG) {\n return { ref: { ...ref, nonNull: true }, end: index + 1 }\n }\n return { ref, end: index }\n}\n\n/** `[_A-Za-z]`. `NaN` (past the end) is never a name character. */\nfunction isNameStart(code: number): boolean {\n return code === 0x5f || (code >= 0x41 && code <= 0x5a) || (code >= 0x61 && code <= 0x7a)\n}\n\n/** `[_0-9A-Za-z]`. */\nfunction isNameContinue(code: number): boolean {\n return isNameStart(code) || (code >= 0x30 && code <= 0x39)\n}\n","/**\n * GraphQL naming rules and built-in types (RFC 0005 §5.7, §6.4).\n *\n * Import-free: shared by the compiler extension (naming diagnostics, ZNIGHT061) and the runtime\n * (structural validation of `metadata.extensions.graphql` and the built-in scalars, ZNIGHT066).\n */\n\n/** Grammar of a GraphQL name (types, fields, arguments, enum values). */\nexport const GRAPHQL_NAME: RegExp = /^[_A-Za-z][_0-9A-Za-z]*$/\n\n/** `true` when `name` is a GraphQL name that user types may take (not reserved with `__`). */\nexport function isGraphQLName(name: string): boolean {\n return GRAPHQL_NAME.test(name) && !name.startsWith('__')\n}\n\n/** Names an enum value may not take (GraphQL spec §3.9). */\nexport const RESERVED_ENUM_VALUES: ReadonlySet<string> = new Set(['true', 'false', 'null'])\n\n/** Names of the root operation types; user types may not take them (ZNIGHT061). */\nexport const ROOT_TYPE_NAMES: {\n readonly query: 'Query'\n readonly mutation: 'Mutation'\n readonly subscription: 'Subscription'\n} = Object.freeze({ query: 'Query', mutation: 'Mutation', subscription: 'Subscription' })\n\n/** Scalars of the GraphQL specification: always present, never declared in the metadata nor printed. */\nexport const SPECIFIED_SCALARS: ReadonlySet<string> = new Set(['String', 'Int', 'Float', 'Boolean', 'ID'])\n\n/** A scalar `@znight/graphql` implements itself (`kind: 'scalar', builtin: true` in the metadata). */\nexport interface BuiltinScalarInfo {\n /** `@specifiedBy(url:)`. Absent: none. */\n readonly specifiedByURL?: string\n}\n\n/**\n * The scalars `@znight/graphql` implements (§5.7): `DateTime` (`Date`), `BigInt` (`bigint`) and\n * `JSON` (`JSONValue`). They have no description. The runtime builds them with exactly these\n * properties and without `valueToLiteral`, so that graphql-js `printSchema` and `printSdl()` agree.\n */\nexport const BUILTIN_SCALARS: ReadonlyMap<string, BuiltinScalarInfo> = new Map<string, BuiltinScalarInfo>([\n ['BigInt', {}],\n ['DateTime', { specifiedByURL: 'https://datatracker.ietf.org/doc/html/rfc3339' }],\n ['JSON', {}],\n])\n\n/** The default `@deprecated` reason of graphql-js: printed as a bare `@deprecated`. */\nexport const DEFAULT_DEPRECATION_REASON = 'No longer supported'\n"],"mappings":";;AAiBA,MAAa,2BAA2B;;;;;;ACoBxC,SAAgB,aAAa,MAA0C;CACrE,MAAM,OAAO,QAAQ,MAAM,CAAC;CAC5B,OAAO,SAAS,KAAA,KAAa,KAAK,QAAQ,KAAK,SAAS,KAAK,MAAM,KAAA;AACrE;;AAGA,SAAgB,aAAa,KAA6B;CACxD,MAAM,QAAQ,IAAI,SAAS,UAAU,IAAI,OAAO,IAAI,aAAa,IAAI,EAAE,EAAE;CACzE,OAAO,IAAI,UAAU,GAAG,MAAM,KAAK;AACrC;AASA,MAAM,eAAe;AACrB,MAAM,gBAAgB;AACtB,MAAM,OAAO;AAEb,SAAS,QAAQ,MAAc,OAAiC;CAC9D,IAAI;CACJ,IAAI;CACJ,IAAI,KAAK,WAAW,KAAK,MAAM,cAAc;EAC3C,MAAM,OAAO,QAAQ,MAAM,QAAQ,CAAC;EACpC,IAAI,SAAS,KAAA,KAAa,KAAK,WAAW,KAAK,GAAG,MAAM,eAAe,OAAO,KAAA;EAC9E,QAAQ,KAAK,MAAM;EACnB,MAAM;GAAE,MAAM;GAAQ,IAAI,KAAK;GAAK,SAAS;EAAM;CACrD,OAAO;EACL,QAAQ;EACR,IAAI,CAAC,YAAY,KAAK,WAAW,KAAK,CAAC,GAAG,OAAO,KAAA;EACjD;EACA,OAAO,eAAe,KAAK,WAAW,KAAK,CAAC,GAAG;EAC/C,MAAM;GAAE,MAAM;GAAS,MAAM,KAAK,MAAM,OAAO,KAAK;GAAG,SAAS;EAAM;CACxE;CACA,IAAI,KAAK,WAAW,KAAK,MAAM,MAC7B,OAAO;EAAE,KAAK;GAAE,GAAG;GAAK,SAAS;EAAK;EAAG,KAAK,QAAQ;CAAE;CAE1D,OAAO;EAAE;EAAK,KAAK;CAAM;AAC3B;;AAGA,SAAS,YAAY,MAAuB;CAC1C,OAAO,SAAS,MAAS,QAAQ,MAAQ,QAAQ,MAAU,QAAQ,MAAQ,QAAQ;AACrF;;AAGA,SAAS,eAAe,MAAuB;CAC7C,OAAO,YAAY,IAAI,KAAM,QAAQ,MAAQ,QAAQ;AACvD;;;;;;;;;AChFA,MAAa,eAAuB;;AAGpC,SAAgB,cAAc,MAAuB;CACnD,OAAO,aAAa,KAAK,IAAI,KAAK,CAAC,KAAK,WAAW,IAAI;AACzD;;AAGA,MAAa,uCAA4C,IAAI,IAAI;CAAC;CAAQ;CAAS;AAAM,CAAC;;AAG1F,MAAa,kBAIT,OAAO,OAAO;CAAE,OAAO;CAAS,UAAU;CAAY,cAAc;AAAe,CAAC;;AAGxF,MAAa,oCAAyC,IAAI,IAAI;CAAC;CAAU;CAAO;CAAS;CAAW;AAAI,CAAC;;;;;;AAazG,MAAa,kCAA0D,IAAI,IAA+B;CACxG,CAAC,UAAU,CAAC,CAAC;CACb,CAAC,YAAY,EAAE,gBAAgB,gDAAgD,CAAC;CAChF,CAAC,QAAQ,CAAC,CAAC;AACb,CAAC;;AAGD,MAAa,6BAA6B"}
|
|
@@ -482,17 +482,18 @@ function pipelineFactory(options) {
|
|
|
482
482
|
}
|
|
483
483
|
function fieldFunctions(options, normalizers, binding, coordinate, field, parent) {
|
|
484
484
|
const container = options.container;
|
|
485
|
-
const invoke = binding.invoke;
|
|
486
485
|
const target = options.resolver(binding, coordinate);
|
|
487
486
|
const guards = [...globalGuardsApply(binding) ? options.globalGuards : [], ...binding.guards.map((token) => options.guard(token, coordinate))];
|
|
488
487
|
const normalize = field.args === void 0 ? void 0 : normalizers.args(field.args);
|
|
489
488
|
const recover = options.results?.(field, coordinate);
|
|
490
|
-
const
|
|
489
|
+
const custom = binding.context === true;
|
|
490
|
+
const route = guards.length === 0 && recover === void 0 && !custom ? void 0 : Object.freeze({
|
|
491
491
|
meta: binding.meta,
|
|
492
492
|
coordinate
|
|
493
493
|
});
|
|
494
494
|
const parentType = parent.name;
|
|
495
495
|
const fieldName = field.name;
|
|
496
|
+
const invoke = custom ? customInvoke(options, binding, coordinate, route, parentType, fieldName) : binding.invoke;
|
|
496
497
|
let resolve;
|
|
497
498
|
if (guards.length === 0) {
|
|
498
499
|
if (target.token === void 0) {
|
|
@@ -515,10 +516,11 @@ function fieldFunctions(options, normalizers, binding, coordinate, field, parent
|
|
|
515
516
|
resolve = (p, a, c, i) => {
|
|
516
517
|
const operation = c;
|
|
517
518
|
const args = a;
|
|
518
|
-
const
|
|
519
|
+
const fieldContext = new FieldContext(route, operation, parentType, fieldName, args, p, i);
|
|
520
|
+
const allowed = runGuards(container, guards, fieldContext);
|
|
519
521
|
const call = () => {
|
|
520
522
|
if (normalize !== void 0) normalize(args);
|
|
521
|
-
return invoke(resolveIn(container, target), p, args, operation, i);
|
|
523
|
+
return invoke(resolveIn(container, target), p, args, operation, i, fieldContext);
|
|
522
524
|
};
|
|
523
525
|
if (allowed === true) return call();
|
|
524
526
|
if (allowed === false) return forbidden();
|
|
@@ -537,6 +539,27 @@ function identity$1(payload) {
|
|
|
537
539
|
return payload;
|
|
538
540
|
}
|
|
539
541
|
/**
|
|
542
|
+
* The invoke of a method with custom parameters (RFC 0010): the generated `invoke` receives the
|
|
543
|
+
* field's `ResolverContext` (the guards' one when the field has guards, else a new one) and the
|
|
544
|
+
* instances of its parameter resolvers: one frozen array resolved at boot when they are all
|
|
545
|
+
* singletons, otherwise resolved in the operation scope on every call.
|
|
546
|
+
*/
|
|
547
|
+
function customInvoke(options, binding, coordinate, route, parentType, fieldName) {
|
|
548
|
+
const generated = binding.invoke;
|
|
549
|
+
const container = options.container;
|
|
550
|
+
const resolvers = (binding.paramResolvers ?? []).map((token) => {
|
|
551
|
+
if (options.paramResolver === void 0) throw new TypeError(`No parameter resolver for ${coordinate}`);
|
|
552
|
+
return options.paramResolver(token, coordinate);
|
|
553
|
+
});
|
|
554
|
+
const context = (p, a, c, i, f) => f ?? new FieldContext(route, c, parentType, fieldName, a, p, i);
|
|
555
|
+
if (resolvers.length === 0) return (r, p, a, c, i, f) => generated(r, p, a, c, i, context(p, a, c, i, f));
|
|
556
|
+
if (resolvers.every((resolver) => resolver.token === void 0)) {
|
|
557
|
+
const instances = Object.freeze(resolvers.map((resolver) => resolveIn(container, resolver)));
|
|
558
|
+
return (r, p, a, c, i, f) => generated(r, p, a, c, i, context(p, a, c, i, f), instances);
|
|
559
|
+
}
|
|
560
|
+
return (r, p, a, c, i, f) => generated(r, p, a, c, i, context(p, a, c, i, f), resolvers.map((resolver) => resolveIn(container, resolver)));
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
540
563
|
* The resolve function of a field that carries results (RFC 0008): errors of the whole pipeline
|
|
541
564
|
* (guards, null handling, `invoke`), thrown or rejected, go through `recover`. Synchronous results
|
|
542
565
|
* stay synchronous; a promise gets one rejection handler. For a subscription, a value is a source
|
|
@@ -1701,6 +1724,7 @@ var GraphQLPlugin = class GraphQLPlugin {
|
|
|
1701
1724
|
globalGuards: globalGuards.map((guard) => guard.resolvable),
|
|
1702
1725
|
guard: (token, coordinate) => providers.token(token, `guard of ${coordinate}`, "canResolve"),
|
|
1703
1726
|
resolver: (binding, coordinate) => providers.token(binding.token, `resolver of ${coordinate}`, binding.method),
|
|
1727
|
+
paramResolver: (token, coordinate) => providers.token(token, `parameter resolver of ${coordinate}`, "resolve"),
|
|
1704
1728
|
inputs,
|
|
1705
1729
|
results: (field, coordinate) => results.recover(field, coordinate)
|
|
1706
1730
|
}));
|
|
@@ -1882,4 +1906,4 @@ var DeferredPubSub = class extends PubSub {
|
|
|
1882
1906
|
};
|
|
1883
1907
|
export { PubSub as a, MemoryPubSub as i, endpointOf as n, orderByKeys as o, executorOf as r, GraphQLPlugin as t };
|
|
1884
1908
|
|
|
1885
|
-
//# sourceMappingURL=plugin-
|
|
1909
|
+
//# sourceMappingURL=plugin-BssB7wtn.mjs.map
|