ohler55 / agoo

A High Performance HTTP Server for Ruby
MIT License
908 stars 39 forks source link

Fragment usage #101

Closed alexander-r-jaimy closed 3 years ago

alexander-r-jaimy commented 3 years ago

Good morning, I'd like to know of a valid example of using fragments.

When I try this it doesn't work: Screenshot from 2021-05-21 11-23-39

even though this work perfectly fine: Screenshot from 2021-05-21 11-23-49

ohler55 commented 3 years ago

Fragments are supported. There is a test in test/graphql_test.rb named test_post_fragment.

I can look into why you example doesn't work though. It might take a couple of days before I can get to it though.

ohler55 commented 3 years ago

Started looking at this today. I am not able to reproduce the issue so I suspect there is something different about the request. Can you tell me what the HTTP POST request looks like or what the content type of the request is? Is it application/graphql?

alexander-r-jaimy commented 3 years ago

Good afternoon,

We are working to provide you a reproducible example. Meanwhile, this is the request that we are sending:

Request URL: http://localhost:6464/phrases Request Method: POST Status Code: 200 OK Remote Address: 127.0.0.1:6464 Referrer Policy: strict-origin-when-cross-origin accept: application/json, multipart/mixed Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 Connection: keep-alive Content-Length: 269\n content-type: application/json Host: localhost:6464 Origin: http://localhost:6464 Referer: http://localhost:6464/iql.html Sec-Fetch-Dest: empty Sec-Fetch-Mode: cors Sec-Fetch-Site: same-origin Sec-GPC: 1 User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36 {"query":"\nfragment Phrase on Phrase {\n code\n usages\n starting_english_phrase\n is_system\n rank\n}\n\nquery getPhrases($filters: PhrasesInput) {\n phrases(filters: $filters) {\n ...Phrase\n }\n}\n","variables":{"filters":{}},"operationName":"getPhrases"}

and this is the response that comes:

{"data":{"phrases":[{},{},{},{},{},{}]}}

I checked the test that you mention, on the example with fragments you are using application/json, but in any cases we tried with application/graphql and it doesn't really help.

I'm attaching some postman requests to demonstrate the issue: Screenshot from 2021-05-31 11-26-10 A valid graphql call Screenshot from 2021-05-31 11-27-03 Same but with fragment instead Screenshot from 2021-05-31 11-27-24

ohler55 commented 3 years ago

That helps. I'll try testing with JSON instead of GraphQL content.

ohler55 commented 3 years ago

That helped a lot although I would have expected to see an error on the fragment calls. There is a bug in the JSON parser which I will fix. Please try the json-parser-fix branch.

alexander-r-jaimy commented 3 years ago

Thank you for your time for having a look on this issue.

Regarding content-type: application/graphql, I think there's another bug to it: The first image with "name not provided" "parse error" is the outcome of trying to send a request with application/graphql.

And secondly, when I try to introspect the schema with this library graphqurl and execute the following command gq <url> --introspect > schema.json it fails with unsupported content type.

Noticeably, if I modify the command to export json rather than schema, it works, but then again I have to explicitly indicate the content-type: gq <url> -H 'content-type: application/json' --introspect --format json > schema.json

ohler55 commented 3 years ago

I'm not familiar with the gq tool so I'm not sure what the --introspect does but I will check it out and run some tests to get it all working.

I can't tell from the first image what the content was of the call. With that I could probably figure out what is going on.

alexander-r-jaimy commented 3 years ago

ah, the content was the same as on other images, with or without fragment usage the error will be the same.

--introspect basically runs an IntrospectionQuery that downloads a schema.

ohler55 commented 3 years ago

I assume you mean the the same but in graphql format and not JSON, right?

alexander-r-jaimy commented 3 years ago

yes indeed. it should download a SDL schema, instead of JSON

ohler55 commented 3 years ago

To nights homework for me will be to try out gq and see what is sent.

alexander-r-jaimy commented 3 years ago

The following command: gq https://graphqlzero.almansi.me/api --introspect > schema.graphql downloads a schema. This is useful for generating typescript types to use in frontend frameworks - more automation

and then this schema is feed to graphql-codegen that will generate the types we need

ohler55 commented 3 years ago

BTW, with Agoo you can also download the schema with http://localhost:3000/graphql/schema if the GraphQL endpoint is http://localhost:3000/graphql.

Can graphql-codegen be configured to generate ruby code as well?

ohler55 commented 3 years ago

The reason for the error in the first block is that just changing the header with gq does not change the content. The content is still JSON but the header claims to be graphql so Agoo attempts to parse as graphql and fails. Digging in to more but want to give you some preliminary feedback.

I'll have to try something else beside gq for introspect. Agoo is returning the expected result but gq is refusing to read it for some reason. I'll try curl with the same query and see what happens but that will be tomorrow.

ohler55 commented 3 years ago

I haven't been able to reproduce the gq introspect issue. Curl works fine with the same query as does graphiql. I did uncover another issue with graphiql. A comment only request caused a crash which has been fixed. Just refresh the branch.

ohler55 commented 3 years ago

I plan on releasing these changes if I don't hear back from you by tomorrow.

ohler55 commented 3 years ago

Released and closing.