Skip to content

Commit 68aa617

Browse files
Test coerce scalar in nested object
1 parent b92feeb commit 68aa617

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

test/integration/graphql_test.lua

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,28 @@ function g.test_custom_type_scalar_variables()
608608
resolve = function(_, args)
609609
return args.object.nested_object.field
610610
end
611-
}
611+
},
612+
['test_json_type_inputObject'] = {
613+
kind = json_type,
614+
arguments = {
615+
object = types.inputObject({
616+
name = 'ComplexJsonInputObject',
617+
fields = {
618+
nested_object = types.inputObject({
619+
name = 'ComplexJsonNestedInputObject',
620+
fields = {
621+
field = json_type,
622+
}
623+
}),
624+
}
625+
}),
626+
},
627+
resolve = function(_, args)
628+
t.assert_type(args.object.nested_object.field, 'table', "Object element is not a table! ")
629+
t.assert_not_equals(args.object.nested_object.field.test, nil, "No field 'test' in object element!")
630+
return args.object.nested_object.field
631+
end
632+
},
612633
}
613634

614635
t.assert_equals(check_request([[
@@ -779,6 +800,16 @@ function g.test_custom_type_scalar_variables()
779800
]], query_schema, nil, nil, {variables = {fields = {'echo'}}})
780801
end
781802
)
803+
804+
t.assert_equals(check_request([[
805+
query($field: Json!) {
806+
test_json_type_inputObject(
807+
object: { nested_object: { field: $field } }
808+
)
809+
}
810+
]], query_schema, nil, nil, {
811+
variables = {field = json.encode({test = 123})},
812+
}), {test_json_type_inputObject = '{"test":123}'})
782813
end
783814

784815
function g.test_output_type_mismatch_error()

0 commit comments

Comments
 (0)