I do import graphQL query as:
import {getStudents} from'./../graphql/Queries.graphql'
Queries.graphql file:
query getStudents($schoolID: Int!){
allStudents(schoolId: $schoolID){
pickUpLat
pickUpLng
}
}
but when I try to pass the query to the component as:
export default graphql(getStudents, {
options: (props) => ({ variables: { schoolID: props.schoolID } })
})( StudentsMap );
I get this error:
Uncaught Error: Argument of undefined passed to parser was not a valid GraphQL DocumentNode. You may need to use 'graphql-tag' or another method to convert your operation into a document
at invariant (browser.js:38)
at parser (react-apollo.browser.umd.js:199)
at graphql (react-apollo.browser.umd.js:1061)
at Object../src/map/StudentsMap.js (StudentsMap.js:96)
at __webpack_require__ (bootstrap b06dc52180087582baaa:19)
at Object../src/App.js (App.css?9a66:26)
at __webpack_require__ (bootstrap b06dc52180087582baaa:19)
at Object../src/index.js (index.css?f255:26)
at __webpack_require__ (bootstrap b06dc52180087582baaa:19)
at Object.0 (registerServiceWorker.js:117)
However, if I define the query in the same file of component (not importing it) as:
const getStudents= gql`
query getStudents($schoolID: Int){
allStudents(schoolId: $schoolID){
pickUpLat
pickUpLng
}
}`
then it does work normally, any idea why I get that error when try to import the query?
Here is my webpack.config.js
settings: (based on this reference)
var webpack = require('webpack');
module: {
rules: [
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
],
}
It seems that Loading queries with Webpack fails? or what it could be?