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

时间:2017-05-28 03:37:49

标签: graphql relayjs relay

找不到模块:错误:无法解决' ./ 生成 /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也不起作用。

2 个答案:

答案 0 :(得分:4)

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

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

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

答案 1 :(得分:3)

要获得两个扩展,您需要提供两次标记:

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