const getGQL = url => { return (query, variables) => { fetch(url, { method: 'POST', headers: { "content-type": "application/json" }, body: JSON.stringify({ query, variables }) }).then(res => res.json()).then(data => console.log(data)) } } let gql = getGQL("http://shop-roles.asmer.fs.a-level.com.ua/graphql") let getId = (type, name) => { let t = type.toLowerCase(); let query; if (t === "category") { query = `query fndCtgId($n: String) { CategoryFind(query: $n){ _id } }` } else if (t === "good") { query = `query fndCtgId($n: String) { GoodFind(query: $n){ _id } }` } let qVariables = { "n": JSON.stringify([{ "name": name }]) } gql(query, qVariables) } let categoryById = id => { let query = `query fndcategory($id: String) { CategoryFind(query: $id){ name goods{ name price images { url } } } }` let qVariables = { "id": JSON.stringify([{ "_id": id }]) } gql(query, qVariables) } let goodById = id => { let query = `query fndgood($id: String) { GoodFind(query: $id){ name price images { url } } }` let qVariables = { "id": JSON.stringify([{ "_id": id }]) } gql(query, qVariables) }