const getGQL = url => (query, variables) => fetch(url , { method: 'POST', headers: { "content-type": "application/json" }, body: JSON.stringify({query, variables}) }).then(res => res.json()) let gql = getGQL("http://shop-roles.asmer.fs.a-level.com.ua/graphql") async function categoryById(id) { let query = `query CategoryFind($id:String) { CategoryFind(query:$id) { name goods { name price description images {url} } } }` let variables = {"id": JSON.stringify([{ "_id": id }])} //or {"id": "[{\"_id\":\"id\"}]"} let res = await gql(query, variables) console.log(res) return res } categoryById("5dc458985df9d670df48cc47") async function goodById(id) { let query = `query GoodFind($id:String) { GoodFind(query:$id) { categories { _id name } name price description createdAt images {url} } }` let variables = {"id": JSON.stringify([{ "_id": id }])} //or {"id": "[{\"_id\":\"id\"}]"} let res = await gql(query, variables) console.log(res) return res } goodById("5e203b5456d8f720513e6cba") async function goodFind() { let query = `query GoodFind($q:String) { GoodFind(query:$q) { categories { _id name } _id name price description createdAt images {url} } }` let variables = {"q": JSON.stringify([{}])} //or {"q": "[{}]"} let res = await gql(query, variables) console.log(res) return res } goodFind() async function categoryFind() { let query = `query CategoryFind($q:String) { CategoryFind(query:$q) { _id name createdAt goods { _id name price createdAt } } }` let variables = {"q": JSON.stringify([{}])} //or {"q": "[{}]"} let res = await gql(query, variables) console.log(res) return res } categoryFind()