'How to generate the Apollo sha256 hash?

I need to generate the sha256 string from a graphql query - without Apollo. Assuming my query looks something like:

query Foo {
  bar {
    test
  }
  bar2
}

How to properly format the string to match with the query in the URL? E.g. with/without white spaces, etc.

Ty



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source