Skip to Content
Menu

GraphQL Custom Query Studio

by
Odoo

176.70

v 16.0 Third Party
Live Preview
Availability
Odoo Online
Odoo.sh
On Premise
Odoo Apps Dependencies Discuss (mail)
Community Apps Dependencies
Lines of code 2881
Technical Name graphql_studio
LicenseOPL-1
Websitehttps://ekika.co
Versions 12.0 13.0 14.0 15.0 16.0 17.0 18.0
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Odoo Apps Dependencies Discuss (mail)
Community Apps Dependencies
Lines of code 2881
Technical Name graphql_studio
LicenseOPL-1
Websitehttps://ekika.co
Versions 12.0 13.0 14.0 15.0 16.0 17.0 18.0
Versions 12 13 14 15 16 17 18
Community
Enterprise

https://www.ekika.co/support

GraphQL Custom Query Studio

with

EKIKA's "api_framework"

Background Image

This module allows you to write your own Custom GraphQL Queries. Here you can use various features of api_framework like different authentication, CORS configurations etc. using GraphQL.

Configuring API

How It Works:

Create Queries

  • To create a custom API endpoint, define methods within the easy.graphql.customstudio model. You can find the relevant file at: /models/custom_graphql_studio.py.
  • Use the def my_custom_graphql_queries(cls) method to list out your queries. Ensure it returns a list of query name.
  • Use the def my_custom_graphql_mutations(cls) method to list out your mutations. Ensure it returns a list of mutation name.
  • Define a method matching one of the names in the list above. Ensure it accepts args and fields as a parameter.
  • For Queries: The methods you implement must return tuple where first element returns dictionary object of result and second element return dictionary object of page-info.
  • For Mutations: The methods you implement must return dictionary object of result.

Create your own intrespection for your Queries

  • To do this, create a method in the easy.graphql.customstudio You can find the relevant file at: /models/custom_graphql_studio.py, naming it starting with "\_doc\_" followed by "yourCustomQuery", such as "\_doc\_{yourCustomQuery}". This method should return a dictionary including keys like "query_data, schema_data. You can find an example in /models/custom_graphql_studio.py.

Now you can perform your custom GraphQL Queries.

For more detail please refer below examples:

*** python ***

from odoo import models
from odoo.http import request


