@@ -30,6 +30,8 @@ import {
3030import { GraphQLBoolean , GraphQLString } from '../../type/scalars.js' ;
3131import { GraphQLSchema } from '../../type/schema.js' ;
3232
33+ import { valueFromASTUntyped } from '../../utilities/valueFromASTUntyped.js' ;
34+
3335import { executeSync , experimentalExecuteIncrementally } from '../execute.js' ;
3436import { getVariableValues } from '../values.js' ;
3537
@@ -64,6 +66,16 @@ const TestComplexScalar = new GraphQLScalarType({
6466 } ,
6567} ) ;
6668
69+ const TestJSONScalar = new GraphQLScalarType ( {
70+ name : 'JSONScalar' ,
71+ coerceInputValue ( value ) {
72+ return value ;
73+ } ,
74+ coerceInputLiteral ( value ) {
75+ return valueFromASTUntyped ( value ) ;
76+ } ,
77+ } ) ;
78+
6779const NestedType : GraphQLObjectType = new GraphQLObjectType ( {
6880 name : 'NestedType' ,
6981 fields : {
@@ -151,6 +163,7 @@ const TestType = new GraphQLObjectType({
151163 fieldWithNestedInputObject : fieldWithInputArg ( {
152164 type : TestNestedInputObject ,
153165 } ) ,
166+ fieldWithJSONScalarInput : fieldWithInputArg ( { type : TestJSONScalar } ) ,
154167 list : fieldWithInputArg ( { type : new GraphQLList ( GraphQLString ) } ) ,
155168 nested : {
156169 type : NestedType ,
@@ -859,6 +872,74 @@ describe('Execute: Handles inputs', () => {
859872 } ) ;
860873 } ) ;
861874
875+ // Note: the below is non-specified custom graphql-js behavior.
876+ describe ( 'Handles custom scalars with embedded variables' , ( ) => {
877+ it ( 'allows custom scalars' , ( ) => {
878+ const result = executeQuery ( `
879+ {
880+ fieldWithJSONScalarInput(input: { a: "foo", b: ["bar"], c: "baz" })
881+ }
882+ ` ) ;
883+
884+ expectJSON ( result ) . toDeepEqual ( {
885+ data : {
886+ fieldWithJSONScalarInput : '{ a: "foo", b: ["bar"], c: "baz" }' ,
887+ } ,
888+ } ) ;
889+ } ) ;
890+
891+ it ( 'allows custom scalars with non-embedded variables' , ( ) => {
892+ const result = executeQuery (
893+ `
894+ query ($input: JSONScalar) {
895+ fieldWithJSONScalarInput(input: $input)
896+ }
897+ ` ,
898+ { input : { a : 'foo' , b : [ 'bar' ] , c : 'baz' } } ,
899+ ) ;
900+
901+ expectJSON ( result ) . toDeepEqual ( {
902+ data : {
903+ fieldWithJSONScalarInput : '{ a: "foo", b: ["bar"], c: "baz" }' ,
904+ } ,
905+ } ) ;
906+ } ) ;
907+
908+ it ( 'allows custom scalars with embedded operation variables' , ( ) => {
909+ const result = executeQuery (
910+ `
911+ query ($input: String) {
912+ fieldWithJSONScalarInput(input: { a: $input, b: ["bar"], c: "baz" })
913+ }
914+ ` ,
915+ { input : 'foo' } ,
916+ ) ;
917+
918+ expectJSON ( result ) . toDeepEqual ( {
919+ data : {
920+ fieldWithJSONScalarInput : '{ a: "foo", b: ["bar"], c: "baz" }' ,
921+ } ,
922+ } ) ;
923+ } ) ;
924+
925+ it ( 'allows custom scalars with embedded fragment variables' , ( ) => {
926+ const result = executeQueryWithFragmentArguments ( `
927+ {
928+ ...JSONFragment(input: "foo")
929+ }
930+ fragment JSONFragment($input: String) on TestType {
931+ fieldWithJSONScalarInput(input: { a: $input, b: ["bar"], c: "baz" })
932+ }
933+ ` ) ;
934+
935+ expectJSON ( result ) . toDeepEqual ( {
936+ data : {
937+ fieldWithJSONScalarInput : '{ a: "foo", b: ["bar"], c: "baz" }' ,
938+ } ,
939+ } ) ;
940+ } ) ;
941+ } ) ;
942+
862943 describe ( 'Handles lists and nullability' , ( ) => {
863944 it ( 'allows lists to be null' , ( ) => {
864945 const doc = `
0 commit comments