startgg-helper-browser 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.js +45 -0
- package/package.json +27 -0
package/main.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Query } from "startgg-helper";
|
|
2
|
+
export * from "startgg-helper"
|
|
3
|
+
|
|
4
|
+
export async function loadQuery(url, maxTries = null){
|
|
5
|
+
try {
|
|
6
|
+
let schema = await fetch(url)
|
|
7
|
+
.then(res => res.text())
|
|
8
|
+
return new Query(schema, maxTries);
|
|
9
|
+
} catch (err){
|
|
10
|
+
throw new Error("Failed to load query from GraphQL file. Reason : " + err);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function requestStartGG(schema, variables, token){
|
|
15
|
+
return fetch('https://api.start.gg/gql/alpha', {
|
|
16
|
+
method: 'POST',
|
|
17
|
+
headers: {
|
|
18
|
+
'Content-Type': 'application/json',
|
|
19
|
+
'accept' : 'application/json',
|
|
20
|
+
'Authorization' : token
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify({
|
|
23
|
+
'query': schema,
|
|
24
|
+
'variables' : variables
|
|
25
|
+
}),
|
|
26
|
+
|
|
27
|
+
})
|
|
28
|
+
.then((response) => response.json())
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export class SGGHelperClient {
|
|
32
|
+
#token;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param {string} token
|
|
37
|
+
*/
|
|
38
|
+
constructor(token){
|
|
39
|
+
this.#token = token;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
request(schema, variables){
|
|
43
|
+
return requestStartGG(schema, variables, this.#token);
|
|
44
|
+
}
|
|
45
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "startgg-helper-browser",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A set of functions and classes useful to communicate with the start.gg API from a web app",
|
|
5
|
+
"main": "main.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://gitlab.com/TwilCynder/startgg-helper.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"GraphQL",
|
|
15
|
+
"start.gg",
|
|
16
|
+
"API"
|
|
17
|
+
],
|
|
18
|
+
"author": "TwilCynder",
|
|
19
|
+
"license": "ISC",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://gitlab.com/TwilCynder/startgg-helper/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://gitlab.com/TwilCynder/startgg-helper#readme",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"startgg-helper": "^1.0.2"
|
|
26
|
+
}
|
|
27
|
+
}
|