1234567891011121314151617181920212223242526272829303132333435363738 |
- //gql
- {
- async function gql(url, query, options) {
- let settings = {
- method: "POST",
- headers:{
- "Content-Type": "application/json",
- "Accept": "application/json"
- },
- body: JSON.stringify({query: query, variables: options})
- }
- const res = await fetch(url, settings)
- return await res.json()
- }
-
-
- async function login() {
- const catQuery = `query cats($q: String){
- CategoryFind(query: $q){
- _id name
- }
- }`
- const cats = await gql("http://shop-roles.node.ed.asmer.org.ua/graphql", catQuery, {q: "[{}]"})
- console.log(cats) //список категорий с _id name и всем таким прочим
-
-
- const loginQuery = `query login($login:String, $password:String){
- login(login:$login, password:$password)
- }`
-
- const token = await gql("http://shop-roles.node.ed.asmer.org.ua/graphql", loginQuery ,{login: "test457", password: "123123"})
- console.log(token)
- }
- login()
- }
|