|
@@ -0,0 +1,60 @@
|
|
|
+let getGQL = function(url) {
|
|
|
+ return async function(data) {
|
|
|
+ let res = await fetch(url, {
|
|
|
+ method: "POST",
|
|
|
+ headers: {
|
|
|
+ "content-type": "application/json"
|
|
|
+ },
|
|
|
+ body: JSON.stringify(data)
|
|
|
+ });
|
|
|
+
|
|
|
+ return res.json();
|
|
|
+ };
|
|
|
+};
|
|
|
+
|
|
|
+let gql = getGQL("http://shop-roles.asmer.fs.a-level.com.ua/graphql");
|
|
|
+
|
|
|
+let login = async function(login, password) {
|
|
|
+ let data = {
|
|
|
+ query: "query log($login: String, $password: String) {login(login: $login, password: $password)}",
|
|
|
+ variables: {
|
|
|
+ login: login,
|
|
|
+ password: password
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ let res = await gql(data);
|
|
|
+ let token = res["data"]["login"];
|
|
|
+
|
|
|
+ return token;
|
|
|
+};
|
|
|
+
|
|
|
+let catByID = async function(id) {
|
|
|
+ let data = {
|
|
|
+ query: "query cat($query: String) {CategoryFindOne(query: $query) {_id name image {url}}}",
|
|
|
+ variables: {
|
|
|
+ query: JSON.stringify([{"_id": id}])
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ let res = await gql(data);
|
|
|
+
|
|
|
+ return res;
|
|
|
+};
|
|
|
+
|
|
|
+let goodByID = async function(id) {
|
|
|
+ let data = {
|
|
|
+ query: "query findGood($goodQuery: String) {GoodFindOne(query:$goodQuery) {_id name}}",
|
|
|
+ variables: {
|
|
|
+ goodQuery: JSON.stringify([{"_id": id}])
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ let res = await gql(data);
|
|
|
+
|
|
|
+ return res;
|
|
|
+};
|
|
|
+
|
|
|
+login("user789", "123123");
|
|
|
+catByID("5dc49f4d5df9d670df48cc64");
|
|
|
+goodByID("5dcad32b6d09c45440d14d0f");
|