graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Unable to add a field with arguments to the Fragment

Open MurzNN opened this issue 1 year ago • 0 comments

I need to insert a field with arguments to a Fragment, to have something like this:

fragment hero on Hero {
  name
  friends
}

So, here is the code to do this:

$hero = new \GraphQL\Entities\Fragment('hero', 'Hero');
$hero->use('name');
$hero->friends(['first'=>2])->use('name');

echo $hero->toString();

But it throws an error:

PHP Fatal error:  Uncaught GraphQL\Exceptions\InvalidMethodException: Invalid method friends in /var/www/html/vendor/graphql/src/Entities/Fragment.php:50
Stack trace:
#0 /var/www/html/vendor/graphql/src/tests.php(12): GraphQL\Entities\Fragment->__call('friends', Array)
#1 {main}
  thrown in /var/www/html/vendor/graphql/src/Entities/Fragment.php on line 50

Fatal error: Uncaught GraphQL\Exceptions\InvalidMethodException: Invalid method friends in /var/www/html/vendor/graphql/src/Entities/Fragment.php on line 50

GraphQL\Exceptions\InvalidMethodException: Invalid method friends in /var/www/html/vendor/graphql/src/Entities/Fragment.php on line 50

Call Stack:
    0.0007     492664   1. {main}() /var/www/html/vendor/graphql/src/tests.php:0
    0.0104     715344   2. GraphQL\Entities\Fragment->__call($method = 'friends', $arguments = [0 => ['first' => 2]]) /var/www/html/vendor/graphql/src/tests.php:12

So, if this possible, what is the correct usage to add a field with arguments?

MurzNN avatar Aug 06 '24 13:08 MurzNN