Евгения Акиншина 3 éve
szülő
commit
a6b9a83388
2 módosított fájl, 120 hozzáadás és 0 törlés
  1. 13 0
      js16-change/index.html
  2. 107 0
      js16-change/js/main.js

+ 13 - 0
js16-change/index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=\, initial-scale=1.0">
+    <link rel="stylesheet" href="css/style.css">
+    <title>HW16</title>
+</head>
+<body>
+    <script src='js/main.js'></script>
+</body>
+</html>

+ 107 - 0
js16-change/js/main.js

@@ -0,0 +1,107 @@
+const getGQL = url => 
+    (query, variables) =>
+        fetch(url , {
+            method: 'POST',
+            headers: {
+                "content-type": "application/json"
+            },
+            body: JSON.stringify({query, variables})
+        }).then(res => res.json())
+
+let gql = getGQL("http://shop-roles.asmer.fs.a-level.com.ua/graphql")
+
+async function categoryById(id) {
+    let query = `query CategoryFind($id:String) {
+        CategoryFind(query:$id) {
+            name goods {
+            name
+            price
+            description
+            images {url}
+            }
+        }
+    }`
+  
+    let variables =  {"id": JSON.stringify([{ "_id": id }])}    //or {"id": "[{\"_id\":\"id\"}]"}
+    
+    let res = await gql(query, variables)
+    console.log(res)
+    return res 
+}
+
+categoryById("5dc458985df9d670df48cc47")
+
+async function goodById(id) {
+    let query = `query GoodFind($id:String) {
+        GoodFind(query:$id) {
+            categories {
+                _id
+                name
+            }
+            name
+            price
+            description
+            createdAt
+            images {url}
+        }
+    }`
+
+    let variables =  {"id": JSON.stringify([{ "_id": id }])}    //or {"id": "[{\"_id\":\"id\"}]"}
+      
+
+    let res = await gql(query, variables)
+    console.log(res)
+    return res 
+}
+
+goodById("5e203b5456d8f720513e6cba")
+
+async function goodFind() {
+    let query = `query GoodFind($q:String) {
+        GoodFind(query:$q) {
+            categories {
+                _id
+                name
+            }
+            _id
+            name
+            price
+            description
+            createdAt
+            images {url}
+            
+        }
+    }`
+  
+    let variables =   {"q": JSON.stringify([{}])}    //or {"q": "[{}]"}
+    
+    let res = await gql(query, variables)
+    console.log(res)
+    return res 
+}
+
+goodFind()
+
+async function categoryFind() {
+    let query = `query CategoryFind($q:String) {
+        CategoryFind(query:$q) {
+            _id
+            name
+            createdAt
+            goods {
+                _id 
+                name 
+                price
+                createdAt
+            }
+        }
+    }`
+  
+    let variables =   {"q": JSON.stringify([{}])}    //or {"q": "[{}]"}
+    
+    let res = await gql(query, variables)
+    console.log(res)
+    return res 
+}
+
+categoryFind()