Skip to content

Proposal: "and" (or product) types. #247

Closed
@AndrewIngram

Description

@AndrewIngram

When building large schemas using the schema language patterns, it's relatively awkward to build the mutation type. My definitions are spread across a large number of files, and I typically want my mutations to be defined alongside the types they are most related to.

We're restricted to having a single Mutation type, with no namespacing, that has to hold all the mutations for the entire schema, this makes it relatively awkward to define mutations in a modular way without resorting to some trickery.

I'm proposing something like this:

type User {
  id: ID!
  username: String
}

type UserMutation {
  createUser(username: String!): User
  updateUser(id: ID!, username: String!): User
}

type Article {
    id: ID!
    author: User!
    title: String!
    body: String!
}

type ArticleMutation {
  createArticle(authorId: ID!, title: String!, body: String!): Article
  updateUser(id: ID!, authorId: ID, title: String, body: String): Article
}

type Mutation = UserMutation & ArticleMutation

Aside from the syntactic sugar provided by the last line, this is something I already do as a post-processing step after generating my schema. But i'd prefer to do away with the hack entirely and have a solution that feels more standardised.

The basic spec would be that an and type combines all the fields of the types being added, and errors on a collision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions