File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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.
66import { typeDefs } from './schema/schema.js' ;
7+ import { GraphQLError } from 'graphql' ;
78
89// data
910import 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 }
You can’t perform that action at this time.
0 commit comments