graphile-settings
Version:
graphile settings
38 lines (37 loc) • 1.63 kB
TypeScript
import 'graphile-build';
import 'graphile-build-pg';
import type { GraphileConfig } from 'graphile-config';
/**
* RequiredInputPlugin - Makes @requiredInput tagged fields non-nullable in mutation inputs.
*
* WHY THIS EXISTS:
* Some foreign key columns are nullable at the database level (to allow SET NULL cascades
* on FK deletion) but should be required at the API level (the application should always
* provide a value when creating or updating a record).
*
* The `api_required` column in constructive-db's metaschema injects a `@requiredInput`
* smart tag via PostgreSQL COMMENT ON COLUMN. This plugin reads that tag and wraps the
* corresponding GraphQL input field type with NonNull, making it required in mutations
* while keeping the output type nullable.
*
* USAGE:
* In the database, set the smart tag on a column:
* COMMENT ON COLUMN app_public.membership.grantor_id IS E'@requiredInput';
*
* Or via constructive-db's metaschema:
* UPDATE metaschema_public.field SET api_required = true WHERE ...;
*
* The trigger `tg_sync_api_required_smart_tag` will inject `{"requiredInput": true}`
* into the column's smart_tags JSONB, which PostGraphile reads as `@requiredInput`.
*
* RESULT:
* - Mutation input types (create, patch, base): field becomes non-nullable (required)
* - Output types: field remains nullable (unchanged)
* - Query filters: unaffected
*/
export declare const RequiredInputPlugin: GraphileConfig.Plugin;
/**
* Preset that includes the RequiredInputPlugin.
* Add this to your main preset's `extends` array.
*/
export declare const RequiredInputPreset: GraphileConfig.Preset;