123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- function getGql (endpoint){
- let headers = {
- 'Content-Type': 'application/json;charset=utf-8',
- 'Accept': 'application/json'
- }
-
- return async function gql(query, variables={}) {
- if ("authToken" in localStorage) {
- headers.Authorization = "Bearer " + localStorage.authToken
- }
- let result = await fetch(endpoint, {
- method: 'POST',
- headers,
- body: JSON.stringify({
- query,
- variables
- })
- }).then(res => res.json())
- if (("errors" in result) && !("data" in result)) {
- throw new Error(JSON.stringify(result.errors))
- }
- result = Object.values(result.data)[0]
- return result
- }
- }
-
-
- const gql = getGql('http://shop-roles.node.ed.asmer.org.ua/graphql')
-
- const gqlRootCats = () =>
- gql(`query baseCategory($searchNullparent: String){
- CategoryFind(query: $searchNullparent){
- _id name parent {
- _id
- name
- }
- }
- }`, {
- searchNullparent: JSON.stringify([{parent: null}])
- })
-
-
- const gqlCategoryGoodsAndSubCategoryGoods = (_id) =>
- gql(`query CategoryGoodsAndSubCategoryGoods($qCategoryId: String) {
- CategoryFindOne(query: $qCategoryId){
- _id
- name
- parent{
- _id
- name
- }
- subCategories{
- _id
- name
- goods{
- _id
- name
- }
- }
- goods{
- _id name price
- images {
- url
- }
- }
- }
- }`, {
- qCategoryId: JSON.stringify([{ _id }])
- })
-
-
- const gqlOneGoodWithDescriptionAndImages = (_id) =>
- gql(`query oneGoodWithDescriptionAndImages($GoodId: String){
- GoodFindOne(query: $GoodId){
- _id
- description
- name
- price
- images{
- url
- }
- }
- }`, {
- GoodId: JSON.stringify( [{ _id }] )
- })
-
-
- const gqlUserAdd = (login, password) =>
- gql(`mutation registration($login:String, $password: String){
- UserUpsert(user: {login:$login, password: $password}){
- _id login createdAt
- }
- }`, {
- login,
- password
- }
- )
-
- const gqllogin = (login, password) =>
- gql(`query login($login:String, $password:String){
- login(login:$login, password:$password)
- }`, {
- login,
- password
- }
- )
-
-
- const gqlOrderFind = () =>
- gql(`query {
- OrderFind(query: "[{}]") {
- _id
- createdAt
- total
- }
- }`,
- )
-
-
- const OrderUpsert2 = (arrGoods) =>
- gql(`mutation ($arrGoods: [OrderGoodInput]){
- OrderUpsert(order: {orderGoods: $arrGoods}) {
- _id, total, orderGoods {
- good {
- name
- }
- }
- }
- }`, {
- arrGoods
- }
- )
|