class MyGraphQLCustomStudio(models.AbstractModel):
    _inherit = 'easy.graphql.customstudio'

    @classmethod
    def my_custom_graphql_queries(cls):
        res = super().my_custom_graphql_queries()
        res.extend(['getContacts', 'getContactDetails'])
        return res

    @classmethod
    def my_custom_graphql_mutations(cls):
        res = super().my_custom_graphql_mutations()
        res.extend(['createContact', 'resetPasswordMail'])
        return res

    @classmethod
    def getContacts(cls, args, fields) -> dict:
        """Get list of contacts
        return list of contacts with name, email fields.
        """
        try:
            offset = int(args.get('offset', 0))
            limit = int(args.get('limit', 5))
            partners = request.env['res.partner'].search_read([], fields=list(fields.keys()), offset=offset, limit=limit)
            count = request.env['res.partner'].search_count([])
            has_next = bool((offset+limit) < count)
            return partners, {'totalCount': count, 'hasNextPage': has_next}
        except Exception as exc:
            result = {'errors': exc.args}
            return result, {}

    @classmethod
    def _doc_getContacts(cls) -> dict:
        return {
            'query_data': {
                'name': 'getContacts',
                'description': "Get Contact List",
                'args': [
                    {
                        "name": "offset",
                        "description": None,
                        "type": {
                            "kind": "SCALAR",
                            "name": "Int",
                            "ofType": None,
                        },
                        "defaultValue": None
                    },
                    {
                        "name": "limit",
                        "description": None,
                        "type": {
                            "kind": "SCALAR",
                            "name": "Int",
                            "ofType": None,
                        },
                        "defaultValue": None
                    },
                ],
                "type": {
                    "kind": "LIST",
                    "name": 'getContacts',
                    "ofType": {
                        "kind": "OBJECT",
                        "name": 'getContacts',
                        "ofType": None
                    }
                },
                "isDeprecated": False,
                "deprecationReason": None
            },
            'schema_data': {
                'kind': 'OBJECT',
                'name': 'getContacts',
                'description': 'For Get Contacts List',
                'fields': [
                    {
                        'name': 'id',
                        'description': 'Id of contact',
                        'args': [],
                        'type': {
                            'kind': 'SCALAR',
                            'name': 'ID',
                            'ofType': None
                        },
                        'isDeprecated': False,
                        'deprecationReason': None
                    },
                    {
                        'name': 'name',
                        'description': 'name of the contact',
                        'args': [],
                        'type': {
                            'kind': 'SCALAR',
                            'name': 'String',
                            'ofType': None
                        },
                        'isDeprecated': False,
                        'deprecationReason': None
                    }
                ],
                'inputFields': None,
                'interfaces': [],
                'enumValues': None,
                'possibleTypes': None
            }
        }

    @classmethod
    def getContactDetails(cls, args, fields) -> dict:
        try:
            partner = request.env['res.partner'].browse(int(args['id']))
            result = partner.read(fields=list(fields.keys()))[0]
            return result, {}
        except Exception as exc:
            result = {'errors': exc.args}
            return result

    @classmethod
    def _doc_getContactDetails(cls) -> dict:
        return {
            'query_data': {
                'name': 'getContactDetails',
                'description': "Get Contact Details",
                'args': [
                    {
                        "name": "id",
                        "description": None,
                        "type": {
                            "name": None,
                            "kind": "NON_NULL",
                            "ofType": {
                                "name": "ID",
                                "kind": "SCALAR"
                            }
                        },
                        "defaultValue": None
                    }
                ],
                "type": {
                    "kind": "OBJECT",
                    "name": 'ResPartner',
                    "ofType": None
                },
                "isDeprecated": False,
                "deprecationReason": None
            },
        }

    @classmethod
    def createContact(cls, args, fields) -> dict:
        try:
            partner = request.env['res.partner'].create({'name': args['name'], 'email': args['email']})
            result = partner.read(fields=list(fields.keys()))
            return result
        except Exception as exc:
            result = {'errors': exc.args}
            return result

    @classmethod
    def _doc_createContact(cls) -> dict:
        return {
            'query_data': {
                'name': 'createContact',
                'description': "Create Contact",
                'args': [
                    {
                        "name": "name",
                        "description": None,
                        "type": {
                            "kind": "SCALAR",
                            "name": "String",
                            "ofType": None,
                        },
                        "defaultValue": None
                    },
                    {
                        "name": "email",
                        "description": None,
                        "type": {
                            "kind": "SCALAR",
                            "name": "String",
                            "ofType": None,
                        },
                        "defaultValue": None
                    }
                ],
                "type": {
                    "kind": "OBJECT",
                    "name": 'ResPartner',
                    "ofType": None
                },
                "isDeprecated": False,
                "deprecationReason": None
            },
        }

    @classmethod
    def resetPasswordMail(cls, args, fields) -> dict:
        try:
            user = request.env['res.users'].browse(int(args['user_id']))
            user.action_reset_password()
            result = {'data': {'success': 'Password reset email sent successfully.'}}
        except Exception as exc:
            result = {'data': {'error': 'Failed to send the password reset email.'}}
        return result

    @classmethod
    def _doc_resetPasswordMail(cls) -> dict:
        return {
            'query_data': {
                'name': 'resetPasswordMail',
                'description': "Reset Password Mail",
                'args': [
                    {
                        "name": "user_id",
                        "description": None,
                        "type": {
                            "name": None,
                            "kind": "NON_NULL",
                            "ofType": {
                                "name": "ID",
                                "kind": "SCALAR"
                            }
                        },
                        "defaultValue": None
                    }
                ],
                "type": {
                    "kind": "OBJECT",
                    "name": 'resetPasswordMail',
                    "ofType": None,
                },
                "isDeprecated": False,
                "deprecationReason": None
            },
            'schema_data': {
                'kind': 'OBJECT',
                'name': 'resetPasswordMail',
                'description': 'Reset Password Mail',
                'fields': [
                    {
                        'name': 'data',
                        'description': 'message response of reset password mail',
                        'args': [],
                        'type': {
                            'kind': 'SCALAR',
                            'name': 'Any',
                            'ofType': None
                        },
                        'isDeprecated': False,
                        'deprecationReason': None
                    },
                ],
                'inputFields': None,
                'interfaces': [],
                'enumValues': None,
                'possibleTypes': None
            }
        }

