-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #3051
- Loading branch information
Showing
23 changed files
with
288 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { ConstValueNode } from '../language/ast'; | ||
|
||
import { GraphQLInputType, GraphQLDefaultValueUsage } from './definition'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function getLiteralDefaultValue( | ||
usage: GraphQLDefaultValueUsage, | ||
type: GraphQLInputType, | ||
): ConstValueNode; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function getCoercedDefaultValue( | ||
usage: GraphQLDefaultValueUsage, | ||
type: GraphQLInputType, | ||
): unknown; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { invariant } from '../jsutils/invariant'; | ||
import type { ConstValueNode } from '../language/ast'; | ||
|
||
import { astFromValue } from '../utilities/astFromValue'; | ||
import { valueFromAST } from '../utilities/valueFromAST'; | ||
|
||
import type { GraphQLInputType, GraphQLDefaultValueUsage } from './definition'; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function getLiteralDefaultValue( | ||
usage: GraphQLDefaultValueUsage, | ||
type: GraphQLInputType, | ||
): ConstValueNode { | ||
if (usage.literal) { | ||
return usage.literal; | ||
} | ||
// Memoize the result of converting value to literal in a hidden field. | ||
let literal = (usage: any)._memoizedLiteral; | ||
// istanbul ignore else (memoized case) | ||
if (!literal) { | ||
literal = astFromValue(usage.value, type); | ||
invariant(literal, 'Value cannot be converted to literal for this type'); | ||
(usage: any)._memoizedLiteral = literal; | ||
} | ||
return literal; | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function getCoercedDefaultValue( | ||
usage: GraphQLDefaultValueUsage, | ||
type: GraphQLInputType, | ||
): mixed { | ||
if (usage.value !== undefined) { | ||
return usage.value; | ||
} | ||
// Memoize the result of coercing the default value in a hidden field. | ||
let coercedValue = (usage: any)._memoizedCoercedValue; | ||
// istanbul ignore else (memoized case) | ||
if (coercedValue === undefined) { | ||
coercedValue = valueFromAST(usage.literal, type); | ||
invariant( | ||
coercedValue !== undefined, | ||
'Literal cannot be converted to value for this type', | ||
); | ||
(usage: any)._memoizedCoercedValue = coercedValue; | ||
} | ||
return coercedValue; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.