import { type GraphQLSchema } from 'graphql'; /** * Check what a widget feeds its page query against the schema as it is NOW. * * A widget's settings reach the page query as GraphQL variables. Some of those * variables are typed input objects (the slideshow's `slides: [SlideInput]`), * and an input object rejects any key it does not define. When ONE variable is * rejected, `execute()` returns no `data` at all, so a single bad key in a * single widget used to blank the whole page and crash the first core * component that reads a prop (`HeadTags`). * * Nothing in here knows a field name. The input types come from the schema * passed in, so a field added to `SlideInput` tomorrow is accepted tomorrow and * a field removed from it is reported tomorrow, with no second list to update. * The final verdict is graphql-js's own `getVariableValues`, the exact step * `execute()` runs, so this check cannot disagree with what a request would do. */ /** One variable a widget's query declares, e.g. `$slides: [SlideInput]`. */ export interface VariableDefinition { /** The name used in the operation. Unique per request. */ alias: string; /** The type as the component wrote it: `[SlideInput]`, `Int!`. */ type: string; /** The name the component's author gave it (`slides`). Used in messages. */ origin?: string; } /** A key inside a variable's value that the input type does not define. */ export interface UnknownKey { /** The variable's own name, e.g. `slides`. */ variable: string; /** Where the key sits inside the value, e.g. `slides[0].imageAlt`. */ path: string; /** The input type that does not define it, e.g. `SlideInput`. */ typeName: string; /** What that type does define, sorted. */ accepted: string[]; } /** Something GraphQL would still reject once the unknown keys are gone. */ export interface VariableProblem { variable: string; message: string; } export interface VariableCheck { /** The values with every unknown key removed. Safe to hand to `execute()` when `problems` is empty. */ values: Record; unknownKeys: UnknownKey[]; problems: VariableProblem[]; } /** * Check `values` (keyed by variable alias) against `defs` and `schema`. * * - Keys the current input types do not define are removed from `values` and * listed in `unknownKeys`. A caller that renders pages uses the cleaned * `values`; a caller that saves data refuses `unknownKeys`. * - Whatever GraphQL still rejects after that (a string where an `Int` goes, a * missing required field, a `null` for a `!` type) is listed in `problems`. */ export declare function checkVariables(schema: GraphQLSchema, defs: VariableDefinition[], values: Record): VariableCheck; /** `slides[0].imageAlt is not a field of SlideInput (it accepts: id, image, ...)` */ export declare function describeUnknownKey(key: UnknownKey): string;