Created
November 27, 2022 20:43
-
-
Save Shadid12/b63bce754a0bf70611c38f0c13f7516b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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