Skip to content

Merging schemas #500

@MidnightDesign

Description

@MidnightDesign

Our project is separated by domain into multiple Composer packages, like acme/user and acme/event. We want to build a GraphQL API now and have the code be split into multiple packages like acme/user-graphql and acme/event-graphql. How would you recommend doing that?

Right now, we have a schema.graphql and resolvers.config.php in each package:

schema.graphql:

type Query {
    user(id: ID!): User
}
type User {
    # ...
}

resolvers.config.php:

<?php

return [
    'Query' => [
        'user' => QueryUser::class
    ]
];

We then want to combine the schemas into a single monolithic one. I thought we could do that by just concatenating the contents of the schema files, but then I get the error that there are multiple definitions of Query because every one of the packages tries to add something to the Query. I've also tried using the SchemaExtender but I get the same error.

The next thing I tried was using extend type Query but then I get the error Schema does not define the required query root type..

I would really appreciate it if you could point me in the right direction with this.

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