Skip to content

Instantly share code, notes, and snippets.

@Shadid12
Created November 27, 2022 20:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shadid12/b63bce754a0bf70611c38f0c13f7516b to your computer and use it in GitHub Desktop.
Save Shadid12/b63bce754a0bf70611c38f0c13f7516b to your computer and use it in GitHub Desktop.
export default class Client {
constructor(key) {
this.key = key;
this.url = `https://us-dev.db.faunadb.net/query/1`;
}
_getKey() {
return this.key;
}
_getUrl() {
return this.url;
}
async query(fql_expression) {
if (!this.key) {
return "Please provide a valid key";
}
return fetch(this.url, {
headers: {
accept: "application/json, text/plain, */*",
authorization: `Bearer ${this.key}`
},
body: JSON.stringify({
query: fql_expression,
arguments: {},
typecheck: true
}),
method: "POST",
mode: "cors",
credentials: "include"
})
.then((res) => res.json())
.then((data) => data.data)
.catch((e) => console.log("ERROR", e));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment