Skip to content

Commit a3cd04a

Browse files
authored
docs: hide private internals schema.__validationErrors and inputValue._memoizedCoercedDefaultValue (#4756)
1 parent 8f01dd2 commit a3cd04a

3 files changed

Lines changed: 21 additions & 5 deletions

File tree

src/type/definition.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3192,6 +3192,11 @@ export class GraphQLArgument implements GraphQLSchemaElement {
31923192
defaultValue: unknown;
31933193
/** Default value represented as either a runtime value or a GraphQL literal. */
31943194
default: GraphQLDefaultInput | undefined;
3195+
/**
3196+
* Cached coerced default value.
3197+
* @private
3198+
*/
3199+
_memoizedCoercedDefaultValue: unknown;
31953200
/** Reason this element is deprecated, if one was provided. */
31963201
deprecationReason: Maybe<string>;
31973202
/** Extension fields to include in the formatted result. */
@@ -3237,6 +3242,7 @@ export class GraphQLArgument implements GraphQLSchemaElement {
32373242
this.type = config.type;
32383243
this.defaultValue = config.defaultValue;
32393244
this.default = config.default;
3245+
this._memoizedCoercedDefaultValue = undefined;
32403246
this.deprecationReason = config.deprecationReason;
32413247
this.extensions = toObjMapWithSymbols(config.extensions);
32423248
this.astNode = config.astNode;
@@ -5150,6 +5156,11 @@ export class GraphQLInputField implements GraphQLSchemaElement {
51505156
defaultValue: unknown;
51515157
/** Default value represented as either a runtime value or a GraphQL literal. */
51525158
default: GraphQLDefaultInput | undefined;
5159+
/**
5160+
* Cached coerced default value.
5161+
* @private
5162+
*/
5163+
_memoizedCoercedDefaultValue: unknown;
51535164
/** Reason this element is deprecated, if one was provided. */
51545165
deprecationReason: Maybe<string>;
51555166
/** Extension fields to include in the formatted result. */
@@ -5197,6 +5208,7 @@ export class GraphQLInputField implements GraphQLSchemaElement {
51975208
this.type = config.type;
51985209
this.defaultValue = config.defaultValue;
51995210
this.default = config.default;
5211+
this._memoizedCoercedDefaultValue = undefined;
52005212
this.deprecationReason = config.deprecationReason;
52015213
this.extensions = toObjMapWithSymbols(config.extensions);
52025214
this.astNode = config.astNode;

src/type/schema.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,10 @@ export class GraphQLSchema {
207207

208208
/** Whether this schema instance skips validation checks. */
209209
assumeValid: boolean;
210-
/** Cached schema validation errors, if validation has already run. */
210+
/**
211+
* Cached schema validation errors, if validation has already run.
212+
* @private
213+
*/
211214
__validationErrors: Maybe<ReadonlyArray<GraphQLError>>;
212215

213216
private _queryType: Maybe<GraphQLObjectType>;
@@ -316,7 +319,6 @@ export class GraphQLSchema {
316319
* schema.getType('AuditEvent'); // => AuditEvent
317320
* schema.getDirective('auth'); // => authDirective
318321
* schema.extensions; // => { owner: 'platform' }
319-
* schema.__validationErrors; // => []
320322
* ```
321323
*/
322324
constructor(config: Readonly<GraphQLSchemaConfig>) {

src/utilities/coerceInputValue.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ interface InputValue {
405405
type: GraphQLInputType;
406406
default?: GraphQLDefaultInput | undefined;
407407
defaultValue?: unknown;
408+
/** @private */
409+
_memoizedCoercedDefaultValue?: unknown;
408410
}
409411

410412
/**
@@ -417,7 +419,7 @@ interface InputValue {
417419
*/
418420
export function coerceDefaultValue(inputValue: InputValue): unknown {
419421
// Memoize the result of coercing the default value in a hidden field.
420-
let coercedDefaultValue = (inputValue as any)._memoizedCoercedDefaultValue;
422+
let coercedDefaultValue = inputValue._memoizedCoercedDefaultValue;
421423
if (coercedDefaultValue !== undefined) {
422424
return coercedDefaultValue;
423425
}
@@ -433,13 +435,13 @@ export function coerceDefaultValue(inputValue: InputValue): unknown {
433435
defaultInput.literal ?? defaultInput.value,
434436
)}.`,
435437
);
436-
(inputValue as any)._memoizedCoercedDefaultValue = coercedDefaultValue;
438+
inputValue._memoizedCoercedDefaultValue = coercedDefaultValue;
437439
return coercedDefaultValue;
438440
}
439441

440442
const defaultValue = inputValue.defaultValue;
441443
if (defaultValue !== undefined) {
442-
(inputValue as any)._memoizedCoercedDefaultValue = defaultValue;
444+
inputValue._memoizedCoercedDefaultValue = defaultValue;
443445
}
444446
return defaultValue;
445447
}

0 commit comments

Comments
 (0)