index.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <script>
  9. /*const originalFetch = fetch;
  10. fetch = (url, params={headers:{}}) => {
  11. params.headers.Authorization = "Bearer " + localStorage.authToken
  12. return originalFetch(url, params)
  13. }*/
  14. localStorage.authToken="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsiaWQiOiI2MWE0ZTA1MmM3NTBjMTJiYTZiYTQwMjkiLCJsb2dpbiI6InZsYWRCcmF1bjQiLCJhY2wiOlsiNjFhNGUwNTJjNzUwYzEyYmE2YmE0MDI5IiwidXNlciJdfSwiaWF0IjoxNjM5MzgwOTIzfQ.DLQ5Ei2bjg4i8eUXkpxANEiDY3P9khMdNmcElWioZ20";
  15. const gql=(url,query, variables)=>fetch(url, {
  16. method:"POST",
  17. headers:{
  18. 'content-type':'application/json',
  19. "Authorization":"Bearer "+localStorage.authToken
  20. },
  21. body: JSON.stringify({query,variables})
  22. })
  23. .then(res=>res.json())
  24. function catById(_id){
  25. (async () => {
  26. let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query catById($query:String){
  27. CategoryFindOne(query:$query){
  28. name goods{
  29. _id name
  30. }
  31. }
  32. }`, {query: JSON.stringify([{_id}])})
  33. console.log(res)
  34. })();
  35. }
  36. catById("5dc458985df9d670df48cc47")
  37. function auth(login, password) {
  38. (async () => {
  39. let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query log($login: String, $password: String) {
  40. login(login: $login, password: $password)
  41. }`, {login: login, password: password})
  42. console.log(res)
  43. })()
  44. }
  45. auth("vladBraun5", "1234");
  46. auth("vladBraun4","123");
  47. /*function rootCats() {
  48. (async () => {
  49. let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query {
  50. CategoryFind(query: $query){
  51. name goods{
  52. _id name
  53. }
  54. }
  55. }`)
  56. console.log(res);
  57. })();
  58. }
  59. rootCats()*/
  60. function reg(login, password) {
  61. (async () => {
  62. let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`mutation reg($login: String, $password: String){
  63. UserUpsert(user: {login: $login,
  64. password: $password,
  65. nick: $login}){
  66. _id login
  67. }
  68. }`, {login: login, password: password})
  69. console.log(res)
  70. })();
  71. }
  72. function goodFind() {
  73. (async () => {
  74. let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query goodz {
  75. GoodFind(query: "[{}]") {
  76. _id
  77. name
  78. price
  79. categories {
  80. _id
  81. name
  82. }
  83. }
  84. }`)
  85. console.log(res)
  86. })();
  87. }
  88. goodFind()
  89. /*function newOrder(count, _id) {
  90. (async () => {
  91. let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`mutation newOrder{
  92. OrderUpsert(order:{
  93. orderGoods:[
  94. {count: $count, good: {_id: $id}}
  95. ]
  96. })
  97. {
  98. _id total
  99. }`, {count: count, id: _id})
  100. console.log(res)
  101. })();
  102. }
  103. newOrder(3,"5dc8885e0e36db246e3049c4");*/
  104. </script>
  105. </body>
  106. </html>