Created
May 7, 2016 22:37
-
-
Save czbaker/38dd153c7d098ead36fe9d3cee913aed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Amazon from 'amazon-product-api' | |
| import config from 'config' | |
| const AmazonClient = Amazon.createClient({ | |
| awsId: config.get('Amazon.AWS_ID'), | |
| awsSecret: config.get('Amazon.AWS_KEY'), | |
| awsTag: config.get('Amazon.AWS_TAG') | |
| }) | |
| export const schema = [` | |
| type AmazonBook { | |
| ISBN: String | |
| Title: String | |
| Author: [String] | |
| Pages: Int | |
| Publisher: String | |
| PublicationDate: String | |
| Image: String | |
| Result: String | |
| } | |
| type RootQuery { | |
| findByISBN(ISBN: String!): AmazonBook | |
| } | |
| schema { | |
| query: RootQuery | |
| } | |
| `] | |
| export const resolvers = { | |
| RootQuery: { | |
| findByISBN: (root, args, context) => { | |
| let ISBN = args.ISBN | |
| AmazonClient.itemLookup({ | |
| idType: "ISBN", | |
| itemId: ISBN, | |
| responseGroup: "ItemAttributes,Images" | |
| }).then((result) => { | |
| let attribs = result[0].ItemAttributes[0] | |
| return { | |
| ISBN: attribs.ISBN[0] | |
| } | |
| }) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment