0
votes

I have seen there are many questions related to mine, but unfortunately, none of them work for me. That is why I am asking my question since I am still learning GraphQL.

I am working on a Project with NestJS, GraphQL, and Angular. I am using the Apollo client and the Apollo server to implement GraphQL.My approach is code first to schema creation. I am getting an error while doing an update mutation. I am using PostgreSQL as the database

Here is the mutation section of the generated schema

type Mutation {
  updateVehicle(email: String!, vinNumber: String!, lastName: String!, firstName: String!, id: Int!): Vehicle!
  deleteVehicle(id: Int!): Vehicle!
}

Here is the resolver for update mutation

 @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) {
....
...
}

Here is the query that I tried on the playground of the apollo server.

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
  }
}

In the query variables section, I put my values like below

{
  "id": 2,
  "firstName":"test",
  "lastName": "test2",
  "vinNumber": "1234",
  "email": "[email protected]"
}

When I execute the query I am getting the below error message. Actually, I cannot figure out what it means.

{
  "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
}

I put the full error message for your reference. May I know the reason for this error? I tried changing the query and mutation as well. But it doesn't work. Appreciate your helpful response.

1
sth messed ... your query/mutation and error are from 2 different worlds/parts - looks like updateVehicle resolver makes internally a request updateVehicleById - broken query, missing args, etc - xadm
Inside my mutation, I call to a Postgraphile endpoint. It is updateVehicleById. The issue was in there. I solved it now. Thanks for your reply. - RYJ

1 Answers

1
votes

The code in this question is wrong, but the error makes it clear what the issue is:

  "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)"
      ]
    }
  }

specifically has the request block that shows that the query throwing the error is

{updateVehicleById(
      input: {vehiclePatch: {id: 2}
    ) {
      vehicle {
        ageOfVehicle  
        carMake 
        carModel 
        email
        firstName  
        id
        lastName
        manufacturedDate
        vinNumber
      }
    }}

The error says line 3 column 5 we can see the error is at ) { and looking closer, we can see the real error is on the previous line:

input: {vehiclePatch: {id: 2}

This input object has mismatched }, so it needs an extra } at the end of the line.