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
+
2
6
const { Projects, Comments } = require ( '../../models/reactypeModels' ) ;
3
7
// Link to Apollo Query Types:
4
8
// https://www.apollographql.com/docs/apollo-server/data/resolvers/#defining-a-resolver
@@ -20,7 +24,7 @@ const Project = {
20
24
}
21
25
22
26
// 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' , {
24
28
argumentName : 'projId' ,
25
29
} ) ;
26
30
} ,
@@ -32,7 +36,7 @@ const Project = {
32
36
resp = resp . filter ( proj => proj . userId == userId ) ;
33
37
// if resp = [] after the filtering, this means the userId doesnt exisit in the database, throw error as follow
34
38
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` , {
36
40
argumentName : 'userId' ,
37
41
} ) ;
38
42
}
@@ -53,7 +57,7 @@ const Project = {
53
57
} ) ) ;
54
58
}
55
59
// resp is null, return error message
56
- throw new UserInputError ( 'Internal Server Error' ) ;
60
+ throw new ApolloServerErrorCode . BAD_USER_INPUT ( 'Internal Server Error' ) ;
57
61
} ,
58
62
} ;
59
63
0 commit comments