Joystream / orion

Atlas backend
GNU General Public License v3.0
7 stars 15 forks source link

Adding `Automatic persisted queries` feature to Atlas/Orion #279

Open zeeshanakram3 opened 9 months ago

zeeshanakram3 commented 9 months ago

This issue proposes adding Automatic persisted queries (APQs) feature to Atlas/Orion to improve network performance by sending smaller requests

Problem it addresses

In practice we've seen GraphQL query sizes ranging well above 10 KB just for the query text. This is significant overhead when compared with a simple URL of 50-100 characters. Clients send queries to Apollo Server as HTTP requests that include the GraphQL string of the query to execute. Depending on your graph's schema, the size of a valid query string might be arbitrarily large. As query strings become larger, increased latency and network usage can noticeably degrade client performance.

For example GetChannelPaymentEvents query which is being used in the My Payments page is over 4KB in length, so by using APQs we could just reduce the request size to constant few hundred bytes.

How it works

A persisted query is a query string that's cached on the server side, along with its unique identifier (always its SHA-256 hash). Clients can send this identifier instead of the corresponding query string, thus reducing request sizes To persist a query string, Apollo Server must first receive it from a requesting client. Consequently, each unique query string must be sent to Apollo Server at least once

Changes required

Orion

No changes are required in Orion's graphql server, as Apollo Server supports APQ without any additional configuration.

Atlas

Reference

https://www.apollographql.com/docs/apollo-server/performance/apq/