-
-
Notifications
You must be signed in to change notification settings - Fork 356
[18.0][MIG] graphql_demo: Migration to 18.0 #475
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ajay-odoogap
wants to merge
44
commits into
OCA:18.0
Choose a base branch
from
odoogap:18.0-mig-graphql_demo
base: 18.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
e063670
[ADD] graphql_base and graphql_demo
sbidoul a7d9f5c
graphql_demo: improve schema, add mutation example
sbidoul 5afb73a
graphql_demo: clarify controller example
sbidoul 8a292c5
graphql_demo: tests
sbidoul ba8b570
graphql: more documentation
sbidoul 8db1b0b
graphql: add development_status and maintainers
sbidoul 67e74d5
graphql: improve and test error handling
sbidoul 4094b30
graphql: silence false travis error
sbidoul 75b9074
graphql: test json input
sbidoul 4c372c9
graphql: test response content type
sbidoul 55373f6
graphql: improve error case test
sbidoul 4e36e89
graphql_demo: add usage instructions
sbidoul 4924566
graphql: fix typos in documentation
sbidoul 2924093
fixup! fix errors in unreached code
sbidoul 92a4778
[UPD] README.rst
OCA-git-bot 3b015cd
[IMP] graphql_demo: add limit/offset example
sbidoul afe30ee
[IMP] graphql_demo: add mutation documentation example
sbidoul 58ccea0
[IMP] graphql_demo: add standalone mutation test
sbidoul 5b87b50
[FIX] graphql: controller must rollback in case of error
sbidoul 97e4ffb
[FIX] graphql: readme lint
sbidoul 94455f3
[ADD] icon.png
OCA-git-bot 6a63c21
[UPD] README.rst
OCA-git-bot cfa3455
black, isort pre-commit
lmignon 1e7dac1
[MIG] 13.0 branch creation
lmignon e8673a4
[MIG] graphql_base, graphql_demo from 12 to 13
sbidoul d6939cc
[UPD] README.rst
OCA-git-bot 9141697
Initialize 14.0 branch
lmignon 311e86f
[MIG] Migration to version 14.0: graphql_base
qgroulard e2ce088
[UPD] Update graphql_demo.pot
oca-travis f876e68
[UPD] README.rst
OCA-git-bot 0b237ff
Forward port from 14.0
lmignon fecb393
[MIG] [16.0] graphql_demo
377b5f5
[UPD] Update graphql_demo.pot
b1ed0d4
[UPD] README.rst
OCA-git-bot d0596d7
graphql_demo 16.0.1.0.1
OCA-git-bot 79d3523
[UPD] README.rst
OCA-git-bot 2563813
[MIG] mark all modules installable=False
sbidoul a85e170
[MIG] graphql_base: Migration to 17.0
dduarte-odoogap a997daf
[UPD] Update graphql_demo.pot
e5517bd
[ADD] dependency on pr 474 to run tests
OCA-git-bot 07ae25e
Merge branch '18.0' into 18.0-mig-graphql_demo
ajay-odoogap 052fbfb
Merge branch '18.0' into 18.0-mig-graphql_demo
ajay-odoogap 62e2118
[FIX] pre commit error
ajay-odoogap 2e480aa
[FIX] module version
ajay-odoogap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| ============ | ||
| GraphQL Demo | ||
| ============ | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:c346b472bba4541d33184c35cf66ba333c2a01b1e0fe15aeaf76c9283ff22389 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png | ||
| :target: https://odoo-community.org/page/development-status | ||
| :alt: Beta | ||
| .. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png | ||
| :target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
| :alt: License: LGPL-3 | ||
| .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/rest-framework/tree/17.0/graphql_demo | ||
| :alt: OCA/rest-framework | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/rest-framework-17-0/rest-framework-17-0-graphql_demo | ||
| :alt: Translate me on Weblate | ||
| .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
| :target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=17.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| This is a demonstration module providing a sample GraphQL endpoint, as | ||
| well as tests for ``graphql_base``. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Usage | ||
| ===== | ||
|
|
||
| This module can be used in different ways: | ||
|
|
||
| - as an example: copy the code and hack your way; | ||
| - to test ``graphql_base`` (install it with ``--test-enable``); | ||
| - on runbot, login and change the url to ``/graphiql/demo``. | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_. | ||
| In case of trouble, please check there if your issue has already been reported. | ||
| If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
| `feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20graphql_demo%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
|
||
| Do not contact contributors directly about support or help with technical issues. | ||
|
|
||
| Credits | ||
| ======= | ||
|
|
||
| Authors | ||
| ------- | ||
|
|
||
| * ACSONE SA/NV | ||
|
|
||
| Maintainers | ||
| ----------- | ||
|
|
||
| This module is maintained by the OCA. | ||
|
|
||
| .. image:: https://odoo-community.org/logo.png | ||
| :alt: Odoo Community Association | ||
| :target: https://odoo-community.org | ||
|
|
||
| OCA, or the Odoo Community Association, is a nonprofit organization whose | ||
| mission is to support the collaborative development of Odoo features and | ||
| promote its widespread use. | ||
|
|
||
| .. |maintainer-sbidoul| image:: https://github.com/sbidoul.png?size=40px | ||
| :target: https://github.com/sbidoul | ||
| :alt: sbidoul | ||
|
|
||
| Current `maintainer <https://odoo-community.org/page/maintainer-role>`__: | ||
|
|
||
| |maintainer-sbidoul| | ||
|
|
||
| This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/17.0/graphql_demo>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import controllers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Copyright 2018 ACSONE SA/NV | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| { | ||
| "name": "GraphQL Demo", | ||
| "version": "17.0.1.0.1", | ||
| "license": "LGPL-3", | ||
| "author": "ACSONE SA/NV, Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/rest-framework", | ||
| "depends": ["graphql_base"], | ||
| "development_status": "Beta", | ||
| "maintainers": ["sbidoul"], | ||
| "installable": True, | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from . import main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Copyright 2018 ACSONE SA/NV | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| from odoo import http | ||
|
|
||
| from odoo.addons.graphql_base import GraphQLControllerMixin | ||
|
|
||
| from ..schema import schema | ||
|
|
||
|
|
||
| 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.graphql_schema) | ||
|
|
||
| # The graphql route, for applications. | ||
| # Note csrf=False: you may want to apply extra security | ||
| # (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.graphql_schema) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| # Translation of Odoo Server. | ||
| # This file contains the translation of the following modules: | ||
| # * graphql_demo | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 17.0\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "Last-Translator: \n" | ||
| "Language-Team: \n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: \n" | ||
|
|
||
| #. module: graphql_demo | ||
| #. odoo-python | ||
| #: code:addons/graphql_demo/schema.py:0 | ||
| #, python-format | ||
| msgid "UserError example" | ||
| msgstr "" | ||
|
|
||
| #. module: graphql_demo | ||
| #. odoo-python | ||
| #: code:addons/graphql_demo/schema.py:0 | ||
| #, python-format | ||
| msgid "as requested" | ||
| msgstr "" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Translation of Odoo Server. | ||
| # This file contains the translation of the following modules: | ||
| # * graphql_demo | ||
| # | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: Odoo Server 16.0\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "PO-Revision-Date: 2024-07-01 11:47+0000\n" | ||
| "Last-Translator: mymage <[email protected]>\n" | ||
| "Language-Team: none\n" | ||
| "Language: it\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: nplurals=2; plural=n != 1;\n" | ||
| "X-Generator: Weblate 4.17\n" | ||
|
|
||
| #. module: graphql_demo | ||
| #. odoo-python | ||
| #: code:addons/graphql_demo/schema.py:0 | ||
| #, python-format | ||
| msgid "UserError example" | ||
| msgstr "Esempio errore utente" | ||
|
|
||
| #. module: graphql_demo | ||
| #. odoo-python | ||
| #: code:addons/graphql_demo/schema.py:0 | ||
| #, python-format | ||
| msgid "as requested" | ||
| msgstr "come richiesto" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [build-system] | ||
| requires = ["whool"] | ||
| build-backend = "whool.buildapi" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| This is a demonstration module providing a sample GraphQL endpoint, as | ||
| well as tests for `graphql_base`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| This module can be used in different ways: | ||
|
|
||
| - as an example: copy the code and hack your way; | ||
| - to test `graphql_base` (install it with `--test-enable`); | ||
| - on runbot, login and change the url to `/graphiql/demo`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| # Copyright 2018 ACSONE SA/NV | ||
| # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). | ||
|
|
||
| # disable undefined variable error, which erroneously triggers | ||
| # on forward declarations of classes in lambdas | ||
| # pylint: disable=E0602 | ||
|
|
||
| import graphene | ||
|
|
||
| from odoo import _ | ||
| from odoo.exceptions import UserError | ||
|
|
||
| from odoo.addons.graphql_base import OdooObjectType | ||
|
|
||
|
|
||
| class Country(OdooObjectType): | ||
| code = graphene.String(required=True) | ||
| name = graphene.String(required=True) | ||
|
|
||
|
|
||
| class Partner(OdooObjectType): | ||
| name = graphene.String(required=True) | ||
| street = graphene.String() | ||
| street2 = graphene.String() | ||
| city = graphene.String() | ||
| zip = graphene.String() | ||
| country = graphene.Field(Country) | ||
| email = graphene.String() | ||
| phone = graphene.String() | ||
| is_company = graphene.Boolean(required=True) | ||
| contacts = graphene.List(graphene.NonNull(lambda: Partner), required=True) | ||
|
|
||
| @staticmethod | ||
| def resolve_country(root, info): | ||
| return root.country_id or None | ||
|
|
||
| @staticmethod | ||
| def resolve_contacts(root, info): | ||
| return root.child_ids | ||
|
|
||
|
|
||
| class Query(graphene.ObjectType): | ||
| all_partners = graphene.List( | ||
| graphene.NonNull(Partner), | ||
| required=True, | ||
| companies_only=graphene.Boolean(), | ||
| limit=graphene.Int(), | ||
| offset=graphene.Int(), | ||
| ) | ||
|
|
||
| reverse = graphene.String( | ||
| required=True, | ||
| description="Reverse a string", | ||
| word=graphene.String(required=True), | ||
| ) | ||
|
|
||
| error_example = graphene.String() | ||
|
|
||
| @staticmethod | ||
| def resolve_all_partners(root, info, companies_only=False, limit=None, offset=None): | ||
| domain = [] | ||
| if companies_only: | ||
| domain.append(("is_company", "=", True)) | ||
| return info.context["env"]["res.partner"].search( | ||
| domain, limit=limit, offset=offset | ||
| ) | ||
|
|
||
| @staticmethod | ||
| def resolve_reverse(root, info, word): | ||
| return word[::-1] | ||
|
|
||
| @staticmethod | ||
| def resolve_error_example(root, info): | ||
| raise UserError(_("UserError example")) | ||
|
|
||
|
|
||
| class CreatePartner(graphene.Mutation): | ||
| class Arguments: | ||
| name = graphene.String(required=True) | ||
| email = graphene.String(required=True) | ||
| is_company = graphene.Boolean() | ||
| raise_after_create = graphene.Boolean() | ||
|
|
||
| Output = Partner | ||
|
|
||
| @staticmethod | ||
| def mutate(self, info, name, email, is_company=False, raise_after_create=False): | ||
| env = info.context["env"] | ||
| partner = env["res.partner"].create( | ||
| {"name": name, "email": email, "is_company": is_company} | ||
| ) | ||
| if raise_after_create: | ||
| raise UserError(_("as requested")) | ||
| return partner | ||
|
|
||
|
|
||
| class Mutation(graphene.ObjectType): | ||
| create_partner = CreatePartner.Field(description="Documentation of CreatePartner") | ||
|
|
||
|
|
||
| schema = graphene.Schema(query=Query, mutation=Mutation) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ajay-odoogap can you finish this PR? It's important so we can test it before merging graphql_base.