Skip to content

Consider making GraphQL types macroable #518

@paulomunky1

Description

@paulomunky1

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));
}

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions