我一直在嘗試將大量Babel功能引入到我主要是手工編寫的React/GraphQL項目中。但是我試圖用這個構建腳本通過schema.graphql文件生成:NodeJS/Babel SyntaxError意外的令牌
import fs from 'fs';
import path from 'path';
import { graphql } from 'graphql';
import { introspectionQuery, printSchema } from 'graphql/utilities';
import schema from '../server/schema';
let file_schema_json = path.join(__dirname, '../graphql/schema.json');
let file_schema_graphql = path.join(__dirname, '../graphql/schema.graphql');
// Save JSON of full schema introspection for Babel Relay Plugin to use
async function createJson()
{
var result = await(graphql(schema, introspectionQuery));
if(result.errors)
{
console.error('ERROR! ');
console.error('ERROR introspecting schema: ', JSON.stringify(result.errors, null, 2));
}
else
{
fs.writeFileSync(file_schema_json, JSON.stringify(result, null, 2));
console.log('Written: ' + file_schema_json);
}
}
// Save user readable type system shorthand of schema
fs.writeFileSync(file_schema_graphql, printSchema(schema));
console.log('Written: ' + file_schema_graphql);
createJson();
,然後我結束了:
/Users/lorm/projects/aggregated_centralized_api/node_modules/babel-core/lib/transformation/file/index.js:591
throw err;
^
SyntaxError: /Users/lorm/projects/aggregated_centralized_api/scripts/build-schema.js: Unexpected token (12:6)
10 |
11 | // Save JSON of full schema introspection for Babel Relay Plugin to use
> 12 | async function createJson()
| ^
13 | {
14 | var result = await(graphql(schema, introspectionQuery));
15 | if(result.errors)
但我複製了所有我能想到的依賴關係:
"dependencies": {
"babel-cli": "^6.8.0",
"babel-core": "^6.8.0",
"babel-eslint": "^6.0.4",
"babel-loader": "^6.2.4",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-async-to-generator": "^6.8.0",
"babel-polyfill": "^6.8.0",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-relay-plugin": "^0.8.1",
"babel-relay-plugin-loader": "^0.8.1",
"babel-runtime": "^6.6.1",
"body-parser": "1.15.1",
"dataloader": "1.1.0",
"dotenv": "2.0.0",
"express": "4.13.4",
"express-graphql": "^0.5.3",
"graphql": "0.4.18",
"graphql-relay": "0.3.6",
"mongodb": "2.0.39",
"q": "1.4.1"
},
"devDependencies": {
"babel": "^5.8.3",
"babel-core": "^5.8.3",
"babel-eslint": "^4.0.5",
"babelify": "^6.1.1",
"babel-cli": "^6.8.0",
"babel-jest": "^12.0.2",
"babel-plugin-transform-runtime": "^6.8.0",
"babel-polyfill": "^6.8.0",
"eslint": "^0.24.0",
"eslint-plugin-react": "^3.2.2",
"flow-bin": "^0.22.1"
},
但仍然,它好像巴別沒有被觸發?或者不知道如何閱讀這種Javascript?什麼會導致這個錯誤?
「異步」在這裏工作:https://github.com/ codefoundries/UniversalRelayBoilerplate/blob/master/scripts/build-schema.js,但不在我的項目中。而且我從那裏複製了.babelrc,並且我已經複製了package.json的大部分內容。我不確定我錯過了什麼。 – lorm
您是否嘗試創建基於React Native的項目? – ctrlplusb
不,我只是想創建一個GraphQL API。 – lorm