Dz15js.html 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. </head>
  9. <body>
  10. <script>
  11. const URLbeck = "http://shop-roles.node.ed.asmer.org.ua/graphql";
  12. let gql = (url, query, variables = {}) =>
  13. fetch(url, {
  14. method: 'POST',
  15. headers: {
  16. Accept: 'application/json',
  17. "Content-Type": 'application/json'
  18. },
  19. body: JSON.stringify({ query, variables })
  20. }).then((res) => res.json())
  21. const categoryFind = () =>
  22. gql(
  23. URLbeck,
  24. `
  25. query cadz{
  26. CategoryFind(query:"[{}]") {
  27. _id name
  28. }
  29. }
  30. `
  31. )
  32. const categoryId = () =>
  33. gql(
  34. URLbeck,
  35. `
  36. query categotyId {
  37. CategoryFind(query:"[{}]"){
  38. _id name
  39. goods{
  40. _id name
  41. price createdAt
  42. description
  43. }
  44. }
  45. }
  46. `
  47. )
  48. const categoryIdImagesDescription = (id) =>{
  49. let SearchId = `\\"_id\\":\\"${id}\\"`
  50. return gql(
  51. URLbeck,
  52. `
  53. query categoryIdImagesDescription{
  54. GoodFind(query:"[{${SearchId}}]"){
  55. name description
  56. images{
  57. _id
  58. url
  59. text
  60. }
  61. }
  62. }
  63. `
  64. )
  65. }
  66. const gqlLogin = (login, password) =>
  67. gql(
  68. URLbeck,
  69. `
  70. query login($login:String, $password: String){
  71. login(login:$login, password: $password)
  72. }
  73. `,
  74. { login, password }
  75. );
  76. const gqlRegistr = (login, password) =>
  77. gql(
  78. URLbeck,
  79. `
  80. mutation register($login:String, $password:String){
  81. UserUpsert(user: {login:$login, password:$password}){
  82. _id login createdAt
  83. }
  84. }
  85. `,
  86. { login, password }
  87. );
  88. console.log(categoryFind());
  89. console.log(categoryId("62d403fbb74e1f5f2ec1a12a"));
  90. console.log(categoryIdImagesDescription(""));
  91. console.log(gqlRegistr("Billy ", "Herrington"));
  92. console.log(gqlLogin("Billy ", "Herrington"));
  93. </script>
  94. </body>
  95. </html>