如何解决React Admin/通过“ra-data-graphql”库构建数据提供者 - 自动注入的“raFetchType”参数未定义
我正在尝试通过 ra-data-graphql
创建一个 dataProvider,如 library's README 中所述,并且我成功地将内省响应传递给 buildQuery
方法,但是 {{1我的 raFetchType
方法中的 }} 参数始终未定义,并且应该发生的查询映射失败。似乎 buildQuery
应该由库自动填充,或者我(或文档)遗漏了一些东西。
在将 raFetchType
注入 buildCustomQuery
时是否需要提供一些额外的选项?
您所期待的:
buildGraphQLProvider
已定义(我假设为“GET_LIST”、“GET_ONE”等之一)
发生了什么:
raFetchType
中的 raFetchType
参数(在库的源代码中称为 buildQuery
)始终未定义
相关代码:
aorFetchType
// App.tsx
const [dataProvider,setDataProvider] = useState<DataProvider>();
const cache = new InMemoryCache();
const link = createHttpLink({
uri: // my graphql API URL
});
const client = new ApolloClient({
cache: cache,link: link,});
useEffect(() => {
buildGraphQLProvider({
client: { client },buildQuery: buildCustomQuery,introspection: {
schema,// JSON prevIoUsly fetched from my GraphQL API
operationNames: introspectionoperationNames,// function that maps the 'Country' resource to the correct query name for 'GET_LIST'
include: ['Country'],// just trying it out with a single Resource first
},}).then((dataProvider: any) => {
setDataProvider(dataProvider);
})
},[]);
环境
- React 管理员版本:3.11.0
- 反应版本:17.0.1
- 浏览器:Chrome
- 堆栈跟踪:
// this is called via `buildGraphQLProvider` on init export const buildCustomQuery = (introspectionResults: any) => (raFetchType: any,resourceName: any,params: any) => { // the introspectionResults contain the 4 properties listed here: https://github.com/marmelab/react-admin/tree/master/packages/ra-data-graphql#specify-your-queries-and-mutations // including the 'Country' resource with the mapped query name // however,`raFetchType` is undefined,and so no query can ever be returned. // I get 'TypeError: Cannot read property 'parseResponse' of undefined' on ra-data-graphql/esm/index.js:113 const resource = introspectionResults.resources.find((r: IntrospectionResource) => r.type.name === resourceName); switch (raFetchType) { case 'GET_LIST': return { query: gql`query ${resource[raFetchType].name}($id: ID) { data: ${resource[raFetchType].name}(id: $id) { ... } } }`,variables: params,// params = { id: ... } parseResponse: (response: any) => response.data,} break; // ... other types handled here default: return undefined; } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。