markhuot / craftql

A drop-in GraphQL server for Craft CMS
Other
320 stars 53 forks source link

Is graphql sending JSON? #315

Closed Jones-S closed 5 years ago

Jones-S commented 5 years ago

I know that this maybe related to some other stuff than craftql, but I just have to ask, because I don't know what else I can do to resolve my issue:

I am using an apollo client to fetch from a craftql service. If I fetch from localhost:3000 to a local backend domain with my craft installation. This works perfectly fine. I get a json response and it works.

If I know want to do the same on the remote (I had to resolve CORS and authorization issues first), I am also getting a response (actually the exact same), but I get an error

"Network error: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data"

But I do already get JSON!

Screenshot 2019-09-09 at 15 47 09

As it is exactly the same response on my local /api and from my remote /api, I was wondering if there could be any server issues that cloak my json as something else, or if a server setting somehow would make my apollo not realizing that I actually get json.

I know this sounds desperate, but I have no idea what could be the reason. I also posted this question within the nuxt/module comunity: https://cmty.app/nuxt/apollo-module/issues/c236

Where I go into more detail about the apollo settings...

If there is anybody with an idea... please send me a hint

Jones-S commented 5 years ago

I also realized that I have slightly different headers (response and request) for the local call which works and the remote call which fails:

WORKS:

Screenshot 2019-09-09 at 16 52 01

you can also see that the Bearer token is sent within the header, and the other time it is not... But still it would get authorized, so that may not be the problem...


FAILS with JSON parse error:

Screenshot 2019-09-09 at 17 01 41
Jones-S commented 5 years ago

This one is actually also resolved. I was totally confused, because I actually had CORS issue (https://github.com/markhuot/craftql/issues/316) but I could disable those cors messages by using no-cors in my apollo client. Somehow this would make the response appear in the Network tab but would never reach my application.

Very weird and very mysterious error messages or rather the total lack of them caused me waisting hours and hours.

Well, it is finally resolved.