简体   繁体   中英

Relay compiler does generate auto generated files

here is my 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
}

here is my component 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>;
    }}
  />
   );
   }
  }

when i try run the command yarn relay it always gives the error

ERROR: Internal Error: Unknown type: 'ID'. error Command failed with exit code 100.

No auto generated files are created by the relay-compiler.

Thanks in Advance

I had the same problem. I don't know why, but if you add a field with type ID to one of your object types, the error disappears:

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

It must be a bug in the compiler.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM