Apollo服务器-GraphQL-语法错误:预期名称,已找到)
我看到有很多问题与我有关,但不幸的是,没有一个对我有用。这就是为什么我问我的问题,因为我还在学习GraphQL 我正在使用NestJS、GraphQL和Angular进行一个项目。我使用Apollo客户端和Apollo服务器来实现GraphQL。我的方法是先编写代码,然后创建模式。我在执行更新时出错。我使用PostgreSQL作为数据库 下面是生成的模式的突变部分Apollo服务器-GraphQL-语法错误:预期名称,已找到),graphql,nestjs,apollo-server,Graphql,Nestjs,Apollo Server,我看到有很多问题与我有关,但不幸的是,没有一个对我有用。这就是为什么我问我的问题,因为我还在学习GraphQL 我正在使用NestJS、GraphQL和Angular进行一个项目。我使用Apollo客户端和Apollo服务器来实现GraphQL。我的方法是先编写代码,然后创建模式。我在执行更新时出错。我使用PostgreSQL作为数据库 下面是生成的模式的突变部分 type Mutation { updateVehicle(email: String!, vinNumber: String!
type Mutation {
updateVehicle(email: String!, vinNumber: String!, lastName: String!, firstName: String!, id: Int!): Vehicle!
deleteVehicle(id: Int!): Vehicle!
}
这是更新的解析器
@Mutation(returns => Vehicle)
async updateVehicle(
@Args({name: 'id', type: () => Int }) id: number,
@Args({name: 'firstName', type: () => String }) firstName: string,
@Args({name: 'lastName', type: () => String }) lastName: string,
@Args({name: 'vinNumber', type: () => String }) vinNumber: string,
@Args({name: 'email', type: () => String }) email: string) {
....
...
}
这是我在阿波罗服务器的操场上尝试的查询
mutation MyMutation(
$id: Int!,
$email:String!,
$firstName:String!,
$lastName:String!,
$vinNumber:String!){
updateVehicle(
id: $id,
email: $email,
firstName: $firstName,
lastName: $lastName,
vinNumber: $vinNumber){
id
email
firstName
lastName
vinNumber
}
}
在查询变量部分,我将我的值放在下面
{
"id": 2,
"firstName":"test",
"lastName": "test2",
"vinNumber": "1234",
"email": "test@live.com"
}
当我执行查询时,我得到下面的错误消息。事实上,我不明白这是什么意思
{
"errors": [
{
"message": "Syntax Error: Expected Name, found \")\".: {\"response\":{\"errors\":[{\"message\":\"Syntax Error: Expected Name, found \\\")\\\".\",\"locations\":[{\"line\":3,\"column\":5}]}],\"status\":400},\"request\":{\"query\":\"{updateVehicleById(\\n input: {vehiclePatch: {id: 2}\\n ) {\\n vehicle {\\n ageOfVehicle \\n carMake \\n carModel \\n email\\n firstName \\n id\\n lastName\\n manufacturedDate\\n vinNumber\\n }\\n }}\"}}",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"updateVehicle"
],
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"response": {
"errors": [
{
"message": "Syntax Error: Expected Name, found \")\".",
"locations": [
{
"line": 3,
"column": 5
}
]
}
],
"status": 400
},
"request": {
"query": "{updateVehicleById(\n input: {vehiclePatch: {id: 2}\n ) {\n vehicle {\n ageOfVehicle \n carMake \n carModel \n email\n firstName \n id\n lastName\n manufacturedDate\n vinNumber\n }\n }}"
},
"stacktrace": [
"Error: Syntax Error: Expected Name, found \")\".: {\"response\":{\"errors\":[{\"message\":\"Syntax Error: Expected Name, found \\\")\\\".\",\"locations\":[{\"line\":3,\"column\":5}]}],\"status\":400},\"request\":{\"query\":\"{updateVehicleById(\\n input: {vehiclePatch: {id: 2}\\n ) {\\n vehicle {\\n ageOfVehicle \\n carMake \\n carModel \\n email\\n firstName \\n id\\n lastName\\n manufacturedDate\\n vinNumber\\n }\\n }}\"}}",
" at GraphQLClient.<anonymous> (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:170:35)",
" at step (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:63:23)",
" at Object.next (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:44:53)",
" at fulfilled (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:35:58)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
}
}
],
"data": null
}
{
“错误”:[
{
“消息”:“语法错误:预期名称,已找到\”\”\“:{”响应\“:{”错误\“:[{”消息\“:\“语法错误:预期名称,已找到\“\”\”\”\”\”,“位置\“:[{{”行\“:3,\“列\“:5}],“状态\“:400},\“请求\“:{”查询\“:\”:“{updateVehicleById(\\n输入:{vehiclebyid:{id:2\\n){{\\n ageOfVehicle\\n carMake\\n carModel\\n email\\n firstName\\n id\\n lastName\\n manufacturedDate\\n vinNumber\\n}\\n}\“}”,
“地点”:[
{
"线":2,,
“专栏”:3
}
],
“路径”:[
“UpdateHicle”
],
“扩展”:{
“代码”:“内部服务器错误”,
“例外情况”:{
“答复”:{
“错误”:[
{
“消息”:“语法错误:应为名称,找到\“\”\”,
“地点”:[
{
"行":3,,
“栏”:5
}
]
}
],
“地位”:400
},
“请求”:{
“查询:{UpdateHiclebyid(\n输入:{vehiclePatch:{id:2}\n){\n vehicle{\n ageOfVehicle\n carMake\n carModel\n email\n firstName\n id\n lastName\n manufacturedDate\n vinNumber\n}\n}”
},
“stacktrace”:[
“错误:语法错误:预期名称,已找到\“\””,“{”响应\“:{”错误\“:[{”消息\“:\“语法错误:预期名称,已找到\“\”\”\”,“位置\“:[{”行\“:3,\“列\“:5}],\”状态\“:400},\“请求\“:{”查询\“:\”{updateVehicleById(\\n输入:{vehiclebyid:{id:2\\n)\\\n){{\\n ageOfVehicle\\n carMake\\n carModel\\n email\\n firstName\\n id\\n lastName\\n manufacturedDate\\n vinNumber\\n}\\n}\“}”,
“在GraphQLClient上。(E:\\Virtusa\\vehicle management app\\vehicle-mgt-server3\\node\u modules\\graphql request\\dist\\index.js:170:35)”,
“在步骤(E:\\Virtusa\\vehicle management app\\vehicle-mgt-server3\\node\u modules\\graphql request\\dist\\index.js:63:23)”中,
“在Object.next(E:\\Virtusa\\vehicle management app\\vehicle-mgt-server3\\node\u modules\\graphql request\\dist\\index.js:44:53)”中,
“至少(E:\\Virtusa\\vehicle management app\\vehicle-mgt-server3\\node\u modules\\graphql request\\dist\\index.js:35:58)”,
“在处理和拒绝时(内部/process/task_queues.js:97:5)”
]
}
}
}
],
“数据”:空
}
我将完整的错误消息放在这里供您参考。我可以知道此错误的原因吗?我也尝试过更改查询和变异。但它不起作用。感谢您的帮助回答。此问题中的代码是错误的,但错误清楚地说明了问题所在:
"extensions": {
"code": "INTERNAL_SERVER_ERROR",
"exception": {
"response": {
"errors": [
{
"message": "Syntax Error: Expected Name, found \")\".",
"locations": [
{
"line": 3,
"column": 5
}
]
}
],
"status": 400
},
"request": {
"query": "{updateVehicleById(\n input: {vehiclePatch: {id: 2}\n ) {\n vehicle {\n ageOfVehicle \n carMake \n carModel \n email\n firstName \n id\n lastName\n manufacturedDate\n vinNumber\n }\n }}"
},
"stacktrace": [
"Error: Syntax Error: Expected Name, found \")\".: {\"response\":{\"errors\":[{\"message\":\"Syntax Error: Expected Name, found \\\")\\\".\",\"locations\":[{\"line\":3,\"column\":5}]}],\"status\":400},\"request\":{\"query\":\"{updateVehicleById(\\n input: {vehiclePatch: {id: 2}\\n ) {\\n vehicle {\\n ageOfVehicle \\n carMake \\n carModel \\n email\\n firstName \\n id\\n lastName\\n manufacturedDate\\n vinNumber\\n }\\n }}\"}}",
" at GraphQLClient.<anonymous> (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:170:35)",
" at step (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:63:23)",
" at Object.next (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:44:53)",
" at fulfilled (E:\\Virtusa\\vehicle-managment-app\\vehicle-mgt-server3\\node_modules\\graphql-request\\dist\\index.js:35:58)",
" at processTicksAndRejections (internal/process/task_queues.js:97:5)"
]
}
}
错误显示在第3行第5列,我们可以看到错误在){
,仔细看,我们可以看到真正的错误在前一行:
input: {vehiclePatch: {id: 2}
此输入对象的
}
不匹配,因此需要额外的}
在这行的末尾。有什么乱七八糟的…你的查询/变异和错误来自两个不同的世界/部分-看起来像updatehiclebile
解析器在内部发出一个请求updatehiclebyid
-断开的查询,缺少参数,等等。除了我的变异,我调用了Postgraphile端点。它是updatehiclebyid
问题就在那里。我现在解决了。谢谢你的回复。问题已经解决了,多亏了你。事实上,我忘了检查邮件查询。我真的很感谢你的快速回复。
input: {vehiclePatch: {id: 2}