Skip to content

Unable to add a field with arguments to the Fragment #34

@MurzNN

Description

@MurzNN

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions