Graphql-tools: Empty types are not allowed in schema language, even if they are later extended

Created on 25 Oct 2017  路  5Comments  路  Source: ardatan/graphql-tools

I just discovered this extend feature, which is super cool! My Query type had gotten massive and bloated and this looks like the perfect tool to break all of its fields out into many files.

The problem: now I don't want _anything_ in the base Query definition, since every field that used to be there now feels more at home in another file. But if I have a definition that looks like this (obviously heavily simplified from my use case):

  type Query {}

  extend type Query {
    hello: String
  }

(Launchpad version: https://launchpad.graphql.com/13v9kk4n9)

I get the error: "Query fields must be an object with field names as keys or a function which returns such an object."

I would expect that an empty type would be OK if (and only if) there was another type somewhere in the schema that extended it.

As a workaround, I'm currently putting a dummy field in the root Query type.

Most helpful comment

@janflyborg This already works in the current version of graphql-tools! The syntax is type Query rather than type Query {}.

All 5 comments

Thanks for the link. Looks like this is a graphql-js concern (https://github.com/graphql/graphql-js/issues/937), so I'll close this issue.

It looks like https://github.com/graphql/graphql-js/issues/937 solved this in December 2017, so I think you should revisit this again. It is quite cumbersome to have to define dummy members just to support type weaving in large schemas that are splitted over several files

@janflyborg This already works in the current version of graphql-tools! The syntax is type Query rather than type Query {}.

@dallonf I didn't know that. Thanks for the help, I'll try that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

adamkl picture adamkl  路  3Comments

benjaminhon picture benjaminhon  路  3Comments

proehlen picture proehlen  路  4Comments

alfaproject picture alfaproject  路  4Comments

flippidippi picture flippidippi  路  3Comments