Daniel15 / urql-persisted-queries

urql exchange that implements Apollo-style Automatic Persisted Queries
https://d.sb/urql-pq
MIT License
27 stars 3 forks source link

Add server hashing for isomorphic environments #5

Open lorenries opened 4 years ago

lorenries commented 4 years ago

This is a wonderful urql exchange but unfortunately can't create persisted queries in server environments like Next.js because it relies on the web crypto api.

This PR checks if typeof window === "undefined", and if it is, hashes queries with node's crypto module.

lorenries commented 4 years ago

Ah, yeah, it bundles properly in Next.js (which is smart enough to strip out conditionals in if typeof window === undefined from client bundles, but not in webpack or parcel.

Would you be open to using something like hash.js, which will work on the client and the server? That's what apollo-link-persisted-queries uses. Or alternatively isomorphic-webcrypto.

kitten commented 4 years ago

@Daniel15 Hiya 👋 we actually found some time to implement persisted queries in our main repo. The reason it’s been built from scratch is to test out more reuse of our core fetching logic (since it always ends up being very similar) including some newer debugging events for our new upcoming devtools timeline.

It should be IE11 ready and the SHA256 shim for Node.js should minors away in web environments, with the proper Webpack config. https://github.com/FormidableLabs/urql/tree/master/exchanges/persisted-fetch/src

Daniel15 commented 4 years ago

Thanks @kitten - Sounds like I should archive this repo then :)