Reactjs ra数据图SQL simple找不到资源
我尝试使用react admin作为我的管理面板,并使用ra数据graphql simple从graphql API获取。 问题是它找不到我的资源,我遇到了以下错误: 未知资源类别。确保它已在服务器端架构中声明。已知资源是 这是我的密码 App.jsReactjs ra数据图SQL simple找不到资源,reactjs,graphql,react-admin,Reactjs,Graphql,React Admin,我尝试使用react admin作为我的管理面板,并使用ra数据graphql simple从graphql API获取。 问题是它找不到我的资源,我遇到了以下错误: 未知资源类别。确保它已在服务器端架构中声明。已知资源是 这是我的密码 App.js import React, { Component } from 'react'; import buildGraphQLProvider from 'ra-data-graphql-simple'; import { Admin, Resourc
import React, { Component } from 'react';
import buildGraphQLProvider from 'ra-data-graphql-simple';
import { Admin, Resource, Delete, ListGuesser } from 'react-admin';
import apolloClient from './apolloSetup';
import { CategoryList } from './categories';
class App extends Component {
constructor() {
super();
this.state = { dataProvider: null };
}
componentDidMount() {
buildGraphQLProvider({ clientOptions: { uri: 'http://127.0.0.1:3434/graphql' }})
.then(dataProvider => this.setState({ dataProvider }));
}
render() {
const { dataProvider } = this.state;
if (!dataProvider) {
return <div>Loading</div>;
}
return (
<Admin dataProvider={dataProvider}>
<Resource name="Category" list={ListGuesser} />
</Admin>
);
}
}
export default App;
这是我的Graphql模式。类别父id始终为1
# source: http://127.0.0.1:3434/graphql
type Category {
body: String
disabled: Boolean
id: ID
image: Upload
parentId: ID
title: String
user: User
}
"""Autogenerated input type of ConfirmOtp"""
input ConfirmOtpInput {
mobile: String!
otp: String!
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
}
"""Autogenerated return type of ConfirmOtp"""
type ConfirmOtpPayload {
accessToken: String
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
errors: [String!]!
}
"""Autogenerated input type of CreateCategory"""
input CreateCategoryInput {
title: String!
body: String
parentId: ID
image: Upload
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
}
"""Autogenerated return type of CreateCategory"""
type CreateCategoryPayload {
category: Category
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
errors: [String!]
}
"""Autogenerated input type of CreatePost"""
input CreatePostInput {
title: String!
body: String
categoryId: ID!
image: Upload
video: Upload
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
}
"""Autogenerated return type of CreatePost"""
type CreatePostPayload {
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
errors: [String!]!
post: Post!
}
"""Autogenerated input type of GenerateOtp"""
input GenerateOtpInput {
mobile: String!
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
}
"""Autogenerated return type of GenerateOtp"""
type GenerateOtpPayload {
"""A unique identifier for the client performing the mutation."""
clientMutationId: String
result: String
}
type Mutation {
confirmOtp(input: ConfirmOtpInput!): ConfirmOtpPayload
createCategory(input: CreateCategoryInput!): CreateCategoryPayload
createPost(input: CreatePostInput!): CreatePostPayload
generateOtp(input: GenerateOtpInput!): GenerateOtpPayload
}
type Post {
body: String
category: Category
disabled: Boolean
id: ID
image: Upload
title: String
user: User
video: Upload
}
type Query {
"""List of all categories or categories of a directory"""
categories(parentId: ID): [Category!]
"""Returns the current user"""
currentUser: User!
"""Find a post by ID"""
post(id: ID!): Post
"""List of all posts"""
posts(categoryId: ID!): [Post!]
}
scalar Upload
type User {
mobile: String!
}
我应该创建自定义数据提供程序吗?如果是,我应该如何为这个模式创建它?如果您仍然停留在这一点上,我建议将您的模式减少到只包含类别类型和相关突变。有关ra数据GraphQL simple的预期GraphQL模式格式,请参阅。首先,尝试将资源中的内容交换为此格式。ra data graphql simple非常挑剔,如果它不喜欢您的模式,它只会忽略资源,因此您会在没有资源的情况下收到错误消息。如果查看源代码,您会注意到,如果资源的类型最少,那么它就是knownResource:
Query {
Post (id: ID!): Post
allPosts (page: Int, perPage: Int, sortField: String, sortOrder: String, filter: PostFilter): [Post]
}
在封面下,ra数据graphql simple使用“多元化”库,在评估资源是否可用时,对大小写等极为敏感。如果资源的大小写版本不正确,它将忽略该资源,并且至少包含GET_ONE、GET_LIST查询元素。因此,对于原始帖子“类别”,至少需要所有类别和类别显示为可查询项
Query {
Post (id: ID!): Post
allPosts (page: Int, perPage: Int, sortField: String, sortOrder: String, filter: PostFilter): [Post]
}