Browse Source

HW<15> done

Levshin95 1 year ago
parent
commit
6dfb2b3d2a
2 changed files with 67 additions and 0 deletions
  1. 12 0
      HW015/index.html
  2. 55 0
      HW015/index.js

+ 12 - 0
HW015/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script src="index.js"></script>
+</body>
+</html>

+ 55 - 0
HW015/index.js

@@ -0,0 +1,55 @@
+let gql = (url, query, variables={}) =>
+    fetch(url, {
+        method: 'POST',
+        headers:{
+            Accept: 'application/json',
+            "Content-Type": 'application/json'
+        },
+        body: JSON.stringify({query, variables})
+    }).then(res => res.json())
+
+const graphiQL = "http://shop-roles.node.ed.asmer.org.ua/graphql";
+
+let log = (login, password) =>
+    gql(graphiQL,
+        `query login($login:String, $password:String){
+	    login(login:$login, password:$password)
+    }`, {login, password})
+
+let register = (login, password) =>
+    gql(graphiQL,
+        `mutation register($login:String, $password:String){
+            UserUpsert(user:{login:$login, password:$password}){
+            _id login createdAt
+        }
+    }`, {login, password})
+
+let category = () =>
+    gql(graphiQL, 
+        `query category {
+        CategoryFind(query: "[{}]"){
+            _id, name
+        }
+    }`)
+
+let catById = () => 
+    gql(graphiQL,
+        `query catById {
+        CategoryFind(query: "[{}]"){
+              _id name goods  {
+              _id
+              name
+              price
+              description 
+              price
+            }
+          }
+      }`)
+      
+
+(async function gqlResult() {
+    console.log(await register("levshin95", "123123"))
+    console.log(await log("levshin95", "123123"));
+    console.log(await category());
+    console.log(await catById());
+})();