123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <script>
- /*const originalFetch = fetch;
- fetch = (url, params={headers:{}}) => {
- params.headers.Authorization = "Bearer " + localStorage.authToken
- return originalFetch(url, params)
- }*/
- localStorage.authToken="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOnsiaWQiOiI2MWE0ZTA1MmM3NTBjMTJiYTZiYTQwMjkiLCJsb2dpbiI6InZsYWRCcmF1bjQiLCJhY2wiOlsiNjFhNGUwNTJjNzUwYzEyYmE2YmE0MDI5IiwidXNlciJdfSwiaWF0IjoxNjM5MzgwOTIzfQ.DLQ5Ei2bjg4i8eUXkpxANEiDY3P9khMdNmcElWioZ20";
- const gql=(url,query, variables)=>fetch(url, {
- method:"POST",
- headers:{
- 'content-type':'application/json',
- "Authorization":"Bearer "+localStorage.authToken
- },
- body: JSON.stringify({query,variables})
- })
- .then(res=>res.json())
- function catById(_id){
- (async () => {
- let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query catById($query:String){
- CategoryFindOne(query:$query){
- name goods{
- _id name
- }
- }
- }`, {query: JSON.stringify([{_id}])})
- console.log(res)
- })();
- }
- catById("5dc458985df9d670df48cc47")
- function auth(login, password) {
- (async () => {
- let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query log($login: String, $password: String) {
- login(login: $login, password: $password)
- }`, {login: login, password: password})
- console.log(res)
- })()
- }
- auth("vladBraun5", "1234");
- auth("vladBraun4","123");
- /*function rootCats() {
- (async () => {
- let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query {
- CategoryFind(query: $query){
- name goods{
- _id name
- }
- }
- }`)
- console.log(res);
- })();
- }
- rootCats()*/
- function reg(login, password) {
- (async () => {
- let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`mutation reg($login: String, $password: String){
- UserUpsert(user: {login: $login,
- password: $password,
- nick: $login}){
- _id login
- }
- }`, {login: login, password: password})
- console.log(res)
- })();
- }
- function goodFind() {
- (async () => {
- let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`query goodz {
- GoodFind(query: "[{}]") {
- _id
- name
- price
- categories {
- _id
- name
- }
- }
- }`)
- console.log(res)
- })();
- }
- goodFind()
- /*function newOrder(count, _id) {
- (async () => {
- let res = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql",`mutation newOrder{
- OrderUpsert(order:{
- orderGoods:[
- {count: $count, good: {_id: $id}}
- ]
- })
- {
- _id total
- }`, {count: count, id: _id})
- console.log(res)
- })();
- }
-
- newOrder(3,"5dc8885e0e36db246e3049c4");*/
- </script>
- </body>
- </html>
|