diff --git a/Resolver/Resolver.php b/Resolver/Resolver.php index 396ebbcd0..a70a5026c 100644 --- a/Resolver/Resolver.php +++ b/Resolver/Resolver.php @@ -49,7 +49,7 @@ public static function wrapArgs(callable $resolver) { return static function () use ($resolver) { $args = func_get_args(); - if (count($args) > 1) { + if (count($args) > 1 && !$args[1] instanceof Argument) { $args[1] = new Argument($args[1]); } diff --git a/Tests/Functional/App/config/argumentWrapper/config.yml b/Tests/Functional/App/config/argumentWrapper/config.yml index 2505a63a3..968c37f14 100644 --- a/Tests/Functional/App/config/argumentWrapper/config.yml +++ b/Tests/Functional/App/config/argumentWrapper/config.yml @@ -13,3 +13,16 @@ overblog_graphql: - type: yaml dir: "%kernel.root_dir%/config/argumentWrapper/mapping" +services: + expression_function_instance_of: + class: Symfony\Component\ExpressionLanguage\ExpressionFunction + factory: Symfony\Component\ExpressionLanguage\ExpressionFunction::fromPhp + arguments: + - 'is_a' + tags: ['overblog_graphql.expression_function'] + expression_function_json_encode: + class: Symfony\Component\ExpressionLanguage\ExpressionFunction + factory: Symfony\Component\ExpressionLanguage\ExpressionFunction::fromPhp + arguments: + - 'json_encode' + tags: ['overblog_graphql.expression_function'] diff --git a/Tests/Functional/App/config/argumentWrapper/mapping/query.types.yml b/Tests/Functional/App/config/argumentWrapper/mapping/query.types.yml index 447453250..7992e9963 100644 --- a/Tests/Functional/App/config/argumentWrapper/mapping/query.types.yml +++ b/Tests/Functional/App/config/argumentWrapper/mapping/query.types.yml @@ -1,16 +1,19 @@ RootQuery: type: object config: - resolveField: '@="Arguments: " ~ args["unknown"] ~ args["name"]' + resolveField: '@="Arguments: " ~ json_encode(args.getRawArguments()) ~ " | InstanceOf: " ~ json_encode(is_a(args, "Overblog\\GraphQLBundle\\Definition\\Argument"))' fields: fieldWithResolverAndArgument: type: String! args: name: {type: String!} - resolve: '@="Arguments: " ~ args["unknown"] ~ args["name"]' + resolve: '@="Field resolver Arguments: " ~ json_encode(args.getRawArguments()) ~ " | InstanceOf: " ~ json_encode(is_a(args, "Overblog\\GraphQLBundle\\Definition\\Argument"))' fieldWithDefaultResolverAndArgument: type: String! args: name: {type: String!} + fieldWithAccess: + type: String! + access: "@=true" field: type: String! diff --git a/Tests/Functional/ArgumentWrapper/ArgumentWrapperTest.php b/Tests/Functional/ArgumentWrapper/ArgumentWrapperTest.php index 53e7c066d..97eb81fa0 100644 --- a/Tests/Functional/ArgumentWrapper/ArgumentWrapperTest.php +++ b/Tests/Functional/ArgumentWrapper/ArgumentWrapperTest.php @@ -13,11 +13,12 @@ protected function setUp() public function testQuery() { - $query = '{ fieldWithResolverAndArgument(name: "foo") fieldWithDefaultResolverAndArgument(name: "bar") field }'; + $query = '{ fieldWithResolverAndArgument(name: "foo") fieldWithDefaultResolverAndArgument(name: "bar") field fieldWithAccess}'; $expectedData = [ - 'fieldWithResolverAndArgument' => 'Arguments: foo', - 'fieldWithDefaultResolverAndArgument' => 'Arguments: bar', - 'field' => 'Arguments: ', + 'fieldWithResolverAndArgument' => 'Field resolver Arguments: {"name":"foo"} | InstanceOf: true', + 'fieldWithDefaultResolverAndArgument' => 'Arguments: {"name":"bar"} | InstanceOf: true', + 'field' => 'Arguments: [] | InstanceOf: true', + 'fieldWithAccess' => 'Arguments: [] | InstanceOf: true', ]; $this->assertGraphQL($query, $expectedData);