Skip to content
This repository was archived by the owner on Feb 10, 2019. It is now read-only.
This repository was archived by the owner on Feb 10, 2019. It is now read-only.

Merging schema instead of replacing in GraphQL::addShema() #151

@Phirames

Description

@Phirames

First, I want to thank you for your amazing work!

My problem is that I can't add schema in multiple places in my code. I use module app architecture (using this package ) where every module has its own service provider. When I use GraphQL::addShema('default', $schema) in my modules service providers the schema is replaced by the last invocation in module service provider which was invoked last.
What I want is GraphQL to have a method which merges schema instead of replace it.

Here is my workaround for those who faced this problem as well
I created my own GraphQL service provider and registered my own GraphQL singleton which has desired mergeSchemas method

namespace App\GraphQL;

use Folklore\GraphQL\Events\SchemaAdded;

class GraphQL extends \Folklore\GraphQL\GraphQL
{
    public function addSchema($name, $schema)
    {
        $this->mergeSchemas($name, $schema);

        event(new SchemaAdded($schema, $name));
    }

    private function mergeSchemas($name, $schema) {

        if (isset($this->schemas[$name]) && $this->schemas[$name]) {

            $this->schemas[$name] = array_merge_recursive($this->schemas[$name], $schema);
        } else {

            $this->schemas[$name] = $schema;
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions