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 type Query {\n} in the sdl response #23

Closed
yuhanz opened this issue Aug 27, 2019 · 7 comments
Closed

Empty type Query {\n} in the sdl response #23

yuhanz opened this issue Aug 27, 2019 · 7 comments

Comments

@yuhanz
Copy link

yuhanz commented Aug 27, 2019

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.

@yuhanz
Copy link
Author

yuhanz commented 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
}

@zionts
Copy link

zionts commented Jan 16, 2020

I believe this should be fixed by 2d7cc26 — can you check you are still having this problem on the latest version?

@yuhanz
Copy link
Author

yuhanz commented Jan 17, 2020

I still observed the issue of Encountered error when loading at ... Syntax Error: Expected Name, found } with a locally built federation-graphql-java-support-0.3.3-SNAPSHOT

@sachindshinde
Copy link
Contributor

Thanks for letting us know, @yuhanz ! We'll look into this issue more, and get back to you by March 9th.

@sachindshinde
Copy link
Contributor

@yuhanz
So we've determined the cause of the issue.

It turns out there's a bug in graphql-java's SchemaPrinter in which it will use empty braces for object type definitions with no members (it also happens for interfaces, enums, and input objects). This violates the GraphQL grammar as per spec, and it should instead be using no braces at all. That is,

type Query {
}

should really be

type Query

This is why Apollo Gateway is giving you the error Syntax Error: Expected Name, found }; it uses graphql.js to parse, which fails because of the invalid grammar. The good news is that someone's already pushed a fix to graphql-java at graphql-java/graphql-java#1798 .

@yuhanz
Copy link
Author

yuhanz commented Mar 19, 2020

Great to know. Thanks for keep tracking. Looking forward to see a new build of graphql-java.

@sachindshinde
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants