我试图用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;
2条答案
按热度按时间af7jpaap1#
下面是一个使用@rtk-query/graphql-request-base-query版本2.2.0的示例。
l2osamch2#
我在遵循代码生成文档时遇到了同样的问题。要添加到@dwight建议的内容中,您也可以复制
@rtk-query/graphql-request-base-query
包的代码文件并将它们放入您的项目中。从那里导入graphqlRequestBaseQuery
。@rtk-query/graphql-request-base-query
在内部从graphql-request
导入GraphQLClient
,类型不匹配可能是因为尚未在正式存储库中更新相关性。我希望这能有所帮助