import "./global.ts"; import "./interfaces.ts"; export { isValidBehaviorString } from "./behavior.ts"; import { AddNodeInterfaceToSuitableTypesPlugin, BuiltinScalarConnectionsPlugin, ClientMutationIdDescriptionPlugin, CommonBehaviorsPlugin, CommonTypesPlugin, CursorTypePlugin, MinifySchemaPlugin, MutationPayloadQueryPlugin, MutationPlugin, NodeAccessorPlugin, NodeIdCodecBase64JSONPlugin, NodeIdCodecPipeStringPlugin, NodePlugin, PageInfoStartEndCursorPlugin, QueryPlugin, QueryQueryPlugin, RegisterQueryNodePlugin, StreamDeferPlugin, SubscriptionPlugin, SwallowErrorsPlugin, TrimEmptyDescriptionsPlugin } from "./plugins/index.ts"; import SchemaBuilder from "./SchemaBuilder.ts"; export { camelCase, constantCase, constantCaseAll, EXPORTABLE, EXPORTABLE_ARRAY_CLONE, EXPORTABLE_OBJECT_CLONE, formatInsideUnderscores, gatherConfig, pluralize, singularize, upperCamelCase, upperFirst, } from "./utils.ts"; import type { GrafastArgumentConfig, GrafastFieldConfig, GrafastFieldConfigArgumentMap, PromiseOrDirect } from "grafast"; import type { GraphQLArgumentConfig, GraphQLEnumTypeConfig, GraphQLEnumValueConfig, GraphQLEnumValueConfigMap, GraphQLFieldConfig, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, GraphQLInterfaceType, GraphQLNamedType, GraphQLObjectType, GraphQLScalarTypeConfig, GraphQLSchema, GraphQLSchemaConfig } from "grafast/graphql"; import type { PluginHook } from "graphile-config"; import type { GatherPluginContext, GatherPluginContextBase } from "./interfaces.ts"; import type { NewWithHooksFunction } from "./newWithHooks/index.ts"; export type { GraphileBuild, GraphileConfig }; export type { NewWithHooksFunction }; export { SchemaBuilder }; /** @experimental */ export interface InflectorSource { pluginName: string; source: string; } /** * Generate 'build.inflection' from the given preset. */ export declare const buildInflection: (preset: GraphileConfig.Preset, /** @internal */ trace?: Map) => GraphileBuild.Inflection; /** * One-time gather. See `watchGather` for watch mode. */ export declare const gather: (preset: GraphileConfig.Preset, helpers?: { inflection: GraphileBuild.Inflection; }) => Promise; /** * Tells your gather plugins to monitor their sources, and passes the resulting * BuildInput to the callback each time a new one is generated. It is * guaranteed that the `callback` will be called at least once before the * promise resolves. * * @returns A callback to call to stop watching. */ export declare const watchGather: (preset: GraphileConfig.Preset, helpers: { inflection: GraphileBuild.Inflection; } | undefined, callback: (gather: GraphileBuild.BuildInput | null, error: Error | undefined, retry: () => void) => PromiseOrDirect) => Promise<() => void>; /** * Gets a SchemaBuilder object for the given preset and inflection. It's rare * you would need this, typically you'll want `buildSchema` instead. */ export declare const getBuilder: (preset: GraphileConfig.Preset, inflection?: GraphileBuild.Inflection) => SchemaBuilder; /** * Builds a GraphQL schema according to the given preset and input data. */ export declare const buildSchema: (rawPreset: GraphileConfig.Preset, input: GraphileBuild.BuildInput, shared?: { inflection?: GraphileBuild.Inflection; }) => GraphQLSchema; export { AddNodeInterfaceToSuitableTypesPlugin, BuiltinScalarConnectionsPlugin, ClientMutationIdDescriptionPlugin, CommonBehaviorsPlugin, CommonTypesPlugin, CursorTypePlugin, MinifySchemaPlugin, MutationPayloadQueryPlugin, MutationPlugin, NodeAccessorPlugin, NodeIdCodecBase64JSONPlugin, NodeIdCodecPipeStringPlugin, NodePlugin, PageInfoStartEndCursorPlugin, QueryPlugin, QueryQueryPlugin, RegisterQueryNodePlugin, StreamDeferPlugin, SubscriptionPlugin, SwallowErrorsPlugin, TrimEmptyDescriptionsPlugin, }; export type { GatherPluginContext } from "./interfaces.ts"; export { defaultPreset } from "./preset.ts"; export interface SchemaResult { schema: GraphQLSchema; resolvedPreset: GraphileConfig.ResolvedPreset; } /** * Builds the GraphQL schema by resolving the preset, running inflection then * gather and building the schema. Returns the results. * * @experimental */ export declare function makeSchema(preset: GraphileConfig.Preset): Promise; /** * Runs the "gather" phase in watch mode and calls 'callback' with the * generated SchemaResult each time a new schema is generated. * * It is guaranteed that `callback` will be called at least once before the * promise resolves. * * Returns a function that can be called to stop watching. * * @experimental */ export declare function watchSchema(preset: GraphileConfig.Preset, callback: (fatalError: Error | null, params?: SchemaResult) => PromiseOrDirect): Promise<() => void>; export { version } from "./version.ts"; declare global { namespace GraphileBuild { type EntityBehaviorHook = PluginHook<(behavior: GraphileBuild.BehaviorString, entity: GraphileBuild.BehaviorEntities[entityType], build: GraphileBuild.Build) => GraphileBuild.BehaviorString | GraphileBuild.BehaviorString[]>; } namespace GraphileConfig { interface Provides { default: true; inferred: true; override: true; } interface Preset { /** * The inflection phase is the first phase that occurs when building a * schema with Graphile Build. It is responsible for naming things - both * things that are generated in the `gather` phase, and the ultimate * types, fields, arguments, directives and so on in the GraphQL schema. */ inflection?: GraphileBuild.InflectionOptions; /** * The `gather` phase is the second phase that occurs when building a * schema with Graphile Build. It is responsible for looking at * everything that can influence the shape of your schema, and turning * that into an "input" for the `schema` phase. */ gather?: GraphileBuild.GatherOptions; /** * The `schema` phase is the final phase that occurs when building a * schema with Graphile Build. It is responsible for taking the inputs * from the `gather` phase (and using the inflectors from the * `inflection` phase) and generating a final GraphQL schema. */ schema?: GraphileBuild.SchemaOptions; } interface PluginInflectionConfig { /** * Define new inflectors here */ add?: { [key in keyof GraphileBuild.Inflection]?: (this: GraphileBuild.Inflection, options: ResolvedPreset, ...args: Parameters) => ReturnType; }; /** * Overwrite existing inflectors here. */ replace?: { [key in keyof GraphileBuild.Inflection]?: (this: GraphileBuild.Inflection, previous: // This is specifically so the `this` argument is removed ((...args: Parameters) => ReturnType) | undefined, options: ResolvedPreset, ...args: Parameters) => ReturnType; }; /** * If set and you attempt to replace a non-existent inflector of one of * the given names, we won't warn you. */ ignoreReplaceIfNotExists?: Array; } interface GatherHelpers { } interface GatherHooks { } interface PluginGatherConfig { /** * A unique namespace for this plugin to use. */ namespace?: TNamespace; /** * If this plugin supports a persistant internal state (aka a cache, this * is an optimisation for watch mode), this returns the value to initialise * this cache to. */ initialCache?: (context: GatherPluginContextBase) => TCache; /** * The initial value to use for this plugin when a new gather run * executes. */ initialState?: (cache: TCache, context: GatherPluginContextBase) => PromiseOrDirect; /** * The plugin must register helpers to allow other plugins to access its * internal state. (Just use an empty object if you don't need any.) */ helpers?: { [key in keyof GatherHelpers[TNamespace]]: (info: GatherPluginContext, ...args: Parameters) => ReturnType; }; hooks?: { [key in keyof GatherHooks]?: PluginHook infer UResult ? (info: GatherPluginContext, ...args: UArgs) => UResult : never>; }; /** * Responsible for kicking off the data collection - ask for data from * other plugins (or your own helpers), write data needed by the 'schema' * phase to the 'output' object. */ main?: (output: Partial, info: GatherPluginContext) => Promise; /** * Called when the plugin is put into watch mode; the plugin should call * the given callback whenever a change is detected, and should return a * function that prevents this behaviour. */ watch?: (info: GatherPluginContext, callback: () => void) => PromiseOrDirect<() => void>; } interface Plugin { inflection?: PluginInflectionConfig; gather?: PluginGatherConfig; schema?: { globalBehavior?: GraphileBuild.BehaviorString | GraphileBuild.BehaviorString[] | ((behavior: GraphileBuild.BehaviorString, build: GraphileBuild.Build) => GraphileBuild.BehaviorString | GraphileBuild.BehaviorString[]); behaviorRegistry?: { add?: Partial; }>>; }; /** * You should use `before`, `after` and `provides` to ensure that the entity * behaviors apply in order. The order should be roughly: * * - `default` - default global behaviors like "update" * - `inferred` - behaviors that are inferred based on the entity, e.g. a plugin might disable filtering _by default_ on a relation if it's unindexed * - `override` - overrides set explicitly by the user */ entityBehavior?: { [entityType in keyof GraphileBuild.BehaviorEntities]?: GraphileBuild.BehaviorString | GraphileBuild.BehaviorString[] | { inferred?: GraphileBuild.EntityBehaviorHook; override?: GraphileBuild.EntityBehaviorHook; }; }; hooks?: { /** * The build object represents the current schema build and is passed to all * hooks, hook the 'build' event to extend this object. Note: you MUST NOT * generate GraphQL objects during this phase. */ build?: PluginHook & GraphileBuild.BuildBase, GraphileBuild.ContextBuild, Partial & GraphileBuild.BuildBase>>; /** * The `init` phase runs after `build` is complete but before any types * or the schema are actually built. It is the only phase in which you * can register GraphQL types; do so using `build.registerType`. */ init?: PluginHook, GraphileBuild.ContextInit, GraphileBuild.Build>>; /** * 'finalize' phase is called once the schema is built; typically you * shouldn't use this, but it's useful for interfacing with external * libraries that mutate an already constructed schema. */ finalize?: PluginHook>; /** * Add 'query', 'mutation' or 'subscription' types in this hook: */ GraphQLSchema?: PluginHook>; /** * Add any types that need registering (typically polymorphic types) here */ GraphQLSchema_types?: PluginHook>; /** * When creating a GraphQLObjectType via `newWithHooks`, we'll * execute, the following hooks: * - 'GraphQLObjectType' to add any root-level attributes, e.g. add a description * - 'GraphQLObjectType_interfaces' to add additional interfaces to this object type * - 'GraphQLObjectType_fields' to add additional fields to this object type (is * ran asynchronously and gets a reference to the final GraphQL Object as * `Self` in the context) * - 'GraphQLObjectType_fields_field' to customize an individual field from above * - 'GraphQLObjectType_fields_field_args' to add additional arguments to a field * - 'GraphQLObjectType_fields_field_args_arg' to customize an individual argument from above */ GraphQLObjectType?: PluginHook, GraphileBuild.ContextObject, GraphileBuild.Build>>; GraphQLObjectType_interfaces?: PluginHook>; GraphQLObjectType_fields?: PluginHook, GraphileBuild.ContextObjectFields, GraphileBuild.Build>>; GraphQLObjectType_fields_field?: PluginHook, GraphileBuild.ContextObjectFieldsField, GraphileBuild.Build>>; GraphQLObjectType_fields_field_args?: PluginHook>; GraphQLObjectType_fields_field_args_arg?: PluginHook, GraphileBuild.ContextObjectFieldsFieldArgsArg, GraphileBuild.Build>>; /** * When creating a GraphQLInputObjectType via `newWithHooks`, we'll * execute, the following hooks: * - 'GraphQLInputObjectType' to add any root-level attributes, e.g. add a description * - 'GraphQLInputObjectType_fields' to add additional fields to this object type (is * ran asynchronously and gets a reference to the final GraphQL Object as * `Self` in the context) * - 'GraphQLInputObjectType_fields_field' to customize an individual field from above */ GraphQLInputObjectType?: PluginHook>; GraphQLInputObjectType_fields?: PluginHook>; GraphQLInputObjectType_fields_field?: PluginHook>; /** * When creating a GraphQLEnumType via `newWithHooks`, we'll * execute, the following hooks: * - 'GraphQLEnumType' to add any root-level attributes, e.g. add a description * - 'GraphQLEnumType_values' to add additional values * - 'GraphQLEnumType_values_value' to change an individual value */ GraphQLEnumType?: PluginHook>; GraphQLEnumType_values?: PluginHook>; GraphQLEnumType_values_value?: PluginHook>; /** * When creating a GraphQLUnionType via `newWithHooks`, we'll * execute, the following hooks: * - 'GraphQLUnionType' to add any root-level attributes, e.g. add a description * - 'GraphQLUnionType_types' to add additional types to this union */ GraphQLUnionType?: PluginHook, GraphileBuild.ContextUnion, GraphileBuild.Build>>; GraphQLUnionType_types?: PluginHook>; /** * When creating a GraphQLInterfaceType via `newWithHooks`, we'll * execute, the following hooks: * - 'GraphQLInterfaceType' to add any root-level attributes, e.g. add a description * - 'GraphQLInterfaceType_fields' to add additional fields to this interface type (is * ran asynchronously and gets a reference to the final GraphQL Interface as * `Self` in the context) * - 'GraphQLInterfaceType_fields_field' to customise an individual field from above * - 'GraphQLInterfaceType_fields_field_args' to add additional arguments to a field * - 'GraphQLInterfaceType_fields_field_args_arg' to customize an individual arguments from the above */ GraphQLInterfaceType?: PluginHook, GraphileBuild.ContextInterface, GraphileBuild.Build>>; GraphQLInterfaceType_fields?: PluginHook, GraphileBuild.ContextInterfaceFields, GraphileBuild.Build>>; GraphQLInterfaceType_fields_field?: PluginHook, GraphileBuild.ContextInterfaceFieldsField, GraphileBuild.Build>>; GraphQLInterfaceType_fields_field_args?: PluginHook>; GraphQLInterfaceType_fields_field_args_arg?: PluginHook>; GraphQLInterfaceType_interfaces?: PluginHook>; /** * For scalars */ GraphQLScalarType?: PluginHook, GraphileBuild.ContextScalar, GraphileBuild.Build>>; }; }; } } } //# sourceMappingURL=index.d.ts.map