Skip to content

Instantly share code, notes, and snippets.

@asoltys
Created May 26, 2022 18:01
Show Gist options
  • Save asoltys/b8ab356242011709e232b7762efe59cb to your computer and use it in GitHub Desktop.
Save asoltys/b8ab356242011709e232b7762efe59cb to your computer and use it in GitHub Desktop.
import wretch from "wretch";
import fetch from "node-fetch";
wretch().polyfills({ fetch });
const hasura = wretch().url(`http://localhost:8080/v1/graphql`).headers({
"x-hasura-admin-secret": "liquidart"
});
const q = async (query, variables) => {
let { data, errors } = await hasura.post({ query, variables }).json();
if (errors) {
for (let index = 0; index < errors.length; index++) {
const element = errors[index];
}
throw new Error(errors[0].message);
}
return data;
}
let { users } = await q("query($id: uuid!) { users(where: { id: { _eq: $id }}) { id, username, display_name }}", { id: "c77831a5-bfa6-4279-9556-0e113cf023ad" });
let user = users[0];
if (user.username.includes('Deg3n')) console.log("PASS");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment