Skip to content

Instantly share code, notes, and snippets.

@jasonbahl
Last active October 21, 2021 22:01
Show Gist options
  • Save jasonbahl/6e3037fd8ebde4a7aca703d5e0a29499 to your computer and use it in GitHub Desktop.
Save jasonbahl/6e3037fd8ebde4a7aca703d5e0a29499 to your computer and use it in GitHub Desktop.
const { hooks } = wpGraphiQL;
import LZString from 'lz-string'
hooks.addFilter( 'graphiql_after_graphiql', 'wp-graphiql-extension', (res, props) => {
const encoded = LZString.compressToEncodedURIComponent(props.query)
const decoded = LZString.decompressFromEncodedURIComponent(encoded)
res.push(
<div style={{maxWidth: `200px`}}>
<h2>Encoded</h2>
<pre>{encoded}</pre>
<br/>
<h2>Decoded</h2>
<pre>{decoded}</pre>
</div>
)
return res
})
@jasonbahl
Copy link
Author

This shows how to filter in a panel to GraphiQL to debug the query encoding/decoding

Screen Shot 2021-10-21 at 4 00 11 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment