这是我的 schema.graphql
schema {
query: RootQuery
}
type RootQuery {
student(id: String): Student
students: [Student]
school(id: String): School
}
type School {
id: String
name: String
address: String
students: [Student]
}
type Student {
id: String
name: String
age: Int
address: String
school: School
}
这是我的组件 StudentQuery.js
import React from "react";
import { graphql, QueryRenderer } from "react-relay";
//import graphql from "babel-plugin-relay/macro";
import environment from "./relayEnvironment";
export default class Database extends React.Component {
render() {
return (
<QueryRenderer
environment={environment}
query={graphql`
query StudentQuery {
student(id: "M1") {
name
}
}
`}
variables={{}}
render={({ error, props }) => {
if (error) {
return <div>Error!</div>;
}
if (!props) {
return <div>Loading...</div>;
}
return <div>User ID: {props.student.name}</div>;
}}
/>
);
}
}
当我尝试运行命令 yarn 中继时 它总是给出错误
错误: 内部错误:未知类型:“ID”。 错误 命令失败,退出代码为 100。
中继编译器不会创建自动生成的文件。
提前致谢
最佳答案
我也遇到了同样的问题。我不知道为什么,但如果您将类型为 ID
的字段添加到您的对象类型之一,错误就会消失:
type School {
strangeID: ID
id: String
name: String
address: String
students: [Student]
}
这一定是编译器中的错误。
关于reactjs - 中继编译器确实会生成自动生成的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58699001/