Search 1.9 billion lines of Odoo code on GitHub

graphql_base

Author: ACSONE SA/NV,Odoo Community Association (OCA)
License: LGPL-3
Branch: 12.0-backport-improve-exception-wrap
Repository: acsone/rest-framework
Dependencies: base, and web
Languages: HTML (397, 53.4%), Python (114, 15.3%), XML (130, 17.5%), and reStructuredText (103, 13.8%)
Other branches: 12.0, 12.0-asw_master, 12.0-base_rest-cors-options, 12.0-datamodel-experiment, 12.0-fix_base_rest_registry, 12.0-new-api-wip, 13.0, 13.0-48-port, 13.0-backport-base-rest-pydantic, 13.0-backport-extendable, 13.0-base_rest-cors-options, 13.0-fixcrashdesc, 14.0, 14.0-abi_master, 14.0-add-pydantic, 14.0-base-rest-pydantic-lmi, 14.0-base_res_service_add_properties-qgr, 14.0-deprecated-implicit-rest-method, 14.0-fdl_master, 14.0-fix-path-parameter-name, 14.0-fix-response-processing, 14.0-fixcrashdesc, 14.0-moz_master, 15.0, 15.0-initial, 16.0, 16.0-fastapi, 16.0-mfr_fix_base_rest_missing_argument, 16.0-upgrade-pre-commit, and oca-port-pr--from-14.0-to-13.0
Other repositories: Ahmad-Datasmith/rest-framework, Change2improve/rest-framework, Digital5-Odoo/rest-framework, Gabinete-Digital/rest-framework, LevelPrime/rest-framework, NeatNerdPrime/rest-framework, OCA-MUK/rest-framework, OCA/rest-framework, SetRac/rest-framework, SeuMarco/rest-framework, TDu/rest-framework, Tomaskarpovic/rest-framework, ajinvn2019/rest-framework, akretion/rest-framework, alecvinent/rest-framework, altanmur/rest-framework, andres-mejia/rest-framework, baotnp/rest-framework, bigmoney-team/rest-framework, boky1993/rest-framework, cedvict/rest-framework, coopiteasy/rest-framework, darshan-odoo/rest-framework, dndoanh/rest-framework, elmosolutions/rest-framework, gastonfeng/rest-framework, glm-conseil/rest-framework, guewen/rest-framework, gurneyalex/rest-framework, guwenfeng/rest-framework, hinfo506/rest-framework, hminle/rest-framework, huntergps/rest-framework, id42sistemas/rest-framework, jacky82669513/rest-framework, jamesvibar/rest-framework, janverb/rest-framework, jobiols/oca-rest-framework, jorgeblanc9/rest-framework, josuf567/rest-framework, lebanggit/rest-framework, led-startup-studio/rest-framework, lideritjnma/rest-framework, marvin981973/rest-framework, maxindo/rest-framework, mohamed-helmy/rest-framework, ngnamuit/rest-framework, novawish/rest-framework, odoogap/rest-framework, oliverzgy/rest-framework, osvalr/rest-framework, royalline1/rest-framework, sanube/rest-framework, simahawk/rest-framework, skander-cherif/rest-framework, themreza/rest-framework, ursais/rest-framework, wahello/rest-framework, x0rzkov/odoo-rest-framework, xaoxaodigital/rest-framework, xoe-labs/rest-framework, xubiuit/rest-framework, xwh123807/rest-framework, and yasmanycastillo/rest-framework

