warrenday / graphql-network-inspector

A better network inspector for viewing and debugging GraphQL requests.
MIT License
466 stars 46 forks source link

Support persisted queries for POST requests #93

Closed PhilippeChab closed 1 year ago

PhilippeChab commented 1 year ago

Description

Thanks to this commit, the extension now supports GET persisted queries. While GET requests allow the browser to use HTTP caching, persisted queries can also be made with POST requests.

This PR adds the support to persisted queries made with POST requests.

Screenshot

CleanShot 2023-03-14 at 12 01 24@2x

Checklist

Closes https://github.com/warrenday/graphql-network-inspector/issues/71

Odonno commented 1 year ago

Oh, good catch. Indeed, we can detect persisted queries for POST requests, although this is not the primary use case.

However, I am not really a fan of this "unknown" thing. You're right in the sense that we don't know what kind of operation we're doing, but persisted query is mainly for queries. Queries do not change often, but mutations do. That's why mutations are not good candidates for persisted queries. I would vote to assume that a persisted query (GET or POST) should be treated as a query.

PhilippeChab commented 1 year ago

... but persisted query is mainly for queries. Queries do not change often, but mutations do. That's why mutations are not good candidates for persisted queries.

This is not true. :) Persisted queries are equally as useful for queries as for mutations. The goal of a persisted query is purely to reduce the request's size, whether it is a POST or a GET doesn't matter.

Executing a GraphQL request as a GET is an other optimization to exploit HTTP caching, something that cannot be done when performing a POST.

That being said, I agree that Unknowns is not ideal UX wise. Persisted POSTs, maybe? I'm open to any suggestion. :)

Links:

Odonno commented 1 year ago

Well, I may not have made myself clear earlier. I know how Persisted Query works, but what I was trying to say is that using it for mutation is not really effective. You will almost always hit the "miss" cache because a mutation often changes. In this case, I meant that using Persisted Query for mutation should not be used by many people. And so I would opt to assume that a PQ is (almost) always for queries.

Otherwise, we could go for "Persisted" like you suggest. They are not readable in general so it could be better in term of UX (knowing which are readable and which are not).

PhilippeChab commented 1 year ago

Let's go with persisted!

Odonno commented 1 year ago

Looks good to me.

warrenday commented 1 year ago

Looks great! Thanks @PhilippeChab