How to use the graphene.ID 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 assembl / assembl / assembl / graphql / timeline.py View on Github external
phase.attachments,
                    models.AttachmentPurpose.IMAGE.value,
                    db,
                    context
                )

            db.flush()

        return UpdateDiscussionPhase(discussion_phase=phase)


class DeleteDiscussionPhase(graphene.Mutation):
    __doc__ = docs.DeleteDiscussionPhase.__doc__

    class Input:
        id = graphene.ID(required=True, description=docs.DeleteDiscussionPhase.id)

    success = graphene.Boolean()

    @staticmethod
    @abort_transaction_on_exception
    def mutate(root, args, context, info):
        cls = models.DiscussionPhase
        phase_id = args.get('id')
        phase_id = int(Node.from_global_id(phase_id)[1])
        phase = cls.get(phase_id)
        require_instance_permission(CrudPermissions.DELETE, phase, context)
        with cls.default_db.no_autoflush as db:
            for attachment in phase.attachments[:]:
                attachment.document.delete_file()
                db.delete(attachment.document)
                db.delete(attachment)
github mirumee / saleor / saleor / dashboard / graphql / api.py View on Github external
description='List of the shop\'s product attributes.')
    categories = DjangoFilterConnectionField(
        Category, filterset_class=DistinctFilterSet,
        level=graphene.Argument(graphene.Int),
        description='List of shop\'s categories.')
    category = graphene.Field(
        Category, id=graphene.Argument(graphene.ID),
        description='Lookup a category by ID.')
    page = graphene.Field(
        Page, id=graphene.Argument(graphene.ID),
        description='Lookup a page by ID.')
    pages = DjangoFilterConnectionField(
        Page, filterset_class=DistinctFilterSet,
        description='List of shop\'s pages.')
    product = graphene.Field(
        Product, id=graphene.Argument(graphene.ID),
        description='Lookup a product by ID.')
    products = DjangoFilterConnectionField(
        Product, filterset_class=ProductFilter,
        category_id=graphene.Argument(graphene.ID),
        description='List of shop\'s products.')
    node = graphene.Node.Field()
    debug = graphene.Field(DjangoDebug, name='__debug')

    @staff_member_required
    def resolve_attributes(self, info):
        return resolve_attributes()

    @staff_member_required
    def resolve_category(self, info, id):
        return get_node(info, id, only_type=Category)
github projectcaluma / caluma / caluma / caluma_form / schema.py View on Github external
),
    )
    all_documents = DjangoFilterConnectionField(
        Document,
        filterset_class=CollectionFilterSetFactory(
            filters.DocumentFilterSet, filters.DocumentOrderSet
        ),
    )
    all_format_validators = ConnectionField(FormatValidatorConnection)
    all_used_dynamic_options = DjangoFilterConnectionField(
        DynamicOption,
        filterset_class=CollectionFilterSetFactory(filters.DynamicOptionFilterSet),
    )

    document_validity = ConnectionField(
        DocumentValidityConnection, id=graphene.ID(required=True)
    )

    def resolve_all_format_validators(self, info):
        return get_format_validators()

    def resolve_document_validity(self, info, id):
        return validate_document(info, id)


QUESTION_ANSWER_TYPES = {
    models.Question.TYPE_MULTIPLE_CHOICE: ListAnswer,
    models.Question.TYPE_INTEGER: IntegerAnswer,
    models.Question.TYPE_FLOAT: FloatAnswer,
    models.Question.TYPE_DATE: DateAnswer,
    models.Question.TYPE_CHOICE: StringAnswer,
    models.Question.TYPE_TEXTAREA: StringAnswer,
github mirumee / saleor / saleor / graphql / menu / types.py View on Github external
"menu",
            "name",
            "page",
            "parent",
            "sort_order",
        ]
        model = models.MenuItem

    @staticmethod
    def resolve_children(root: models.MenuItem, _info, **_kwargs):
        return root.children.all()


class MenuItemMoveInput(graphene.InputObjectType):
    item_id = graphene.ID(description="The menu item ID to move.", required=True)
    parent_id = graphene.ID(
        description="ID of the parent menu. If empty, menu will be top level menu."
    )
    sort_order = graphene.Int(
        description="Sorting position of the menu item (from 0 to x)."
    )
github smbolton / howtographql-tutorial-graphene-backend / links / schema.py View on Github external
# a non-Enum-using FilterSet, with no monkey patching.
#
# LinkConnection below demonstrates a way to use custom Enums in a custom Connection.

class Vote(DjangoObjectType):
    class Meta:
        model = VoteModel
        interfaces = (relay.Node, )
        # We are going to provide a custom Connection, so we need to tell graphene-django not to
        # create one. Failing to do this will result in a error like "AssertionError: Found
        # different types with the same name in the schema: VoteConnection, VoteConnection."
        use_connection = False


class IdInput(graphene.InputObjectType):
    id = graphene.ID(required=True)


class VoteFilter(graphene.InputObjectType):
    """The input object for filtered allVotes queries. The VoteFilter input type provided by the
    Graphcool server used in the front-end tutorial is quite a bit more complex than this, but this
    is all the tutorial itself needs.
    """
    link = graphene.InputField(IdInput)
    user = graphene.InputField(IdInput)


