gpt4 book ai didi

reactjs - ra-data-graphql-simple 找不到资源

转载 作者:行者123 更新时间:2023-12-02 14:47:59 24 4
gpt4 key购买 nike

我正在尝试使用 react-admin 作为我的管理面板,并使用 ra-data-graphql-simple 从 graphql API 获取数据。问题是它找不到我的资源,我得到了这个错误:

未知资源类别。确保它已在您的服务器端模式中声明。已知资源是

这是我的代码。

App.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;

和 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,
});

这是我的 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!
}

我应该创建自定义数据提供程序吗?如果是,我应该如何为这个模式创建它?

最佳答案

如果您查看源代码,您会注意到 Resource 是 knownResource 如果它具有最小类型:

Query {
   Post (id: ID!): Post
   allPosts (page: Int, perPage: Int, sortField: String, sortOrder: String, filter: PostFilter): [Post]

}

关于reactjs - ra-data-graphql-simple 找不到资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57773340/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com