import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react' import { gqlRootCats1, CategoryFindOne, GoodFindOne } from '../components/actions/actions' // export const categoriesApi = createApi({ // reducerPath: 'categoriesApi', // // tagTypes: ['Categories'], // baseQuery: fetchBaseQuery({ baseUrl: 'http://shop-roles.node.ed.asmer.org.ua/graphql' }), // endpoints: (build) => ({ // getCategories: build.query({ // query: ()=> ({ // method: 'POST', // headers: { // 'Content-Type': 'application/json;charset=utf-8', // 'Accept': 'application/json' // }, // body: JSON.stringify({ // query: `query categories{ // CategoryFind(query:"[{}]"){ // _id name // } // }` // }) // }), // // providesTags: (result) => // // result // // ? [ // // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })), // // { type: 'Categories', id: 'LIST' }, // // ] // // : [{ type: 'Categories', id: 'LIST' }], // }) // }) // }) export const categoriesApi = createApi({ reducerPath: 'categoriesApi', // tagTypes: ['Categories'], baseQuery: fetchBaseQuery({ baseUrl: 'http://shop-roles.node.ed.asmer.org.ua/graphql' }), endpoints: (build) => ({ getCategories: build.query({ query: ()=> ({ method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8', 'Accept': 'application/json' }, body: JSON.stringify(gqlRootCats1) }), // providesTags: (result) => // result // ? [ // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })), // { type: 'Categories', id: 'LIST' }, // ] // : [{ type: 'Categories', id: 'LIST' }], }), getCategory: build.query({ query: (_id)=> ({ method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8', 'Accept': 'application/json' }, body: JSON.stringify(CategoryFindOne(_id)) }), // providesTags: (result) => // result // ? [ // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })), // { type: 'Categories', id: 'LIST' }, // ] // : [{ type: 'Categories', id: 'LIST' }], }), getProduct: build.query({ query: (_id)=> ({ method: 'POST', headers: { 'Content-Type': 'application/json;charset=utf-8', 'Accept': 'application/json' }, body: JSON.stringify(GoodFindOne(_id)) }), // providesTags: (result) => // result // ? [ // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })), // { type: 'Categories', id: 'LIST' }, // ] // : [{ type: 'Categories', id: 'LIST' }], }) }) }) export const {useGetCategoriesQuery, useGetCategoryQuery, useGetProductQuery} = categoriesApi