class VotesFilterSet(django_filters.FilterSet):
    """A basic FilterSet for filtering allVotes queries."""
    class Meta:
        model = VoteModel
        fields = ['link', 'user']
github realsuayip / django-sozluk / dictionary_graph / entry / action.py View on Github external
downvoted.add(entry)

        if sender.is_karma_eligible:
            sender.karma = karma - cost
            entry.author.karma = karma - downvote_rate
            sender.save()
            entry.author.save()

        return response


class VoteComment(Mutation):
    count = Int()

    class Arguments:
        pk = ID()
        action = String()

    @staticmethod
    @login_required
    def mutate(_root, info, pk, action):
        comment, sender = Comment.objects.get(pk=pk), info.context.user
        in_upvoted = comment.upvoted_by.filter(pk=sender.pk).exists()
        in_downvoted = comment.downvoted_by.filter(pk=sender.pk).exists()

        if action == "upvote":
            if in_upvoted:
                comment.upvoted_by.remove(sender)
            elif in_downvoted:
                comment.downvoted_by.remove(sender)
                comment.upvoted_by.add(sender)
            else:
github assembl / assembl / assembl / graphql / vote_session.py View on Github external
# return only vote specifications not associated to a proposal
        return [vote_spec for vote_spec in self.vote_specifications if vote_spec.criterion_idea_id is None]

    def resolve_num_participants(self, args, context, info):
        all_participant_ids = set()
        for proposal in self.idea.get_vote_proposals():
            participant_ids = proposal.get_voter_ids()
            all_participant_ids = all_participant_ids.union(participant_ids)
        return len(all_participant_ids)


class UpdateVoteSession(graphene.Mutation):
    __doc__ = docs.UpdateVoteSession.__doc__

    class Input:
        idea_id = graphene.ID(required=True, description=docs.UpdateVoteSession.idea_id)
        see_current_votes = graphene.Boolean(description=docs.UpdateVoteSession.see_current_votes)

    add_langstrings_input_attrs(Input, langstrings_defs.keys())

    vote_session = graphene.Field(VoteSession)

    @staticmethod
    @abort_transaction_on_exception
    def mutate(root, args, context, info):
        idea_id = args.get('idea_id')
        idea_id = int(Node.from_global_id(idea_id)[1])
        idea = models.Idea.get(idea_id)
        discussion_id = context.matchdict["discussion_id"]
        discussion = models.Discussion.get(discussion_id)

        if idea is None:
github tOgg1 / graphene-django-cud / graphene_django_cud / mutations / update.py View on Github external
{
                "auto_context_fields": auto_context_fields or {},
                "optional_fields": optional_fields,
                "required_fields": required_fields,
                "many_to_many_extras": many_to_many_extras,
                "many_to_one_extras": many_to_one_extras,
                "foreign_key_extras": foreign_key_extras,
                "one_to_one_extras": one_to_one_extras,
                "field_types": field_types or {},
            },
        )

        registry.register_converted_field(input_type_name, InputType)

        arguments = OrderedDict(
            id=graphene.ID(required=True), input=InputType(required=True)
        )

        output_fields = OrderedDict()
        output_fields[return_field_name] = graphene.Field(model_type)

        if _meta is None:
            _meta = DjangoUpdateMutationOptions(cls)

        _meta.model = model
        _meta.fields = yank_fields_from_attrs(output_fields, _as=graphene.Field)
        _meta.return_field_name = return_field_name
        _meta.permissions = permissions
        _meta.optional_fields = optional_fields
        _meta.required_fields = required_fields
        _meta.auto_context_fields = auto_context_fields
        _meta.many_to_many_extras = many_to_many_extras
github eamigo86 / graphene-django-extras / graphene_django_extras / converter.py View on Github external
def dynamic_type():
        if input_flag and not nested_field:
            return ID()
        _type = registry.get_type_for_model(model, for_input=input_flag)
        if not _type:
            return
        return Field(_type, required=is_required(field) and input_flag == "create")
github projectcaluma / caluma / caluma / document / schema.py View on Github external
return cls(answer=answer)


class SaveDocumentStringAnswer(SaveDocumentAnswer):
    class Input:
        question = graphene.ID(required=True)
        document = graphene.ID(required=True)
        meta = graphene.JSONString(required=True)
        value = graphene.String(required=True)


class SaveDocumentListAnswer(SaveDocumentAnswer):
    class Input:
        question = graphene.ID(required=True)
        document = graphene.ID(required=True)
        meta = graphene.JSONString(required=True)
        value = graphene.List(graphene.String, required=True)


class SaveDocumentIntegerAnswer(SaveDocumentAnswer):
    class Input:
        question = graphene.ID(required=True)
        document = graphene.ID(required=True)
        meta = graphene.JSONString(required=True)
        value = graphene.Int(required=True)


class SaveDocumentFloatAnswer(SaveDocumentAnswer):
    class Input:
        question = graphene.ID(required=True)
        document = graphene.ID(required=True)