Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
89 changes: 89 additions & 0 deletions graphql_demo/README.rst
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.
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