繁体   English   中英

中继编译器不生成.graphql文件

[英]Relay Compiler not generating .graphql files

找不到模块:错误:无法解析'./ generated /GetAllCities.graphql'

组件:

export class Map extends React.Component {
21   constructor(props){
22     super(props);
23   };


 24   render(){
 25     return(
 26      <div id='map'>
 27        <GoogleMapReact
 28        bootstrapURLKeys={{key: ''}}
 29        defaultCenter={this.props.center}
 30        defaultZoom={this.props.zoom}
 31        >
 32          <QueryRenderer
 33            environment={environment}
 34            query={graphql`
 35              query GetAllCities {
 36                cities {
 37                  id
 38                  lat
 39                }
 40              }
 41           `}
 42            render={
 43              ({error, props}) => {
 44                if (error) {
 45                  return <div>{error.message}</div>;
 46                } else if (props) {
 47                  console.log(props);
 48                  return <div>{props.data.id}</div>;
 49                }
 50                  return <div>Loading</div>;
 51              }
 52            }
 53          />
 54        </GoogleMapReact>

relay-compiler命令:

 11     "relay": "relay-compiler --src ./src --schema ./data/schema.graphql --extensions=js,jsx",

架构:

  1 # A city to be used on the map
  2 type City {
  3   id: Int!
  4   lat: Float
  5   lng: Float
  6   todo: [ToDo]
  7 }
  8 
  9 # Mutations for the To Do List
 10 type Mutation {
 11   createToDo(city_id: Int!, text: String!): ToDo
 12 }
 13 
 14 # An array of Cities
 15 type Query {
 16   cities: [City]
 17   city(id: Int): City
 18 }
 19 
 20 # A To Do for a city
 21 type ToDo {
 22   city_id: Int!
 23   text: String
 24   likes: Int
 25   id: Int!
 26 }

babelrc文件:

  1 {
  2   "plugins": [
  3      ["relay", {
  4        "compat": true,
  5        "schema": "./data/schema.graphql",
  6        "enforceSchema": true,
  7        "suppressWarnings": false,
  8        "debug": false,
  9      }]
 10    ],
 11   "presets": ["react", "es2015", "es2016", "es2017"]
 12 }~   

主要问题是纱线运行继电器或npm运行继电器不生成生成的 GetAllCities.graphql

也没有错误。 之前它使用了一个片段容器。 将文件重命名为.js也不起作用。

回答是将packages.conf脚本更改为:

“relay”:“relay-compiler --src ./src --schema ./data/schema.graphql --extensions jsx”

它现在只适用于jsx文件,但它确实看到了它们

要获得这两个扩展,您需要提供两次标记,如下所示:

"relay": "relay-compiler --src ./src --schema ./data/schema.graphql --extensions=js --extensions=jsx"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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