graphql-java-tools icon indicating copy to clipboard operation
graphql-java-tools copied to clipboard

Bad GET request: path was not "/schema.json" or no query variable named "query" given

Open mluis opened this issue 6 years ago • 11 comments

I'm getting:

Bad GET request: path was not "/schema.json" or no query variable named "query" given

while using:

curl -k -H "Content-Type: application/json" -H "Authorization: Bearer <token here>" -X POST -d '{ "operationName": null, "query": "subscription values($sensorId: String) {\n values(sensorId: $sensorId) {\n  sensor\n  value\n  timestamp\n  __typename\n }\n}\n", "variables": {"sensorId": 33} }' http://localhost:9999/graphql

What's happening? How can one solve this?

EDIT: I don't know if this can help but this happens also in Mutations and Queries since I use

DataFetcher<Flowable<TYPE>>

mluis avatar Mar 26 '20 10:03 mluis

Can you use triple ticks next time for better readability? :)

Looks like you're sending a subscription to the /graphql endpoint. Take a look at the subsription example and start from there.

oliemansm avatar Mar 31 '20 07:03 oliemansm

Hi @oliemansm , thanks for your response. Is there any issue sending subscriptions to the /graphql endpoint? I have successfully tested locally and it works well with HTTP chunked responses.

mluis avatar Mar 31 '20 09:03 mluis

You say you use DataFetcher. How are you using this? The information is rather limited to be able to say anything sensible here. Why do you think this is even an issue with graphql-java-tools? There are multiple working examples in the graphql-spring-boot project. I'd start with one of those working examples if I were you and move towards the solution you have in mind.

oliemansm avatar Mar 31 '20 10:03 oliemansm

I had the same problem due to a cast exception in my error handling, the error simply being that fetching the schema broke our max query depth complexity. I suggest adding a custom log level of debug for graphql.kickstart to see what's actually causing this

mpires avatar Aug 18 '20 15:08 mpires

Closed for inactivity.

vojtapol avatar Sep 02 '20 16:09 vojtapol

I don't know how nobody resolved this issue yet. I see a lot of people using Graphql and having the same problem e.g. " Bad GET request: path was not "/schema.json" or no query variable named "query" given " In Graphql, the biggest problem is logging. I don't know the purpose of the log if you are not able to provide a proper error message? e.g. I was getting this error, and I dive deep into debugging (class HttpRequestHandlerImpl) and I found out that the problem was the field that was removed. So, why would it be so hard to print the log which is already provided in such a deep debugging state?

jaggaer-npasic avatar Jun 22 '21 10:06 jaggaer-npasic

any one plz tell me clear Solution?

deivendran2010 avatar Dec 20 '21 09:12 deivendran2010

any one plz tell me clear Solution?

Make sure your schema file and Dto object have the same variables, with the same naming. If the problem persists, usually, project rebuild helps. Especially if you are using Lombok and Mapstruct. In 99% of the cases, Lombok makes a problem. If there is still a problem, then, I suggest debugging. Line by line. Ironically, GraphQL, in-depth has a proper error, with a very good description, but, then, they are converting that error into mentioned stupid error. I don't know why they are doing that, but they do.

For example, I had the same error, and I did a debug, line by line, and in-deep, I saw that the actual error is, Field xxx not defined in the schema, or Method xxx not found, or something like that.. As you see, an error is a proper one. But it's converted to a stupid general error message.

jaggaer-npasic avatar Dec 20 '21 13:12 jaggaer-npasic

hey, how do we debug graphql line by line? any tutorial to setup that debugging???

Harmanat avatar Jul 20 '22 14:07 Harmanat

any tutorial to setup that debugging

You have to debug your own code. When an exception is thrown, open that line and resend the request until you find the point when an exception occurs. This is very hard to do, especially, because it's not needed at all. I still don't understand why somebody would hide a perfectly valid message that explains the problem with a general message that tells you nothing...

jaggaer-npasic avatar Jul 28 '22 06:07 jaggaer-npasic

Hi, It is not about dtos or something else. Graphql simply returns empty response in any case. I fixed this problem by Downgrading the federation-graphql-java-support dependency to 0.5.0 worked fine for me.

<dependency> <groupId>com.apollographql.federation</groupId> <artifactId>federation-graphql-java-support</artifactId> <version>0.5.0</version> </dependency>

Note: You need to add jcenter repository to your pom.xml

<repository> <id>jcenter</id> <name>jcenter</name> <url>https://jcenter.bintray.com</url> </repository>

nurlanmemmedov avatar Feb 12 '23 19:02 nurlanmemmedov