apollo-tooling
apollo-tooling copied to clipboard
Syntax Error: Unexpected <EOF>
Intended outcome:
When running:
npx apollo client:codegen --target=typescript --globalTypesFile=./src/__generated__/globalTypes.ts
I would expect to get types generated.
Actual outcome:
yarn run v1.22.4
$ npx apollo client:codegen --target=typescript --globalTypesFile=./src/__generated__/globalTypes.ts
✔ Loading Apollo Project
✖ Generating query files with 'typescript' target
→ Syntax error in file:///Users/chris/Apps/ReactNative/Tracker/node_modules/graphql-tag/loader.js: Syntax Error: Unexpected <EOF>.
Error: Syntax error in file:///Users/chris/Apps/ReactNative/Tracker/node_modules/graphql-tag/loader.js: Syntax Error: Unexpected <EOF>.
error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
How to reproduce the issue:
Not able to share the repo, but it's a fresh React Native app with the dependencies listed below. I tried running using apollo@latest
and [email protected]
. Also tried clearing the node_modules
folder and reinstalling to no avail.
apollo.config.js
:
module.exports = {
client: {
tagName: 'gql',
includes: ['./**/!(*.test).{ts,tsx,js,jsx}'],
service: {
name: 'Tracker API',
url: 'http://localhost:5001',
},
},
}
Versions
"dependencies": {
"@apollo/client": "^3.1.4",
"date-fns": "^2.16.1",
"graphql-tag": "^2.11.0", // This was added as an attempt to fix - also tried the previosu version
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-navigation": "^6.12.2",
"react-native-navigation-hooks": "^6.1.0"
},
"devDependencies": {
"@babel/core": "^7.8.4",
"@babel/runtime": "^7.8.4",
"@react-native-community/eslint-config": "^1.1.0",
"@types/jest": "^25.2.3",
"@types/react-native": "^0.63.2",
"@types/react-test-renderer": "^16.9.2",
"@typescript-eslint/eslint-plugin": "^2.27.0",
"@typescript-eslint/parser": "^2.27.0",
"babel-jest": "^25.1.0",
"babel-plugin-module-resolver": "^4.0.0",
"babel-plugin-transform-remove-console": "^6.9.4",
"eslint": "^6.5.1",
"jest": "^25.1.0",
"metro-react-native-babel-preset": "^0.59.0",
"prettier": "^2.1.1",
"react-test-renderer": "16.13.1",
"typescript": "^3.8.3"
},
UPDATE: simplifying apollo.config.js
to the following seems to fix:
module.exports = {
client: {
service: {
name: 'Tracker API',
url: 'http://localhost:5001',
},
},
}
It looks like it's the includes
. Changing the line to the following fixes:
includes: ['./src/**/!(*.test).{ts,tsx,js,jsx}'],
Not sure if this is an issue or not. It happens that in my case I don't need to include anything outside of the src
folder. Could it be a lack of excludes
, and so it's scanning the node modules folder? This hasn't happened on previous projects.
I ran into this as well, after digging around through docs for a while the fix was actually pretty simple, I was mistakenly using the client config structure when I needed to use the server config structure.
// this one doesn't work
module.exports = {
client: {
service: {
addTypeName: false,
name: 'star-wars-api-overlay',
localSchemaFile: './src/schemas/schema.gql',
},
},
};
// This one works
module.exports = {
service: {
addTypeName: false,
localSchemaFile: './src/schemas/schema.gql',
},
};