<h1 class="title">Graphql Base</h1> <p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/rest-framework/tree/12.0/graphql_base"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/rest-framework-12-0/rest-framework-12-0-graphql_base"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/271/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p> <p>This modules enables the creation of <a class="reference external" href="https://graphql.org/">GraphQL</a> endpoints. In itself, it does nothing and must be used by a developer to create the GraphQL schema and resolvers using <a class="reference external" href="https://graphene-python.org/">graphene</a>, and expose them through a controller. An example is available in the <code>graphql_demo</code> module.</p> <p><strong>Table of contents</strong></p> <div class="contents local topic" id="contents"> <ul class="simple"> <li><a class="reference internal" href="#usage" id="id1">Usage</a><ul> <li><a class="reference internal" href="#building-your-schema" id="id2">Building your schema</a></li> <li><a class="reference internal" href="#creating-graphql-controllers" id="id3">Creating GraphQL controllers</a></li> </ul> </li> <li><a class="reference internal" href="#bug-tracker" id="id4">Bug Tracker</a></li> <li><a class="reference internal" href="#credits" id="id5">Credits</a><ul> <li><a class="reference internal" href="#authors" id="id6">Authors</a></li> <li><a class="reference internal" href="#maintainers" id="id7">Maintainers</a></li> </ul> </li> </ul> </div> <a name="usage"></a> <h2><a class="toc-backref" href="#id1">Usage</a></h2> <p>To use this module, you need to</p> <ul class="simple"> <li>create your graphene schema</li> <li>create your controller to expose your GraphQL endpoint, and optionally a GraphiQL IDE.</li> </ul> <p>This module does not attempt to expose the whole Odoo object model. This could be the purpose of another module based on this one. We believe however that it is preferable to expose a specific well tested endpoint for each customer, so as to reduce coupling by knowing precisely what is exposed and needs to be tested when upgrading Odoo.</p> <p>To start working with this module, we recommend the following approach:</p> <ul class="simple"> <li>Learn <a class="reference external" href="https://graphql.org/learn/">GraphQL basics</a></li> <li>Learn <a class="reference external" href="https://graphene-python.org/">graphene</a>, the python library used to create GraphQL schemas and resolvers.</li> <li>Examine the <code>graphql_demo</code> module in this repo, copy it, adapt the controller to suit your needs (routes, authentication methods).</li> <li>Start building your own schema and resolver.</li> </ul> <a name="building-your-schema"></a> <h3><a class="toc-backref" href="#id2">Building your schema</a></h3> <p>The schema can be built using native graphene types. An <code>odoo.addons.graphql_base.types.OdooObjectType</code> is provided as a convenience. It is a graphene <code>ObjectType</code> with a default attribute resolver which:</p> <ul class="simple"> <li>converts False to None (except for Boolean types), to avoid Odoo's weird <code>False</code> strings being rendered as json <code>&quot;false&quot;</code>;</li> <li>adds the user timezone to Datetime fields;</li> <li>raises an error if an attribute is absent to avoid field name typing errors.</li> </ul> <a name="creating-graphql-controllers"></a> <h3><a class="toc-backref" href="#id3">Creating GraphQL controllers</a></h3> <p>The module provides an <code>odoo.addons.graphql_base.GraphQLControllerMixin</code> class to help you build GraphQL controllers providing GraphiQL and/or GraphQL endpoints.</p> <pre> <code lang="python">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 &#64;http.route(&quot;/graphiql/demo&quot;, auth=&quot;user&quot;) 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(&quot;^/graphql/demo/?$&quot;) # The graphql route, for applications. # Note csrf=False: you may want to apply extra security # (such as origin restrictions) to this route. &#64;http.route(&quot;/graphql/demo&quot;, auth=&quot;user&quot;, csrf=False) def graphql(self, **kwargs): return self._handle_graphql_request(schema)</code> </pre> <a name="bug-tracker"></a> <h2><a class="toc-backref" href="#id4">Bug Tracker</a></h2> <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/rest-framework/issues">GitHub Issues</a>. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed <a class="reference external" href="https://github.com/OCA/rest-framework/issues/new?body=module:%20graphql_base%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p> <p>Do not contact contributors directly about support or help with technical issues.</p> <a name="credits"></a> <h2><a class="toc-backref" href="#id5">Credits</a></h2> <a name="authors"></a> <h3><a class="toc-backref" href="#id6">Authors</a></h3> <ul class="simple"> <li>ACSONE SA/NV</li> </ul> <a name="maintainers"></a> <h3><a class="toc-backref" href="#id7">Maintainers</a></h3> <p>This module is maintained by the OCA.</p> <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a> <p>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.</p> <p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p> <p><a class="reference external" href="https://github.com/sbidoul"><img alt="sbidoul" src="https://github.com/sbidoul.png?size=40px" /></a></p> <p>This module is part of the <a class="reference external" href="https://github.com/OCA/rest-framework/tree/12.0/graphql_base">OCA/rest-framework</a> project on GitHub.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>