<commit_before>const fetch = require('node-fetch')
const util = require('util')
const parseXML = util.promisify(require('xml2js').parseString)
const api = require('./.env.json').api
const {
	GraphQLObjectType, GraphQLSchema, GraphQLInt, GraphQLString
} = require('graphql')

// const x = fetch(
// 	'https://www.goodreads.com/author/show.xml?id=4432&key=<KEY>'
// )
// .then(response => response.text())
// .then(parseXML)

const AuthorType = new GraphQLObjectType({
	name: 'Author',
	description: '...',

	fields: () => ({
		name: {
			type: GraphQLString,
			resolve: xml =>
			xml.GoodreadsResponse.author[0].name[0]
		}
	})

})

module.exports = new GraphQLSchema({
	query: new GraphQLObjectType({
		name: 'Query',
		description: '...',

		fields: () => ({
			author: {
				type: AuthorType,
				args: {
					id: { type: GraphQLInt }
				},
				resolve: (root, args) => fetch(
					`https://www.goodreads.com/author/show.xml?id=${args.id}&key=${api.key}`
				)
					.then(response => response.text())
					.then(parseXML)
			}

		})
	})
})<commit_msg>[graphql] book fetching<commit_after>const fetch = require('node-fetch')
const util = require('util')
const parseXML = util.promisify(require('xml2js').parseString)
const api = require('./.env.json').api
const {
	GraphQLObjectType,
	GraphQLSchema,
	GraphQLInt,
	GraphQLString,
	GraphQLList
} = require('graphql')

// const x = fetch(
// 	'https://www.goodreads.com/author/show.xml?id=4432&key=<KEY>'
// )
// .then(response => response.text())
// .then(parseXML)

const BookType = new GraphQLObjectType({
	name: 'book',
	description: '...',
	fields: () => ({
		title: {
			type: GraphQLString,
			resolve: item => item.title[0]
		},
		isbn: {
			type: GraphQLString,
			resolve: item => item.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) => fetch(
					`https://www.goodreads.com/author/show.xml?id=${args.id}&key=${api.key}`
				)
					.then(response => response.text())
					.then(parseXML)
			}

		})
	})
})
{'fraction_non_alphanumeric': 0.19385719984044675, 'fraction_numerical': 0.007179896290386917, 'mean_word_length': 3.3693379790940767, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5920452', 'n_tokens_mistral': 1033, 'n_tokens_neox': 903, 'n_words': 158}