瀏覽代碼

HW14 done

Alyona Brytvina 2 年之前
父節點
當前提交
6054851ba8
共有 3 個文件被更改,包括 73 次插入0 次删除
  1. 11 0
      HW14/index.html
  2. 62 0
      HW14/main.js
  3. 0 0
      HW14/style.css

+ 11 - 0
HW14/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Title</title>
+    <link rel="stylesheet" href="style.css">
+</head>
+<body>
+<script src="main.js"></script>
+</body>
+</html>

+ 62 - 0
HW14/main.js

@@ -0,0 +1,62 @@
+const gql =  function (url) {
+    console.log(url)
+return async function (query, variables = {}){
+        try {
+            fetch(url, {
+                method: 'POST',
+                headers: {
+                    'Content-Type': 'application/json',
+                },
+                body: JSON.stringify({query, variables}),
+            })
+                .then(response => response.json())
+                .then(({data}) => console.log(data[Object.keys(data)]))
+            return data[Object.keys(data)];
+        }catch (error){
+            console.log(`Проверься ${error}`)
+        }
+}
+}
+
+const url = gql(`http://shop-roles.asmer.fs.a-level.com.ua/graphql`);
+
+(async () => {
+    console.log(await url(`query cats{
+      CategoryFind(query:"[{}]"){
+        name goods{
+          name
+        }
+      }
+    }`))
+})();
+
+// const getGQL = function (url) {
+//     return async function (query, variables) {
+//
+//         try {
+//             fetch(url, {
+//                 method: 'POST',
+//                 headers: {
+//                     'Content-Type': 'application/json'
+//                 },
+//                 body: JSON.stringify({query, variables})
+//
+//             }).then((response) => response.json())
+//                 .then(({data}) => {
+//                     console.log({...data})
+//                     return {...data}
+//                 })
+//         } catch (error) {
+//             alert(error)
+//             }
+//         }
+//     }
+//
+// const gql = getGQL(`http://shop-roles.asmer.fs.a-level.com.ua/graphql`);
+//
+// (async () => {
+//     await gql(` query NameForMe1($login:String, $password:String){
+//         login(login:$login, password:$password)
+//     }`, {login: 'tst', password: '123'});
+// })();
+//

+ 0 - 0
HW14/style.css