How to use the graphene.InputObjectType function in graphene

To help you get started, we’ve selected a few graphene examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andela / mrm_api / api / office_structure / schema.py View on Github external
from helpers.auth.authentication import Auth
from utilities.validations import (
    validate_empty_fields,
    validate_structure_nodes
)
from helpers.auth.admin_roles import admin_roles
from helpers.database import db_session
from utilities.utility import update_entity_fields


class StructureNode(SQLAlchemyObjectType):
    class Meta:
        model = StructureModel


class InputNode(graphene.InputObjectType):
    id = graphene.UUID(required=True)
    parent_id = graphene.UUID()
    name = graphene.String(required=True)
    tag = graphene.String(required=True)


class UpdateNode(graphene.Mutation):
    """
        Returns a node payload after updating a node
    """
    class Arguments:
        node_id = graphene.UUID(required=True)
        name = graphene.String()
        tag = graphene.String()
    node = graphene.Field(StructureNode)
github assembl / assembl / assembl / graphql / idea.py View on Github external
    @classmethod
    def resolve_type(cls, instance, context, info):
        if isinstance(instance, graphene.ObjectType):
            return type(instance)
        elif isinstance(instance, models.Idea):
            return Idea


class QuestionInput(graphene.InputObjectType):
    __doc__ = docs.QuestionInput.__doc__
    id = graphene.ID(description=docs.QuestionInput.id)
    title_entries = graphene.List(LangStringEntryInput, required=True, description=docs.QuestionInput.title_entries)


class IdeaMessageColumnInput(graphene.InputObjectType):
    __doc__ = docs.IdeaMessageColumnInput.__doc__
    id = graphene.ID(description=docs.IdeaMessageColumnInput.id)
    name_entries = graphene.List(LangStringEntryInput, required=True, description=docs.IdeaMessageColumnInput.name_entries)
    title_entries = graphene.List(LangStringEntryInput, required=True, description=docs.IdeaMessageColumnInput.title_entries)
    color = graphene.String(required=True, description=docs.IdeaMessageColumnInput.color)
    message_classifier = graphene.String(description=docs.IdeaMessageColumnInput.message_classifier)
    column_synthesis_subject = graphene.List(LangStringEntryInput, description=docs.IdeaMessageColumnInput.column_synthesis_subject)
    column_synthesis_body = graphene.List(LangStringEntryInput, description=docs.IdeaMessageColumnInput.column_synthesis_body)


def update_announcement_body_attachments(context, idea, discussion, new_attachments, purpose):
    """Create, update, delete announcement body attachments."""
    original_ln_attachments = get_attachments_with_purpose(
        idea.attachments, purpose)
    original_attachments_doc_ids = []
    if original_ln_attachments:
github mirumee / saleor / saleor / graphql / menu / mutations.py View on Github external
from ...menu import models
from ...menu.error_codes import MenuErrorCode
from ...menu.utils import update_menu
from ...page import models as page_models
from ...product import models as product_models
from ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
from ..core.types.common import MenuError
from ..core.utils import from_global_id_strict_type
from ..core.utils.reordering import perform_reordering
from ..page.types import Page
from ..product.types import Category, Collection
from .enums import NavigationType
from .types import Menu, MenuItem, MenuItemMoveInput


class MenuItemInput(graphene.InputObjectType):
    name = graphene.String(description="Name of the menu item.")
    url = graphene.String(description="URL of the pointed item.")
    category = graphene.ID(
        description="Category to which item points.", name="category"
    )
    collection = graphene.ID(
        description="Collection to which item points.", name="collection"
    )
    page = graphene.ID(description="Page to which item points.", name="page")


class MenuItemCreateInput(MenuItemInput):
    name = graphene.String(description="Name of the menu item.", required=True)
    menu = graphene.ID(
        description="Menu to which item belongs.", name="menu", required=True
    )
github open-eats / openeats-api / v1 / list / schema.py View on Github external
return UpdateGroceryList(grocery_list=grocery_list)


class DeleteGroceryList(DeleteModel, DeleteMutation):
    class Config:
        model = GroceryList
        auth = 'author'


class BulkDeleteGroceryList(BulkDeleteModel, DeleteMutation):
    class Config:
        model = GroceryList
        auth = 'author'


class GroceryItemInput(graphene.InputObjectType):
    id = graphene.ID()
    list = graphene.ID()
    title = graphene.String()
    completed = graphene.Boolean()


class CreateGroceryItem(graphene.Mutation):
    class Input:
        data = graphene.Argument(GroceryItemInput)

    grocery_item = graphene.Field(lambda: GroceryItemNode)

    @staticmethod
    def mutate(root, args, context, info, model=None):
        list_id = args.get('data').get('list')
        title = args.get('data').get('title')
github riverfr0zen / graphene-mongo-extras / graphene_mongo_extras / filtering / __init__.py View on Github external
class FiltersRegistry:
    _registry = {}

    @classmethod
    def register(cls, filterset_class):
        cls._registry[filterset_class.__name__] = filterset_class

    @classmethod
    def get(cls, classname):
        if classname in cls._registry:
            return cls._registry[classname]
        return None


