Skip to content

Commit

Permalink
[MIG] [16.0] base_graphql
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Conjour committed Jan 3, 2023
1 parent 3a4af23 commit 0f0b8bf
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 34 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ exclude: |
^base_rest_pydantic/|
^datamodel/|
^extendable/|
^graphql_base/|
^graphql_demo/|
^model_serializer/|
^pydantic/|
Expand Down
10 changes: 2 additions & 8 deletions graphql_base/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Graphql Base
:target: https://runbot.odoo-community.org/runbot/271/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This modules enables the creation of `GraphQL <https://graphql.org/>`__ endpoints.
In itself, it does nothing and must be used by a developer to
Expand Down Expand Up @@ -96,12 +96,6 @@ endpoints.
def graphiql(self, **kwargs):
return self._handle_graphiql_request(schema)
# Optional monkey patch, needed to accept application/json GraphQL
# requests. If you only need to accept GET requests or POST
# with application/x-www-form-urlencoded content,
# this is not necessary.
GraphQLControllerMixin.patch_for_json("^/graphql/demo/?$")
# The graphql route, for applications.
# Note csrf=False: you may want to apply extra security
# (such as origin restrictions) to this route.
Expand Down Expand Up @@ -146,7 +140,7 @@ promote its widespread use.

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sbidoul|
|maintainer-sbidoul|

This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/14.0/graphql_base>`_ project on GitHub.

Expand Down
4 changes: 2 additions & 2 deletions graphql_base/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Graphql Base",
"summary": """
Base GraphQL/GraphiQL controller""",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/rest-framework",
Expand All @@ -14,5 +14,5 @@
"external_dependencies": {"python": ["graphene", "graphql_server"]},
"development_status": "Production/Stable",
"maintainers": ["sbidoul"],
"installable": False,
"installable": True,
}
18 changes: 1 addition & 17 deletions graphql_base/controllers/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright 2018 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import re
from functools import partial

from graphql_server import (
Expand All @@ -17,21 +16,6 @@


class GraphQLControllerMixin(object):
@staticmethod
def patch_for_json(path_re):
# this is to avoid Odoo, which assumes json always means json+rpc,
# complaining about "function declared as capable of handling request
# of type 'http' but called with a request of type 'json'"
path_re = re.compile(path_re)
orig_get_request = http.Root.get_request

def get_request(self, httprequest):
if path_re.match(httprequest.path):
return http.HttpRequest(httprequest)
return orig_get_request(self, httprequest)

http.Root.get_request = get_request

def _parse_body(self):
req = http.request.httprequest
# We use mimetype here since we don't need the other
Expand Down Expand Up @@ -77,7 +61,7 @@ def _process_request(self, schema, data):
return response
except HttpQueryError as e:
result = json_encode({"errors": [{"message": str(e)}]})
headers = dict(e.headers)
headers = dict()
headers["Content-Type"] = "application/json"
response = http.request.make_response(result, headers=headers)
response.status_code = e.status_code
Expand Down
6 changes: 0 additions & 6 deletions graphql_base/readme/USAGE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ endpoints.
def graphiql(self, **kwargs):
return self._handle_graphiql_request(schema)
# Optional monkey patch, needed to accept application/json GraphQL
# requests. If you only need to accept GET requests or POST
# with application/x-www-form-urlencoded content,
# this is not necessary.
GraphQLControllerMixin.patch_for_json("^/graphql/demo/?$")
# The graphql route, for applications.
# Note csrf=False: you may want to apply extra security
# (such as origin restrictions) to this route.
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# generated from manifests external_dependencies
graphene
graphql_server
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,
)

0 comments on commit 0f0b8bf

Please sign in to comment.