public function testUsingInlineStructs()
{
// executes with complex input:
$doc = '
{
fieldWithObjectInput(input: {a: "foo", b: ["bar"], c: "baz"})
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
// properly parses single value to list:
$doc = '
{
fieldWithObjectInput(input: {a: "foo", b: "bar", c: "baz"})
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
// properly parses null value to null
$doc = '
{
fieldWithObjectInput(input: {a: null, b: null, c: "C", d: null})
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithObjectInput' => '{"a":null,"b":null,"c":"C","d":null}']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
// properly parses null value in list
$doc = '
{
fieldWithObjectInput(input: {b: ["A",null,"C"], c: "C"})
}
';
$ast = Parser::parse($doc);
$expected = ['data' => ['fieldWithObjectInput' => '{"b":["A",null,"C"],"c":"C"}']];
$this->assertEquals($expected, Executor::execute($this->schema(), $ast)->toArray());
// does not use incorrect value
$doc = '
{
fieldWithObjectInput(input: ["foo", "bar", "baz"])
}
';
$ast = Parser::parse($doc);
$result = Executor::execute($this->schema(), $ast)->toArray();
$expected = ['data' => ['fieldWithObjectInput' => null], 'errors' => [['message' => 'Argument "input" got invalid value ["foo", "bar", "baz"].' . "\n" . 'Expected "TestInputObject", found not an object.', 'path' => ['fieldWithObjectInput']]]];
$this->assertArraySubset($expected, $result);
// properly runs parseLiteral on complex scalar types
$doc = '
{
fieldWithObjectInput(input: {c: "foo", d: "SerializedValue"})
}
';
$ast = Parser::parse($doc);
$this->assertEquals(['data' => ['fieldWithObjectInput' => '{"c":"foo","d":"DeserializedValue"}']], Executor::execute($this->schema(), $ast)->toArray());
}