Skip to content

Commit

Permalink
RFC: Default value validation & coercion
Browse files Browse the repository at this point in the history
Implements graphql/graphql-spec#793

* Adds validation of default values during schema validation.
* Adds coercion of default values anywhere a default value is used at runtime

Potentially breaking:
* Deprecates `astFromValue`
* Changes type of `defaultValue` provided during type configuration from an "internal" to an "external" value.
  • Loading branch information
leebyron authored and yaacovCR committed Sep 17, 2024
1 parent 2300b66 commit 082f177
Show file tree
Hide file tree
Showing 13 changed files with 900 additions and 37 deletions.
2 changes: 2 additions & 0 deletions cspell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ ignoreRegExpList:

words:
- graphiql
- uncoerce
- uncoerced

# Different names used inside tests
- Skywalker
Expand Down
1 change: 0 additions & 1 deletion src/execution/__tests__/variables-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ const TestType = new GraphQLObjectType({
}),
fieldWithNestedInputObject: fieldWithInputArg({
type: TestNestedInputObject,
defaultValue: 'Hello World',
}),
list: fieldWithInputArg({ type: new GraphQLList(GraphQLString) }),
nested: {
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ export {
// Create a JavaScript value from a GraphQL language AST without a Type.
valueFromASTUntyped,
// Create a GraphQL language AST from a JavaScript value.
/** @deprecated use `valueToLiteral()` instead with care to operate on external values - `astFromValue()` will be removed in v18 */
astFromValue,
// A helper to use within recursive-descent visitors which need to be aware of the GraphQL type system.
TypeInfo,
Expand Down
4 changes: 1 addition & 3 deletions src/type/__tests__/enumType-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ const QueryType = new GraphQLObjectType({
args: {
fromEnum: {
type: ComplexEnum,
// Note: defaultValue is provided an *internal* representation for
// Enums, rather than the string name.
defaultValue: Complex1,
defaultValue: 'ONE',
},
provideGoodValue: { type: GraphQLBoolean },
provideBadValue: { type: GraphQLBoolean },
Expand Down
Loading

0 comments on commit 082f177

Please sign in to comment.