yot*_*ami 2 reactjs graphql react-admin
我正在尝试使用react-admin作为我的管理面板,并使用ra-data-graphql-simple从graphql API中获取。问题是它找不到我的资源,我收到此错误:
Unknown resource Category. Make sure it has been declared on your server side schema. Known resources are
这是我的代码。
应用程序.js
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;
Run Code Online (Sandbox Code Playgroud)
和 apolloSetup.js
import { HttpLink, createHttpLink } from 'apollo-link-http';
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
const httpLink = createHttpLink({
uri: 'http://localhost:3434/graphql',
mode: 'no-cors',
});
export default new ApolloClient({
cache: new InMemoryCache(),
link: httpLink,
});
Run Code Online (Sandbox Code Playgroud)
这是我的 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!
}
Run Code Online (Sandbox Code Playgroud)
我应该创建自定义数据提供程序吗?如果是,我应该如何为此架构创建它?
如果您查看源代码,您会注意到如果该资源具有最小类型,则该资源是knownResource:
\n\nQuery {\n\xc2\xa0\xc2\xa0 Post (id: ID!): Post\n\xc2\xa0\xc2\xa0 allPosts (page: Int, perPage: Int, sortField: String, sortOrder: String, filter: PostFilter): [Post]\n\n}\nRun Code Online (Sandbox Code Playgroud)\n
| 归档时间: |
|
| 查看次数: |
1364 次 |
| 最近记录: |