Commit d40a316d by Nicolas Joyard

Remove graphene

parent f5547409
# -*- coding: utf-8 -*-
from flask_graphql import GraphQLView
from .schema import schema
class API(object):
def setup_routes(self, app, prefix='/graphql/'):
if not prefix.endswith('/'):
prefix = '%s/' % prefix
if not prefix.startswith('/'):
prefix = '/%s' % prefix
app.add_url_rule(
prefix,
view_func=GraphQLView.as_view(
'graphql',
schema=schema,
graphiql=True
)
)
# -*- coding: utf-8 -*-
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField
from ..models.an import (
Acte as ActeModel,
Acteur as ActeurModel,
ActeurAmendement as ActeurAmendementModel,
ActeurDocument as ActeurDocumentModel,
ActeurDossier as ActeurDossierModel,
ActeurReunion as ActeurReunionModel,
Amendement as AmendementModel,
Document as DocumentModel,
Dossier as DossierModel,
Legislature as LegislatureModel,
Mandat as MandatModel,
ODJItem as ODJItemModel,
ODJPoint as ODJPointModel,
Organe as OrganeModel,
OrganeDocument as OrganeDocumentModel,
OrganeDossier as OrganeDossierModel,
OrganeReunion as OrganeReunionModel,
Regime as RegimeModel,
Reunion as ReunionModel,
Scrutin as ScrutinModel,
ScrutinGroupe as ScrutinGroupeModel,
Theme as ThemeModel,
Votant as VotantModel,
)
from ..models.parlapi import Job as JobModel
class Acte(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ActeModel
class Acteur(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ActeurModel
class ActeurAmendement(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ActeurAmendementModel
class ActeurDocument(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ActeurDocumentModel
class ActeurDossier(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ActeurDossierModel
class ActeurReunion(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ActeurReunionModel
class Amendement(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = AmendementModel
class Document(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = DocumentModel
class Dossier(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = DossierModel
class Job(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = JobModel
class Legislature(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = LegislatureModel
class Mandat(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = MandatModel
class ODJItem(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ODJItemModel
class ODJPoint(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ODJPointModel
class Organe(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = OrganeModel
class OrganeDocument(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = OrganeDocumentModel
class OrganeDossier(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = OrganeDossierModel
class OrganeReunion(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = OrganeReunionModel
class Regime(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = RegimeModel
class Reunion(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ReunionModel
class Scrutin(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ScrutinModel
class ScrutinGroupe(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ScrutinGroupeModel
class Theme(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = ThemeModel
class Votant(SQLAlchemyObjectType):
class Meta:
exclude_fields = ('search_vector',)
interfaces = (relay.Node,)
model = VotantModel
class Query(graphene.ObjectType):
node = relay.Node.Field()
all_actes = SQLAlchemyConnectionField(Acte)
all_acteurs = SQLAlchemyConnectionField(Acteur)
all_amendements = SQLAlchemyConnectionField(Amendement)
all_documents = SQLAlchemyConnectionField(Document)
all_dossiers = SQLAlchemyConnectionField(Dossier)
all_jobs = SQLAlchemyConnectionField(Job)
all_legislatures = SQLAlchemyConnectionField(Legislature)
all_mandats = SQLAlchemyConnectionField(Mandat)
all_organes = SQLAlchemyConnectionField(Organe)
all_regimes = SQLAlchemyConnectionField(Regime)
all_reunions = SQLAlchemyConnectionField(Reunion)
all_scrutins = SQLAlchemyConnectionField(Scrutin)
all_themes = SQLAlchemyConnectionField(Theme)
schema = graphene.Schema(
query=Query,
types=[
Acte,
Acteur,
ActeurAmendement,
ActeurDocument,
ActeurDossier,
ActeurReunion,
Amendement,
Document,
Dossier,
Job,
Legislature,
Mandat,
ODJItem,
ODJPoint,
Organe,
OrganeDocument,
OrganeDossier,
OrganeReunion,
Regime,
Reunion,
Scrutin,
ScrutinGroupe,
Theme,
Votant,
]
)
# -*- coding: utf-8 -*-
from .api import API
def setup_api(app):
return API()
......@@ -9,12 +9,9 @@ import humanize
from .models.parlapi import Job
def setup_routes(app, rest_api, graphql_api):
def setup_routes(app, rest_api):
rest_api.setup_routes(app, '/rest/')
graphql_prefix = '/graphql/'
graphql_api.setup_routes(app, graphql_prefix)
@app.template_filter('humanize_seconds')
def humanize_seconds(seconds):
if not seconds:
......@@ -55,6 +52,5 @@ def setup_routes(app, rest_api, graphql_api):
'an': u'Assemblée nationale',
'parlapi': 'ParlAPI'
},
graphql_prefix=graphql_prefix,
jobs=Job.query.all()
)
......@@ -26,13 +26,9 @@ def setup_app(name):
from .rest.setup import setup_api as setup_rest_api
rest_api = setup_rest_api(app)
# Setup GraphQL API
from .graphql.setup import setup_api as setup_graphql_api
graphql_api = setup_graphql_api(app)
# Setup routes
from .routes import setup_routes
setup_routes(app, rest_api, graphql_api)
setup_routes(app, rest_api)
# Enable Markdown
Markdown(app)
......
......@@ -77,7 +77,7 @@
</section>
</div>
<div class="col-md-6">
<div class="col-md-12">
<section class="panel panel-default">
<header class="panel-heading">
<b>Sources de données</b>
......@@ -117,31 +117,6 @@
</section>
</div>
<div class="col-md-6">
<section class="panel panel-default">
<header class="panel-heading">
<b>API GraphQL</b>
</header>
<article class="panel-body">
<p>Cette API donne accès au schéma de données via des requêtes GraphQL.</p>
<p>Lorsqu'il est utilisé depuis un navigateur web, le point d'entrée ci-dessous présente une interface de requétage avec auto-complétion et une documentation auto-générée du modèle.</p>
<p><a href="{{ graphql_prefix }}{% raw %}?query={%0A allActeurs(first%3A 10) {%0A edges {%0A node {%0A civilite%0A nom%0A prenom%0A mandats(first%3A 1) {%0A edges {%0A node {%0A qualite%0A organes {%0A edges {%0A node {%0A libelle%0A }%0A }%0A }%0A }%0A }%0A }%0A }%0A }%0A }%0A}%0A{% endraw %}">Cliquez ici</a> pour ouvrir l'interface avec un exemple de requête permettant de lister les 10 premiers acteurs et leur 1er mandat, avec seulement certains champs renvoyés.</p>
</article>
<table class="table table-striped table-responsive">
<tr>
<th>Description</th>
<th>Point d'entrée API</th>
</tr>
<tr>
<td>Point d'entrée GraphQL</td>
<td><a href="{{ graphql_prefix }}"><code>{{ graphql_prefix }}</code></a></td>
</tr>
</table>
</section>
</div>
<div class="col-md-12">
</div>
......
......@@ -29,7 +29,6 @@ setup(
'flask-marshmallow>=0.7,<0.8',
'flask-script>=2.0,<3',
'flask-sqlalchemy>=2.1,<3',
'graphene_sqlalchemy>=1.0,<2',
'html5lib>=0.9999999,<1',
'humanize>=0.5,<1',
'ijson>=2.3,<3',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment