Skip to content

Commit 3d8299b

Browse files
committed
code migration for apollo v4 error handling syntax
1 parent 2ba0813 commit 3d8299b

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@
141141
"@types/react-redux": "^7.1.24",
142142
"@types/react-router-dom": "^5.3.3",
143143
"ace-builds": "^1.8.1",
144-
"apollo-server": "^3.0.0",
145-
"apollo-server-core": "^3.12.0",
146-
"apollo-server-express": "^3.12.0",
147144
"app-root-path": "^3.0.0",
148145
"autoprefixer": "^10.4.8",
149146
"babel-polyfill": "^6.26.0",

server/graphQL/resolvers/query.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
const { UserInputError } = require('apollo-server-express');
1+
// const { UserInputError } = require('apollo-server-express');//v3 syntax
2+
3+
import { ApolloServerErrorCode } from '@apollo/server/errors';// v4 syntax
4+
//now using ApolloServerErrorCode.BAD_USER_INPUT in place of UserInputError
5+
26
const { Projects, Comments } = require('../../models/reactypeModels');
37
// Link to Apollo Query Types:
48
// https://www.apollographql.com/docs/apollo-server/data/resolvers/#defining-a-resolver
@@ -20,7 +24,7 @@ const Project = {
2024
}
2125

2226
// resp is null if nothing is found based on the project ID
23-
throw new UserInputError('Project is not found. Please try another project ID', {
27+
throw new ApolloServerErrorCode.BAD_USER_INPUT('Project is not found. Please try another project ID', {
2428
argumentName: 'projId',
2529
});
2630
},
@@ -32,7 +36,7 @@ const Project = {
3236
resp = resp.filter(proj => proj.userId == userId);
3337
// if resp = [] after the filtering, this means the userId doesnt exisit in the database, throw error as follow
3438
if (resp.length === 0) {
35-
throw new UserInputError(`Project for userId: "${userId}". Please try another id`, {
39+
throw new ApolloServerErrorCode.BAD_USER_INPUT(`Project for userId: "${userId}". Please try another id`, {
3640
argumentName: 'userId',
3741
});
3842
}
@@ -53,7 +57,7 @@ const Project = {
5357
}));
5458
}
5559
// resp is null, return error message
56-
throw new UserInputError('Internal Server Error');
60+
throw new ApolloServerErrorCode.BAD_USER_INPUT('Internal Server Error');
5761
},
5862
};
5963

0 commit comments

Comments
 (0)