123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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
|