mghoneimy/php-graphql-client

GET requests not working

oneserv-heuser opened this issue · 6 comments

I added the possibilty to make a GET request (#39). But now I saw that i completly fucked it up. I'm so sorry for that.

GET requests cannot work as the query itself is never attached to the uri which has to happen of course if you want to make a GET request. If you try to execute a GET request at the moment you'll reveice the error GraphQL Request must include at least one of those two parameters: "query" or "queryId".

The solution would be to add the query and it's variables to the request url, here. I already tried it locally but I'm to incompetent to make it work.

Again, sorry for fucking this thing up so hard.

So there are a few things we need to do now:

  1. Research how query parameters and variables are formatted in the query string in GET requests:
    This library converts the query objects into JSON-like format used by GraphQL in POST request body. Because query URL parameters are formatted differently, we will need to reformat the generated body by the query objects into the query parameters format.
  2. Fix the issue:
    We need convert the query generated here into the format used in URL query parameters, and then set it in the URL as you said in there.
  3. Add tests that expose all new logic
    We need to add tests for the query string conversion and an end-to-end tests that shows the GET request with query URL parameters set in the new format.

Let me know how soon you can look into creating a pull request with these changes.

@mghoneimy I don't know when I'm able to do so as it's very stressful at work at the moment. I'll try it as soon as I can.

@mghoneimy Just started working on this. I've got a problem which I need input for.

When preparing the query for the GET request there is a problem with "\n". "\n" is all over the place and when appending the queryString to the url and passing this to the PSR7 Request object the method "parse_url" gets called which converts this to underscores (https://stackoverflow.com/a/283781/6137257). So for example instead of requesting the field "product" you'd request "_product" which of course doesn't work.

But I cannot just replace all "\n" with spaces or nothing as the "\n" are important for selections. For example:
"field1\nfield2" works but replacing "\n" would result in "field1field2" which doesn't work.

You've got any idea?

Can you please provide with a link to a GraphQL server that receives responses in GET requests?

For the time being, users were prevented form being able to use any request type other than "POST" with release 1.9.2
https://github.com/mghoneimy/php-graphql-client/releases/tag/v1.9.2

Let's work on a pull request to enable GET requests in the mean time

@mghoneimy No, unfortunately I cannot provide a link as our API we're using this package for is under development and internal.

Well, what are your thoughts on the issue I described before?