Request Considering above Examples:

IconGet Contacts
*** python ***

import requests
import json

url = "http://localhost:8018/user-graphql-apikey"

payload = "{\"query\":\"query MyQuery{\\n  getContacts(offset:10, limit:2){\\n    id\\n    name\\n  }\\n}\",\"variables\":{}}"
headers = {
  'x-api-key': '9tByi7zYVNMVH1UsvvhOcxPP4d3y2xME',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
IconGet Contact Details
*** python ***

import requests
import json

url = "http://localhost:8018/user-graphql-apikey"

payload = "{\"query\":\"query MyQuery{\\n  getContactDetails(id: 12){\\n    id\\n    name\\n  }\\n}\",\"variables\":{}}"
headers = {
  'x-api-key': '9tByi7zYVNMVH1UsvvhOcxPP4d3y2xME',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

IconCreate Contact

*** python ***

import requests
import json

url = "http://localhost:8018/user-graphql-apikey"

payload = "{\"query\":\"mutation MyMutation{\\n    createContact(name: \\\"Hello 1\\\" email: \\\"hello1@mail.com\\\"){\\n        id\\n        name\\n        email\\n    }\\n}\",\"variables\":{}}"
headers = {
  'x-api-key': '9tByi7zYVNMVH1UsvvhOcxPP4d3y2xME',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
IconReset Password Mail
*** python ***

import requests
import json

url = "http://localhost:8018/user-graphql-apikey"

payload = "{\"query\":\"mutation MyMutation{\\n    resetPasswordMail(user_id: 2){\\n        data\\n    }\\n}\",\"variables\":{}}"
headers = {
  'x-api-key': '9tByi7zYVNMVH1UsvvhOcxPP4d3y2xME',
  'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)

Frequently Asked Questions (FAQs)

Find answers of common questions you might have about this addon. If you don't see your question addressed here, feel free to contact us!

Contact Us:

  • Whats App / Phone: +919510031431 -- URGENT
  • EMail: hello@ekika.co
  • Skype: amshukla17
  • Website: https://ekika.co
  • Support Ticket: https://ekika.co/support -- Get Notifications of Progress.
  • 24 x 7 Available! Contact us NOW.

We love hearing your ideas for improvement! If you have a feature in mind that would make your Odoo experience even better, simply contact us. We're happy to discuss your needs and explore the best way to implement them.

We offer a wide range of Odoo services to help you at any stage, from initial setup ("implementation") to ongoing customization and support. This includes:

  • Adding new features and functionalities ("addons development")
  • Changing behaviour of whole system ("server and structure level changes")
  • Server maintenance and configuration changes ("nginx / filestores / size issues etc.")
  • Integration with other systems
  • RESTful APIs, WebHooks, Slave-Master DB, Real-time data communication ("socket connection") etc.
  • Improving app performance and user experience ("performance tuning" and "UI/UX design")
  • Secure and reliable managed hosting solutions
  • Annual maintenance contracts to keep your Odoo running smoothly and so much more...

Basically, we're your one-stop shop for all things Odoo! We offer premium services at competitive rates.

Need Help?

EKIKA Has Your Back - 24/7 Support.

We're just a message away, no matter the time zone.

90 Days Free Support

We understand that even with great documentation, you might have questions or need additional assistance. That's why we offer exceptional support.

https://ekika.co/api
Documentation & User Guide
(copy link to clipboard)
https://www.youtube.com/@ekika_co/videos
Video Guide
(copy link to clipboard)
https://ekika.co/support
Support
(copy link to clipboard)

Our Other Apps

Odoo PowerBI Connector | Odoo PowerBI Direct Connector | PowerBI Odoo Integration | Power BI Odoo Data Import | Odoo PowerBI Sync | Odoo Power BI Data Connector | Odoo PowerBI Live Connection | Odoo PowerBI User Access Control | PowerBI Odoo Sudo Mode | Odoo to Power BI Direct Fetch | PowerBI Odoo Company Restrictions | Odoo PowerBI Admin Access | Odoo 17 PowerBI Connector | Odoo 16 Power BI Module | Odoo PowerBI Integration v18 | Odoo Business Intelligence | PowerBI Odoo API Connector | Odoo BI Data Extraction | Odoo Power BI Dashboard Integration

PowerBI Connector

Odoo BigQuery Connector | BigQuery Odoo Integration | Odoo BigQuery Direct Connector | Odoo BigQuery Data Sync | Odoo to BigQuery Export | BigQuery Odoo Data Connector | Odoo BigQuery User Access Control | BigQuery Odoo Sudo Mode | Odoo BigQuery Company Restrictions | Odoo BigQuery Automated Upload | BigQuery Odoo Table Sync | Odoo BigQuery Field Selection | Odoo 17 BigQuery Connector | Odoo 16 BigQuery Integration | Odoo BigQuery Connector v18 | Odoo Business Intelligence BigQuery | BigQuery Odoo API Connector | Odoo Google BigQuery Export | Odoo BigQuery Data Pipeline

BigQuery Connector

Advance RESTful API with Security for Odoo. It allows access of resources/data with (optional) predefined JSON:API schema of response Odoo models, fields and much more. | Auto-generated easy to access and secure documentation with Open API (Swagger). | Reach set of Authentication and Authorization available with dynamic configuration control. | Multi-API, Multi-Company & Multi-Website Supported. | Easy to Use and Easy to Secure access of resources.

Odoo RESTful API Framework with JsonAPI, GraphQL and more

Services EKIKA Provides

EKIKA is your destination for expert Odoo ERP implementation and customization. We pride ourselves on building reliable, trust-based partnerships that give you full transparency and control over your business processes.

With over 12 years of experience, we can assist you with eCommerce platforms, production planning, point-of-sale systems, managing inventory adjustments, and providing advanced field worker tracking solutions to optimize your workflows and boost operational efficiency.

Ekika Odoo Implementation

Implementation

Utilise Odoo ERP tailored for your business needs for smooth operations.

Ekika Odoo Customization

Customization

Personalized adjustments to Odoo modules for seamless management.

Ekika Odoo Support

Support

Ongoing assistance and maintenance to optimize your Odoo system's performance.

Are you struggling with disorganized operations, high operational costs, or lack of transparency in your processes? What sets us apart is our commitment to personalized solutions tailored to your unique business needs and our proactive support, ensuring seamless integration and ongoing success.

Would you like to explore Odoo ERP for your business? Schedule a free consultation with EKIKA today!

Odoo Proprietary License v1.0

This software and associated files (the "Software") may only be used (executed,
modified, executed after modifications) if you have purchased a valid license
from the authors, typically via Odoo Apps, or if you have received a written
agreement from the authors of the Software (see the COPYRIGHT file).

You may develop Odoo modules that use the Software as a library (typically
by depending on it, importing it and using its resources), but without copying
any source code or material from the Software. You may distribute those
modules under the license of your choice, provided that this license is
compatible with the terms of the Odoo Proprietary License (For example:
LGPL, MIT, or proprietary licenses similar to this one).

It is forbidden to publish, distribute, sublicense, or sell copies of the Software
or modified copies of the Software.

The above copyright notice and this permission notice must be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author or have a question related to your purchase, please use the support page.