Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Relay Compiler not generating .graphql files

Module not found: Error: Can't resolve './generated/GetAllCities.graphql'

the component:

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>

the relay-compiler command:

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

the schema:

  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 }

the babelrc file:

  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 }~   

the major issue is yarn run relay or npm run relay does not generate the generated GetAllCities.graphql

also get no error. it worked before with a fragment container. renaming the file to .js also doesn't work.

like image 904
liminal18 Avatar asked Feb 05 '23 09:02

liminal18


2 Answers

answer was to change the packages.conf script to:

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

it now only works on jsx files but it does see them

like image 51
liminal18 Avatar answered Feb 20 '23 05:02

liminal18


To get both extensions you need to supply the flag twice like so:

"relay": "relay-compiler --src ./src --schema ./data/schema.graphql --extensions=js --extensions=jsx"
like image 22
Martin Dawson Avatar answered Feb 20 '23 06:02

Martin Dawson