{"size": 1661, "ext": "js", "max_stars_repo_path": "schema.js", "max_stars_repo_name": "nuhman/graphql-goodreads", "max_stars_repo_stars_event_min_datetime": "2019-10-01T04:49:46.000Z", "max_stars_repo_stars_event_max_datetime": "2019-10-01T04:49:46.000Z", "max_issues_repo_path": "schema.js", "max_issues_repo_name": "nuhman/graphql-goodreads", "max_issues_repo_issues_event_min_datetime": "2022-01-22T01:32:13.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T01:32:13.000Z", "max_forks_repo_path": "schema.js", "max_forks_repo_name": "nuhman/graphql-goodreads", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 25.953125, "max_line_length": 92, "alphanum_fraction": 0.4726068633}
const fetch = require('node-fetch')
const utlil = require('util')
const parseXML = utlil.promisify(require('xml2js').parseString)
const {
    GraphQLSchema,
    GraphQLObjectType,
    GraphQLInt,
    GraphQLString,
    GraphQLList
} = require('graphql');

api_key = 'oJWo7PjObM9vjK9zzBGJDw'

const BookType = new GraphQLObjectType({
    name: 'Books',
    description: '...',
    fields: () => ({
        title: {
            type: GraphQLString,  
            resolve: xml => xml.title[0]          
        },
        isbn: {
            type: GraphQLString,
            resolve: xml => xml.isbn[0]          
        }
    })
})

const AuthorType = new GraphQLObjectType({
    name: 'Author',
    description: '....',
    fields: () => ({
        name: {
            type:GraphQLString,
            resolve: xml => xml.GoodreadsResponse.author[0].name[0]
        },
        books: {
            type: new GraphQLList(BookType),
            resolve: xml => xml.GoodreadsResponse.author[0].books[0].book
        }
    })
})

module.exports = new GraphQLSchema({
    query: new GraphQLObjectType({
        name: 'query',
        description: '....',
        fields: () => ({
            author: {
                type: AuthorType,
                args: {
                    id: { type: GraphQLInt }
                },
                resolve: (root, args) => {
                    return fetch(                    
                    `https://www.goodreads.com/author/show.xml?id=${args.id}&key=${api_key}`
                )
                .then(response => response.text())
                .then(parseXML)
                }
            }
        })
    })
});