categoriesApi copy.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
  2. import { gqlRootCats1, CategoryFindOne, GoodFindOne } from '../components/actions/actions'
  3. // export const categoriesApi = createApi({
  4. // reducerPath: 'categoriesApi',
  5. // // tagTypes: ['Categories'],
  6. // baseQuery: fetchBaseQuery({ baseUrl: 'http://shop-roles.node.ed.asmer.org.ua/graphql' }),
  7. // endpoints: (build) => ({
  8. // getCategories: build.query({
  9. // query: ()=> ({
  10. // method: 'POST',
  11. // headers: {
  12. // 'Content-Type': 'application/json;charset=utf-8',
  13. // 'Accept': 'application/json'
  14. // },
  15. // body: JSON.stringify({
  16. // query: `query categories{
  17. // CategoryFind(query:"[{}]"){
  18. // _id name
  19. // }
  20. // }`
  21. // })
  22. // }),
  23. // // providesTags: (result) =>
  24. // // result
  25. // // ? [
  26. // // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })),
  27. // // { type: 'Categories', id: 'LIST' },
  28. // // ]
  29. // // : [{ type: 'Categories', id: 'LIST' }],
  30. // })
  31. // })
  32. // })
  33. export const categoriesApi = createApi({
  34. reducerPath: 'categoriesApi',
  35. // tagTypes: ['Categories'],
  36. baseQuery: fetchBaseQuery({ baseUrl: 'http://shop-roles.node.ed.asmer.org.ua/graphql' }),
  37. endpoints: (build) => ({
  38. getCategories: build.query({
  39. query: ()=> ({
  40. method: 'POST',
  41. headers: {
  42. 'Content-Type': 'application/json;charset=utf-8',
  43. 'Accept': 'application/json'
  44. },
  45. body: JSON.stringify(gqlRootCats1)
  46. }),
  47. // providesTags: (result) =>
  48. // result
  49. // ? [
  50. // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })),
  51. // { type: 'Categories', id: 'LIST' },
  52. // ]
  53. // : [{ type: 'Categories', id: 'LIST' }],
  54. }),
  55. getCategory: build.query({
  56. query: (_id)=> ({
  57. method: 'POST',
  58. headers: {
  59. 'Content-Type': 'application/json;charset=utf-8',
  60. 'Accept': 'application/json'
  61. },
  62. body: JSON.stringify(CategoryFindOne(_id))
  63. }),
  64. // providesTags: (result) =>
  65. // result
  66. // ? [
  67. // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })),
  68. // { type: 'Categories', id: 'LIST' },
  69. // ]
  70. // : [{ type: 'Categories', id: 'LIST' }],
  71. }),
  72. getProduct: build.query({
  73. query: (_id)=> ({
  74. method: 'POST',
  75. headers: {
  76. 'Content-Type': 'application/json;charset=utf-8',
  77. 'Accept': 'application/json'
  78. },
  79. body: JSON.stringify(GoodFindOne(_id))
  80. }),
  81. // providesTags: (result) =>
  82. // result
  83. // ? [
  84. // ...Object.values(result.data)[0].map(({ _id }) => ({ type: 'Categories', _id })),
  85. // { type: 'Categories', id: 'LIST' },
  86. // ]
  87. // : [{ type: 'Categories', id: 'LIST' }],
  88. })
  89. })
  90. })
  91. export const {useGetCategoriesQuery, useGetCategoryQuery, useGetProductQuery} = categoriesApi