let gql = (url, query, variables={}) => fetch(url, { method: 'POST', headers:{ Accept: 'application/json', "Content-Type": 'application/json' }, body: JSON.stringify({query, variables}) }).then(res => res.json()) const graphiQL = "http://shop-roles.node.ed.asmer.org.ua/graphql"; let log = (login, password) => gql(graphiQL, `query login($login:String, $password:String){ login(login:$login, password:$password) }`, {login, password}) let register = (login, password) => gql(graphiQL, `mutation register($login:String, $password:String){ UserUpsert(user:{login:$login, password:$password}){ _id login createdAt } }`, {login, password}) let category = () => gql(graphiQL, `query category { CategoryFind(query: "[{}]"){ _id, name } }`) let catById = () => gql(graphiQL, `query catById { CategoryFind(query: "[{}]"){ _id name goods { _id name price description price } } }`) (async function gqlResult() { console.log(await register("levshin95", "123123")) console.log(await log("levshin95", "123123")); console.log(await category()); console.log(await catById()); })();