-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbasic_types.py
50 lines (42 loc) · 1.36 KB
/
basic_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import graphene
from graphene.types.resolver import dict_resolver
from pymongo import MongoClient
client = MongoClient()
reviews_collection = client.goodreads.reviews
class Review(graphene.ObjectType):
class Meta:
default_resolver = dict_resolver
_id = graphene.ID()
bookId = graphene.ID()
rate = graphene.Float()
text = graphene.String()
likes = graphene.Int()
class Book(graphene.ObjectType):
class Meta:
default_resolver = dict_resolver
bookId = graphene.ID()
workId = graphene.Int()
title = graphene.String()
originalTitle = graphene.String()
isbn = graphene.String()
isbn13 = graphene.Int()
authors = graphene.List(graphene.String)
publicationYear = graphene.Int()
languageCode = graphene.String()
avgRating = graphene.Float()
ratingsCount = graphene.Int()
workRatingsCount = graphene.Int()
workTextReviewsCount = graphene.Int()
ratings1 = graphene.Int()
ratings2 = graphene.Int()
ratings3 = graphene.Int()
ratings4 = graphene.Int()
ratings5 = graphene.Int()
coverURL = graphene.String()
smallCoverURL = graphene.String()
description = graphene.String()
reviews = graphene.List(Review)
@classmethod
def resolve_reviews(self, root, info, **kwargs):
results = reviews_collection.find({'bookId': root['bookId']})
return results