Skip to content

Commit f3bb3fe

Browse files
committed
Add some logic
1 parent 0b37b94 commit f3bb3fe

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

graphQLApollo/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,24 @@ const resolvers = {
1515
books() {
1616
return db.books
1717
},
18+
authors() {
19+
return db.authors
20+
},
21+
addressAuthor(parent, args, context) {
22+
let resAddress = db.authors.find(author => {
23+
return author.name === args.name
24+
})
25+
if(resAddress) {
26+
return resAddress
27+
} else {
28+
throw new GraphQLError('NOT FOUND', {
29+
extensions: {
30+
code: 'BAD_REQUEST',
31+
argumentName: 'name',
32+
},
33+
});
34+
}
35+
},
1836
book(parent, args, context) {
1937
//console.log(parent, "\n", context)
2038
let result = db.books.find((b) => {

graphQLApollo/schema/schema.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,7 @@ export const typeDefs = `#graphql
2424
type Query {
2525
books: [Book]
2626
book(id: Int!): Book
27+
authors: [Author]
28+
addressAuthor(name: String!): Address
2729
}
2830
`

0 commit comments

Comments
 (0)