Skip to content
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

[18.0][MIG] graphql_demo: Migration to 18.0 #475

Open
wants to merge 41 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
e063670
[ADD] graphql_base and graphql_demo
sbidoul Nov 19, 2018
a7d9f5c
graphql_demo: improve schema, add mutation example
sbidoul Dec 3, 2018
5afb73a
graphql_demo: clarify controller example
sbidoul Dec 3, 2018
8a292c5
graphql_demo: tests
sbidoul Dec 3, 2018
ba8b570
graphql: more documentation
sbidoul Dec 3, 2018
8db1b0b
graphql: add development_status and maintainers
sbidoul Dec 3, 2018
67e74d5
graphql: improve and test error handling
sbidoul Dec 3, 2018
4094b30
graphql: silence false travis error
sbidoul Dec 3, 2018
75b9074
graphql: test json input
sbidoul Dec 3, 2018
4c372c9
graphql: test response content type
sbidoul Dec 3, 2018
55373f6
graphql: improve error case test
sbidoul Dec 3, 2018
4e36e89
graphql_demo: add usage instructions
sbidoul Dec 3, 2018
4924566
graphql: fix typos in documentation
sbidoul Dec 3, 2018
2924093
fixup! fix errors in unreached code
sbidoul Dec 18, 2018
92a4778
[UPD] README.rst
OCA-git-bot Jan 14, 2019
3b015cd
[IMP] graphql_demo: add limit/offset example
sbidoul Feb 6, 2019
afe30ee
[IMP] graphql_demo: add mutation documentation example
sbidoul Feb 6, 2019
58ccea0
[IMP] graphql_demo: add standalone mutation test
sbidoul Feb 6, 2019
5b87b50
[FIX] graphql: controller must rollback in case of error
sbidoul Feb 6, 2019
97e4ffb
[FIX] graphql: readme lint
sbidoul Feb 6, 2019
94455f3
[ADD] icon.png
OCA-git-bot Apr 3, 2019
6a63c21
[UPD] README.rst
OCA-git-bot Jul 29, 2019
cfa3455
black, isort pre-commit
lmignon Oct 17, 2019
1e7dac1
[MIG] 13.0 branch creation
lmignon Oct 17, 2019
e8673a4
[MIG] graphql_base, graphql_demo from 12 to 13
sbidoul Oct 12, 2019
d6939cc
[UPD] README.rst
OCA-git-bot Oct 18, 2019
9141697
Initialize 14.0 branch
lmignon Dec 24, 2020
311e86f
[MIG] Migration to version 14.0: graphql_base
qgroulard Dec 10, 2021
e2ce088
[UPD] Update graphql_demo.pot
oca-travis Dec 24, 2021
f876e68
[UPD] README.rst
OCA-git-bot Dec 24, 2021
0b237ff
Forward port from 14.0
lmignon Jun 14, 2022
fecb393
[MIG] [16.0] graphql_demo
Jan 3, 2023
377b5f5
[UPD] Update graphql_demo.pot
Jan 16, 2023
b1ed0d4
[UPD] README.rst
OCA-git-bot Jan 16, 2023
d0596d7
graphql_demo 16.0.1.0.1
OCA-git-bot Jan 16, 2023
79d3523
[UPD] README.rst
OCA-git-bot Sep 3, 2023
2563813
[MIG] mark all modules installable=False
sbidoul Nov 12, 2023
a85e170
[MIG] graphql_base: Migration to 17.0
dduarte-odoogap Aug 19, 2024
a997daf
[UPD] Update graphql_demo.pot
Oct 3, 2024
1d23bef
[BOT] post-merge updates
OCA-git-bot Oct 3, 2024
6e9e9e0
[MIG] graphql_demo: Migration to 18.0
ajay-odoogap Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions graphql_demo/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
============
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/18.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-18-0/rest-framework-18-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=18.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

Contributors
~~~~~~~~~~~~

* Ajay Javiya <ajaviya@odoogap.com>

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/18.0/graphql_demo>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions graphql_demo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import controllers
14 changes: 14 additions & 0 deletions graphql_demo/__manifest__.py
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": "18.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"],
"development_status": "Beta",
"maintainers": ["sbidoul"],
"installable": True,
}
1 change: 1 addition & 0 deletions graphql_demo/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import main
22 changes: 22 additions & 0 deletions graphql_demo/controllers/main.py
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)
28 changes: 28 additions & 0 deletions graphql_demo/i18n/graphql_demo.pot
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 ""
31 changes: 31 additions & 0 deletions graphql_demo/i18n/it.po
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 <stefano.consolaro@mymage.it>\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"
3 changes: 3 additions & 0 deletions graphql_demo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions graphql_demo/readme/DESCRIPTION.md
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`.
5 changes: 5 additions & 0 deletions graphql_demo/readme/USAGE.md
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`.
101 changes: 101 additions & 0 deletions graphql_demo/schema.py
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)
Binary file added graphql_demo/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading