GraphQL - Syntax error: expected ":", found ")"
GraphQL - Syntax error: expected ":", found ")"
我正在开发一个使用 GraphQL 的项目,其中包含一些基本查询和变更。我已经以与过去相同的格式设置了 typeDef 和解析器,并且大多期望得到相同的结果。但是,当我尝试启动我的服务器时,出现以下错误。到目前为止,我已经从我的 typeDef 中一次一个地删除查询和变更,并且一次一个地注释掉解析器,但没有任何效果。我已经仔细阅读了错误位置,但一直无法真正找到任何信息来指出存在此语法错误的区域甚至文件。任何帮助都会非常有帮助!
$ npm start
> crm-tools@1.0.0 start E:\Coding_Bootcamp\projects\CRM-Tools\server
> node server.js
E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1413
throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
^
GraphQLError [Object]: Syntax Error: Expected ":", found ")".
at syntaxError (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\error\syntaxError.js:15:10)
at Parser.expectToken (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1413:40)
at Parser.parseInputValueDef (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:912:10)
at Parser.optionalMany (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1503:28)
at Parser.parseArgumentDefs (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:900:17)
at Parser.parseFieldDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:880:21)
at Parser.optionalMany (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1503:28)
at Parser.parseFieldsDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:868:17)
at Parser.parseObjectTypeDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:812:23)
at Parser.parseTypeSystemDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:708:23) {
locations: [ { line: 53, column: 25 } ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! crm-tools@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the crm-tools@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\shawn\AppData\Roaming\npm-cache\_logs21-07-02T03_23_00_391Z-debug.log
/typedefs.js
const { gql } = require('apollo-server-express');
// create our typeDefs
// TODO timecard formatting?
const typeDefs = gql`
type Employee {
_id: ID
firstName: String
lastName: String
street: String
city: String
state: String
zipcode: Int
email: String
phone: String
timeCards: [Int]
}
type Client {
_id: ID
firstName: String
lastName: String
street: String
city: String
state: String
zipcode: Int
email: String
phone: String
workOrders: [WorkOrder]
}
type WorkOrder {
_id: ID
date: String
description: String
notes: [String]
parts: [String]
invoice: String
timeClocks: [Int]
}
type Warehouse {
parts: [String]
laborItems: [String]
}
type Query {
me: Employee
employees(_id: ID): [Employee]
employee(_id: ID!): Employee
clients: [Client]
client(_id: ID!): Client
}
type Mutation {
addEmployee(Employee): Employee
}
`;
// export the typeDefs
module.exports = typeDefs;
resolvers.js
const { Client, Employee } = require('../models');
const resolvers = {
Query: {
// get all clients
clients: async () => {
return Client.find()
.populate("workOrders");
},
// get single client
client: async (parent, { _id }) => {
return Client.findOne({ _id })
//.populate("workOrders");
},
// get all employees
employees: async () => {
return Employee.find()
.populate("timeCards");
},
// get single employee
employee: async(parent, { _id }) => {
return Employee.findOne({ _id })
.populate("timeCards");
}
},
Mutation: {
addEmployee: async (parent, args) => {
const employee = await Employee.create(args);
}
}
};
module.exports = resolvers;
突变的定义不正确,它需要在类型之前有一个变量:
type Mutation {
addEmployee(employee: Employee): Employee
}
您可以通过 graphiql 插件或此 publicly available one.
验证 graphql 的语法
我正在开发一个使用 GraphQL 的项目,其中包含一些基本查询和变更。我已经以与过去相同的格式设置了 typeDef 和解析器,并且大多期望得到相同的结果。但是,当我尝试启动我的服务器时,出现以下错误。到目前为止,我已经从我的 typeDef 中一次一个地删除查询和变更,并且一次一个地注释掉解析器,但没有任何效果。我已经仔细阅读了错误位置,但一直无法真正找到任何信息来指出存在此语法错误的区域甚至文件。任何帮助都会非常有帮助!
$ npm start
> crm-tools@1.0.0 start E:\Coding_Bootcamp\projects\CRM-Tools\server
> node server.js
E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1413
throw (0, _syntaxError.syntaxError)(this._lexer.source, token.start, "Expected ".concat(getTokenKindDesc(kind), ", found ").concat(getTokenDesc(token), "."));
^
GraphQLError [Object]: Syntax Error: Expected ":", found ")".
at syntaxError (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\error\syntaxError.js:15:10)
at Parser.expectToken (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1413:40)
at Parser.parseInputValueDef (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:912:10)
at Parser.optionalMany (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1503:28)
at Parser.parseArgumentDefs (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:900:17)
at Parser.parseFieldDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:880:21)
at Parser.optionalMany (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:1503:28)
at Parser.parseFieldsDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:868:17)
at Parser.parseObjectTypeDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:812:23)
at Parser.parseTypeSystemDefinition (E:\Coding_Bootcamp\projects\CRM-Tools\server\node_modules\graphql\language\parser.js:708:23) {
locations: [ { line: 53, column: 25 } ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! crm-tools@1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the crm-tools@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\shawn\AppData\Roaming\npm-cache\_logs21-07-02T03_23_00_391Z-debug.log
/typedefs.js
const { gql } = require('apollo-server-express');
// create our typeDefs
// TODO timecard formatting?
const typeDefs = gql`
type Employee {
_id: ID
firstName: String
lastName: String
street: String
city: String
state: String
zipcode: Int
email: String
phone: String
timeCards: [Int]
}
type Client {
_id: ID
firstName: String
lastName: String
street: String
city: String
state: String
zipcode: Int
email: String
phone: String
workOrders: [WorkOrder]
}
type WorkOrder {
_id: ID
date: String
description: String
notes: [String]
parts: [String]
invoice: String
timeClocks: [Int]
}
type Warehouse {
parts: [String]
laborItems: [String]
}
type Query {
me: Employee
employees(_id: ID): [Employee]
employee(_id: ID!): Employee
clients: [Client]
client(_id: ID!): Client
}
type Mutation {
addEmployee(Employee): Employee
}
`;
// export the typeDefs
module.exports = typeDefs;
resolvers.js
const { Client, Employee } = require('../models');
const resolvers = {
Query: {
// get all clients
clients: async () => {
return Client.find()
.populate("workOrders");
},
// get single client
client: async (parent, { _id }) => {
return Client.findOne({ _id })
//.populate("workOrders");
},
// get all employees
employees: async () => {
return Employee.find()
.populate("timeCards");
},
// get single employee
employee: async(parent, { _id }) => {
return Employee.findOne({ _id })
.populate("timeCards");
}
},
Mutation: {
addEmployee: async (parent, args) => {
const employee = await Employee.create(args);
}
}
};
module.exports = resolvers;
突变的定义不正确,它需要在类型之前有一个变量:
type Mutation {
addEmployee(employee: Employee): Employee
}
您可以通过 graphiql 插件或此 publicly available one.
验证 graphql 的语法