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

Federation sometimes returns empty json with graphql-java #3153

Closed
pepijno opened this issue Aug 13, 2019 · 2 comments · Fixed by #3213
Closed

Federation sometimes returns empty json with graphql-java #3153

pepijno opened this issue Aug 13, 2019 · 2 comments · Fixed by #3213

Comments

@pepijno
Copy link

pepijno commented Aug 13, 2019

Hi,

Thanks for the awesome work and projects!

I discovered a peculiar bug but it is a bit difficult to describe, so here goes.
On a query, the graphql-java library parses the data in the variables field of the input (I think using Jackson) to the correct values. For example, given the following schema

type Query {
  bookByPageCount(pageCount: Int!): Book
}

type Book {
  id: ID
  name: String
  pageCount: Int
}

and the following query data

{  
   "query": "query getBook($pageCount: Int!) { bookByPageCount(pageCount: $pageCount) { id name pageCount } }",
   "variables": {  
      "pageCount": "223"
   },
   "operationName": null
}

the string "223" is parsed to an Integer by java since pageCount needs to be an Int according to the schema.
When we add a apollo federation service (using apollo-server version 2.8.1 and @apollo/gateway version 0.8.2) on top of a java service serving the above schema

const gateway = new ApolloGateway({
	serviceList: [
		{ name: "books", url: `server-endpoint` },
	]
});

(async () => {
	const { schema, executor } = await gateway.load();

	const server = new ApolloServer({ schema, executor });

	server.listen().then(({ url }) => {
		console.log(`Server ready at ${url}`);
	});
})();

and we send the same query as mentioned earlier but now to the apollo federation service we get the response

{}

while the java service does return the correct response.
I have created a simple sample project which shows this issue: https://github.com/pepijno/apollo-federation-variables-bug

What I would expect to happen instead of returning an empty json is either one of two things:

  1. The federation service also returns the same data as the java service
  2. The federation service returns an error telling that the variables are not according to the schema

I hope I have outlined the issue clearly. It might be that this issue is unexpected behaviour in the graphql-java library in which case I will issue a bug for that library.

@trevor-scheer
Copy link
Member

Thanks for bringing this to our attention @pepijno (and the wonderful reproduction!).

ApolloServer's behavior is to respond with an error about incorrect variable types (as opposed to coercion, as you mentioned Java does). It appears that gateway doesn't return that error the way that ApolloServer does, which is something that we should fix!

@pepijno
Copy link
Author

pepijno commented Aug 30, 2019

Thanks for solving!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants