Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty types are not allowed in schema language, even if they are later extended #450

Closed
dallonf opened this issue Oct 25, 2017 · 8 comments

Comments

@dallonf
Copy link
Contributor

dallonf commented Oct 25, 2017

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.

@ashconnell
Copy link

related: #293

@dallonf
Copy link
Contributor Author

dallonf commented Nov 6, 2017

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

@dallonf dallonf closed this as completed Nov 6, 2017
@janflyborg
Copy link

It looks like graphql/graphql-js#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

@dallonf
Copy link
Contributor Author

dallonf commented Oct 18, 2018

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

@janflyborg
Copy link

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

@benoj
Copy link

benoj commented Mar 18, 2021

So I know this is an old issue - but when I do @dallonf's solution I get an error "Type Query must define one or more fields."?

@dallonf
Copy link
Contributor Author

dallonf commented Mar 18, 2021

So I know this is an old issue - but when I do @dallonf's solution I get an error "Type Query must define one or more fields."?

@benoj iirc, every type needs to have a field at least somewhere in the schema. So even if you define it as empty, you still need to extend it.

@Jccp1983
Copy link

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.

Repository owner locked as too heated and limited conversation to collaborators Sep 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants