Skip to content

Instantly share code, notes, and snippets.

@czbaker
Created May 7, 2016 22:37
Show Gist options
  • Select an option

  • Save czbaker/38dd153c7d098ead36fe9d3cee913aed to your computer and use it in GitHub Desktop.

Select an option

Save czbaker/38dd153c7d098ead36fe9d3cee913aed to your computer and use it in GitHub Desktop.
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