Skip to content

Commit 358cb34

Browse files
committed
Use GraphQLError
1 parent 2455504 commit 358cb34

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

graphQLApollo/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { startStandaloneServer } from '@apollo/server/standalone';
44
// that together define the "shape" of queries that are executed against
55
// your data.
66
import { typeDefs } from './schema/schema.js';
7+
import { GraphQLError } from 'graphql';
78

89
// data
910
import db from './data/_db.js'
@@ -15,15 +16,20 @@ const resolvers = {
1516
return db.books
1617
},
1718
book(parent, args, context) {
18-
console.log(args.id)
19+
//console.log(parent, "\n", context)
1920
let result = db.books.find((b) => {
2021
return b.id === args.id
2122
})
22-
console.log("RESULT ", result)
23+
2324
if(result) {
2425
return result
2526
} else {
26-
return "ERROR"
27+
throw new GraphQLError('NOT FOUND', {
28+
extensions: {
29+
code: 'BAD_REQUESTPUT',
30+
argumentName: 'id',
31+
},
32+
});
2733
}
2834
}
2935
}

0 commit comments

Comments
 (0)