class FiltersetBase(graphene.InputObjectType):
    op = graphene.String(default_value="AND")


def _is_embedded_list(field):
    if hasattr(field, 'field') and isinstance(
        field.field,
        EmbeddedDocumentField
    ):
        return True
    return False


def filters_factory(model, base_classname, filtering_opts={}, as_list=False):
    field_filters = {}
    graphene_mongo_registry = get_global_registry()
    filters_classname = "{}Filters".format(base_classname)
github mirumee / saleor / saleor / graphql / product / mutations / products.py View on Github external
public = False
        error_type_class = ProductError
        error_type_field = "product_errors"


class ProductClearPrivateMeta(ClearMetaBaseMutation):
    class Meta:
        description = "Clears private metadata item for product."
        model = models.Product
        permissions = (ProductPermissions.MANAGE_PRODUCTS,)
        public = False
        error_type_class = ProductError
        error_type_field = "product_errors"


class ProductVariantInput(graphene.InputObjectType):
    attributes = graphene.List(
        AttributeValueInput,
        required=False,
        description="List of attributes specific to this variant.",
    )
    cost_price = Decimal(description="Cost price of the variant.")
    price_override = Decimal(description="Special price of the particular variant.")
    sku = graphene.String(description="Stock keeping unit.")
    quantity = graphene.Int(
        description="The total quantity of this variant available for sale."
    )
    track_inventory = graphene.Boolean(
        description=(
            "Determines if the inventory of this variant should be tracked. If false, "
            "the quantity won't change when customers buy this item."
        )
github riverfr0zen / graphene-mongo-extras / graphene_mongo_extras / filtering / __init__.py View on Github external
base_classname,
                                                  as_list=True)
                        filters = {"{}__{}".format(fieldname, filtr): fieldobj
                                   for filtr, fieldobj in filters.items()}
                        field_filters.update(filters)
                else:
                    filters = [{
                        "{}__{}".format(fieldname, lookup):
                            convert_for_lookup(converted_field, lookup)
                    } for lookup in lookups]
                    field_filters.update(dict(ChainMap(*filters)))

        if as_list:
            return field_filters
        filters_class = type(filters_classname,
                             (graphene.InputObjectType,),
                             field_filters)
        FiltersRegistry.register(filters_class)
    return filters_class
github mirumee / saleor / saleor / graphql / account / mutations / base.py View on Github external
instance.delete()
        instance.id = db_id

        # Refresh the user instance to clear the default addresses. If the
        # deleted address was used as default, it would stay cached in the
        # user instance and the invalid ID returned in the response might cause
        # an error.
        user.refresh_from_db()

        response = cls.success_response(instance)

        response.user = user
        return response


class UserInput(graphene.InputObjectType):
    first_name = graphene.String(description="Given name.")
    last_name = graphene.String(description="Family name.")
    email = graphene.String(description="The unique email address of the user.")
    is_active = graphene.Boolean(required=False, description="User account is active.")
    note = graphene.String(description="A note about the user.")


class UserAddressInput(graphene.InputObjectType):
    default_billing_address = AddressInput(
        description="Billing address of the customer."
    )
    default_shipping_address = AddressInput(
        description="Shipping address of the customer."
    )
github graphql-python / graphene-django / graphene_django / rest_framework / serializer_converter.py View on Github external
def convert_serializer_to_input_type(serializer_class):
    cached_type = convert_serializer_to_input_type.cache.get(
        serializer_class.__name__, None
    )
    if cached_type:
        return cached_type
    serializer = serializer_class()

    items = {
        name: convert_serializer_field(field)
        for name, field in serializer.fields.items()
    }
    ret_type = type(
        "{}Input".format(serializer.__class__.__name__),
        (graphene.InputObjectType,),
        items,
    )
    convert_serializer_to_input_type.cache[serializer_class.__name__] = ret_type
    return ret_type
github mozilla / mozillians / mozillians / graphql_profiles / mutation.py View on Github external
import graphene
import requests

from django.conf import settings

from mozillians.graphql_profiles.decorators import graphql_permission_check
from mozillians.graphql_profiles.schema import CoreProfile
from mozillians.graphql_profiles.utils import json2obj


class SimpleInputField(graphene.InputObjectType):
    """Simple Input Field that accepts a string argument."""
    value = graphene.String(required=False)


class BasicProfileInput(graphene.InputObjectType):
    """Basic Profile Mutation for the v2 profile schema."""
    first_name = graphene.InputField(SimpleInputField)
    last_name = graphene.InputField(SimpleInputField)
    primary_email = graphene.InputField(SimpleInputField)


class EditBasicProfile(graphene.Mutation):

    class Arguments:
        basic_profile_data = BasicProfileInput(required=False)
        # Get the user_id for editing
        user_id = graphene.String(required=True)

    errors = graphene.List(graphene.String)
    updated_profile = graphene.Field(lambda: CoreProfile)