【问题标题】:Relay compiler does generate auto generated files中继编译器确实生成自动生成的文件
【发布时间】:2019-11-07 01:10:47
【问题描述】:

这是我的 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 relay 它总是给出错误

错误: 内部错误:未知类型:“ID”。 错误命令失败,退出代码为 100。

中继编译器不会创建自动生成的文件。

提前致谢

【问题讨论】:

    标签: reactjs graphql relaymodern


    【解决方案1】:

    我遇到了同样的问题。我不知道为什么,但是如果您将类型为 ID 的字段添加到您的对象类型之一,错误就会消失:

    type School {
        strangeID: ID
        id: String
        name: String
        address: String
        students: [Student]
    }
    

    一定是编译器的bug。

    【讨论】:

      猜你喜欢
      • 2017-10-28
      • 1970-01-01
      • 2013-02-17
      • 1970-01-01
      • 2015-09-12
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多