【发布时间】:2022-11-23 01:54:12
【问题描述】:
我正在尝试使用 GraphQL 构建 rtk 查询 api。但似乎@rtk-query/graphql-request-base-query 和graphql-request 之间的包类型不匹配
我得到的错误如下;
Type 'import("path/to/file/node_modules/graphql-request/dist/index").GraphQLClient' is not assignable to type 'import("path/to/file/node_modules/@rtk-query/graphql-request-base-query/node_modules/graphql-request/dist/index").GraphQLClient'.
Types have separate declarations of a private property 'url'.ts(2322)
我在 graphqlRequestBaseQuery 的 **client** 字段上收到错误 我试图删除 node_modules 并重新安装,不幸的是没有工作......
这是我的api.ts;
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
import { graphqlRequestBaseQuery } from '@rtk-query/graphql-request-base-query';
import { GraphQLClient } from 'graphql-request';
import { gqlClient } from '../gql/gql-client';
export const api = createApi({
baseQuery: graphqlRequestBaseQuery({ client: new GraphQLClient('http://localhost:4000/graphql') }), // error is at "client" field
tagTypes: [],
endpoints: (builder) => ({
getUsers: builder.query({
query: () => '/users',
}),
}),
});
export const { useGetUsersQuery } = api;
【问题讨论】:
标签: reactjs redux graphql redux-toolkit rtk-query