-
-
Notifications
You must be signed in to change notification settings - Fork 268
Closed
Labels
Description
Consider making GraphQL type macroable
In my tests I often need to check whether a field exists on the GraphQL type declaration
For example:
use App\GraphQL\Types\UserType;
public function test_that_company_id_attribute_is_included_on_type()
{
$this->assertTrue($this->hasField('company_id', User::class));
}
protected function hasField($attribute, $graphQLType) {
$query = app($graphQLType);
if (!method_exists($query, 'fields')) {
return false;
}
return array_key_exists($attribute, $query->fields());
}
In this example, I would like to be able to add the hasField method onto the Type using a Laravel Service Provider when the application boots up. If I could extend the class to include my own methods I could simply do the following in my test:
public function test_that_company_id_attribute_is_included_on_type()
{
$this->assertTrue(app(User::class)->hasField('company_id));
}