-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (31 loc) · 1.16 KB
/
app.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
from flask import Flask
from flask_graphql import GraphQLView
from flask_cors import CORS
from scrapes import get_page_length, get_link_data, get_story_data
import graphene
app = Flask(__name__)
CORS(app)
class Link(graphene.ObjectType):
href = graphene.String()
content = graphene.String()
class Story(graphene.ObjectType):
headline = graphene.String()
by = graphene.String()
date = graphene.Date()
tags = graphene.List(graphene.String)
content = graphene.List(graphene.String)
href = graphene.String()
class Query(graphene.ObjectType):
pages = graphene.Int()
links = graphene.List(Link, index=graphene.Int(default_value=2))
story = graphene.Field(Story, url=graphene.String(required=True))
def resolve_pages(self, info):
return get_page_length()
def resolve_links(self, info, index: int):
return get_link_data(index)
def resolve_story(self, info, url: str):
return get_story_data(url)
schema = graphene.Schema(query=Query)
app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True))
if __name__ == "__main__":
app.run(debug=True)