无法读取null的属性“名称”(react-admin)

时间:2020-02-06 06:03:31

标签: react-admin

我拥有最简单的代码来检查$lookup

react-admin

但是在控制台中我总是遇到相同的错误:无法读取null的属性'name'

我的依赖是:

import React, { Component } from "react";
import buildGraphQLProvider from "ra-data-graphql-simple";
import { Admin, Resource } from "react-admin";
import posts from "./routes/posts";

class App extends Component {
  constructor() {
    super();
    this.state = { dataProvider: null };
  }
  componentDidMount() {
    buildGraphQLProvider({
      clientOptions: { uri: "https://countries.trevorblades.com" }
    })
      .then(dataProvider => this.setState({ dataProvider }))
      .catch(e => console.log(e.message));
  }

  render() {
    const { dataProvider } = this.state;

    if (!dataProvider) {
      return <div>Loading</div>;
    }

    return (
      <Admin dataProvider={dataProvider}>
        <Resource name="posts" {...posts} />
      </Admin>
    );

    //or, directly return <Admin dataProvider={dataProvider} />

  }
}

export default App;

我做错了什么?

2 个答案:

答案 0 :(得分:1)

我有同样的问题。

问题是我在我的graphql模式中缺少Mutation类型,因此检查了

type.name !== schema.mutationType.name

抛出错误,因为schema.mutationType未定义

即使模式为空,也要确保模式中有Mutation类型

答案 1 :(得分:0)

也许您想写?

<Resource name="posts" />

您阅读文档了吗?

https://marmelab.com/react-admin/Resource.html