Skip to content

Commit

Permalink
[MIG] Migration to version 14.0: graphql_base
Browse files Browse the repository at this point in the history
  • Loading branch information
qgroulard committed Dec 15, 2021
1 parent feb7b91 commit ca9d509
Show file tree
Hide file tree
Showing 13 changed files with 48 additions and 24 deletions.
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^graphql_base/|
^graphql_demo/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
Expand Down
8 changes: 4 additions & 4 deletions graphql_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"name": "Graphql Base",
"summary": """
Base GraphQL/GraphiQL controller""",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/rest-framework",
"depends": ["base"],
"data": ["views/graphiql.xml"],
"external_dependencies": {"python": ["graphene", "graphql-server-core"]},
"development_status": "Beta",
"external_dependencies": {"python": ["graphene", "graphql_server"]},
"development_status": "Production/Stable",
"maintainers": ["sbidoul"],
"installable": False,
"installable": True,
}
8 changes: 4 additions & 4 deletions graphql_base/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

from graphql_server import (
HttpQueryError,
default_format_error,
encode_execution_results,
format_error_default,
json_encode,
load_json_body,
run_http_query,
Expand Down Expand Up @@ -58,12 +58,12 @@ def _process_request(self, schema, data):
query_data=request.args,
batch_enabled=False,
catch=False,
context={"env": http.request.env},
context_value={"env": http.request.env},
)
result, status_code = encode_execution_results(
execution_results,
is_batch=isinstance(data, list),
format_error=default_format_error,
format_error=format_error_default,
encode=partial(json_encode, pretty=False),
)
headers = dict()
Expand All @@ -76,7 +76,7 @@ def _process_request(self, schema, data):
env.clear()
return response
except HttpQueryError as e:
result = json_encode({"errors": [default_format_error(e)]})
result = json_encode({"errors": [{"message": str(e)}]})
headers = dict(e.headers)
headers["Content-Type"] = "application/json"
response = http.request.make_response(result, headers=headers)
Expand Down
21 changes: 14 additions & 7 deletions graphql_base/views/graphiql.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2018 ACSONE SA/NV
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
Expand Down Expand Up @@ -28,13 +28,20 @@
If you do not want to rely on a CDN, you can host these files locally or
include them directly in your favored resource bunder.
-->
<link href="//cdn.jsdelivr.net/npm/[email protected]/graphiql.css" rel="stylesheet"/>
<script src="//cdn.jsdelivr.net/npm/[email protected]/fetch.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/[email protected]/umd/react.production.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.production.min.js"></script>
<script src="//cdn.jsdelivr.net/npm/[email protected]/graphiql.min.js"></script>
<link
href="//cdn.jsdelivr.net/npm/[email protected]/graphiql.css"
rel="stylesheet"
/>
<script src="//cdn.jsdelivr.net/npm/[email protected]/fetch.min.js" />
<script
src="//cdn.jsdelivr.net/npm/[email protected]/umd/react.production.min.js"
/>
<script
src="//cdn.jsdelivr.net/npm/[email protected]/umd/react-dom.production.min.js"
/>
<script src="//cdn.jsdelivr.net/npm/[email protected]/graphiql.min.js" />
</t>
<t t-set="head" t-value="head"/>
<t t-set="head" t-value="head" />
</t>
<body>
<div id="graphiql">Loading...</div>
Expand Down
4 changes: 2 additions & 2 deletions graphql_demo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

{
"name": "GraphQL Demo",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/rest-framework",
"depends": ["graphql_base"],
"external_dependencies": {"python": ["graphene"]},
"development_status": "Beta",
"maintainers": ["sbidoul"],
"installable": False,
"installable": True,
}
4 changes: 2 additions & 2 deletions graphql_demo/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GraphQLController(http.Controller, GraphQLControllerMixin):
# The GraphiQL route, providing an IDE for developers
@http.route("/graphiql/demo", auth="user")
def graphiql(self, **kwargs):
return self._handle_graphiql_request(schema)
return self._handle_graphiql_request(schema.graphql_schema)

# Optional monkey patch, needed to accept application/json GraphQL
# requests. If you only need to accept GET requests or POST
Expand All @@ -26,4 +26,4 @@ def graphiql(self, **kwargs):
# (such as origin restrictions) to this route.
@http.route("/graphql/demo", auth="user", csrf=False)
def graphql(self, **kwargs):
return self._handle_graphql_request(schema)
return self._handle_graphql_request(schema.graphql_schema)
8 changes: 5 additions & 3 deletions graphql_demo/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
from werkzeug.urls import url_encode

from odoo.tests import HttpCase
from odoo.tests.common import HOST, PORT
from odoo.tools import mute_logger
from odoo.tests.common import HOST
from odoo.tools import config, mute_logger


class TestController(HttpCase):
def url_open_json(self, url, json):
return self.opener.post("http://{}:{}{}".format(HOST, PORT, url), json=json)
return self.opener.post(
"http://{}:{}{}".format(HOST, config["http_port"], url), json=json
)

def _check_all_partners(self, all_partners, companies_only=False):
domain = []
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
apispec
apispec>=4.0.0
cerberus
graphene
graphql_server
jsondiff
marshmallow
marshmallow-objects>=2.0.0
Expand Down
1 change: 1 addition & 0 deletions setup/graphql_base/odoo/addons/graphql_base
6 changes: 6 additions & 0 deletions setup/graphql_base/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions setup/graphql_demo/odoo/addons/graphql_demo
6 changes: 6 additions & 0 deletions setup/graphql_demo/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
promise # Needed by graphene.test.Client

0 comments on commit ca9d509

Please sign in to comment.