question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Empty `type Query {\n}` in the sdl response

See original GitHub issue

I encountered this issue when Apollo-Gateway has trouble recognizing sdl from a graphql service served from federation-jvm. The schema is copied from Apollo-Gateway sample for the inventory service, with a little modification by removing the extend keyword in the front and adding @extends directive:

  type Product @key(fields: "upc") @extends {
    upc: String! @external
    weight: Int @external
    price: Int @external
    shippingEstimate: Int @requires(fields: "price weight")
  }

This schema works well in the NodeJs version of graphql federation. However, with the same schema copied to the side of federation-jvm, Apollo-Gateway stopped to recognize the schema. The following message showed in the Apollo-Gateway log:

Encountered error when loading productsExt at http://localhost:9000/graphql: Syntax Error: Expected Name, found }

Looking at the response body of sdl query from federation-jvm, the @extends was pulled in front of @keyword and there is an empty type Query {\n}.

{
  "data": {
    "_service": {
      "sdl": "type Product @extends @key(fields : \"upc\") {\n  price: Int @external\n  shippingEstimate: Int @requires(fields : \"price weight\")\n  upc: String! @external\n  weight: Int @external\n}\n\ntype Query {\n}\n"
    }
  }
}

The order of the @extends directive seemed to have no negative effect, as verified in by switching the order of @extends and @keyword in the NodeJS graphql federation. The empty type Query {} is probably the cause.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7

github_iconTop GitHub Comments

4reactions
yuhanzcommented, Aug 27, 2019

To work around this issue, you can include the trivial type Query in your schema so that it is not empty, for example:

type Product @key(fields: "upc") @extends {
    upc: String! @external
    inStock: Boolean
    quantity: Int
}

type Query @extends {
    trivial: Product
}
0reactions
sachindshindecommented, Mar 26, 2020

@yuhanz In the meanwhile, we’ve copied their printer and patched it, so if you use federation-jvm v0.3.4 or later you shouldn’t have any issues (note that using v0.3.4 requires upgrading to graphql-java v13).

I’ll close out this issue, but let me know if you still experience similar issues and I can reopen.

Read more comments on GitHub >

github_iconTop Results From Across the Web

GraphQL schema basics - Apollo GraphQL Docs
The Query type is a special object type that defines all of the top-level entry points for queries that clients execute against your...
Read more >
graphqljs - Query root type must be provided - Stack Overflow
I cannot pass null and if I pass an empty GraphQLObjectType it gives me the error: Type Query must define one or more...
Read more >
Resolvers | NestJS - A progressive Node.js framework
Resolvers. Resolvers provide the instructions for turning a GraphQL operation (a query, mutation, or subscription) into data. They return the same shape of ......
Read more >
GraphQL specification
GraphQL. June 2018 Edition. Introduction. This is the specification for GraphQL, a query language and execution engine originally created at Facebook in ...
Read more >
How GraphQL Nexus can help you create better APIs
SDL-first, we can learn more about GraphQL Nexus. ... you can use the t argument to define the type of response of your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found