How to use the graphene.relay.Node 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 KCarretto / Arsenal / teamserver / teamserver / api / session.py View on Github external
"""
        Allow access to the model.
        """
        model = models.SessionConfig
        interfaces = (Node,)

class Session(MongoengineObjectType):
    """
    This class represents the schema for a Session object.
    """
    class Meta:
        """
        Allow access to the model.
        """
        model = models.Session
        interfaces = (Node,)

class SessionConfigInput(graphene.InputObjectType):
    """
    Input format for the SessionConfig embedded object model.
    """
    interval = graphene.Int(required=True)
    delta = graphene.Int(required=True)
    servers = graphene.List(graphene.String)

class CreateSession(graphene.Mutation):
    """
    Create a session object model.
    """
    class Arguments:
        """
        Accepted arguments.
github mozilla / treeherder / treeherder / webapp / graphql / schema.py View on Github external
class TextLogStepGraph(DjangoObjectType):
    class Meta:
        model = TextLogStep


class JobGraph(DjangoObjectType):
    class Meta:
        model = Job
        filter_fields = {
            'id': ['exact'],
            'guid': ['exact'],
            'result': ['exact'],
            'tier': ['exact', 'lt'],
        }
        interfaces = (graphene.relay.Node, )

    job_details = DjangoFilterConnectionField(JobDetailGraph)

    def resolve_job_details(self, info, **kwargs):
        return JobDetail.objects.filter(job=self, **kwargs)


class BuildPlatformGraph(DjangoObjectType):
    class Meta:
        model = BuildPlatform


class MachinePlatformGraph(DjangoObjectType):
    class Meta:
        model = MachinePlatform
github mytardis / mytardis / tardis / tardis_portal / graphql / facility.py View on Github external
from django_filters import FilterSet, OrderingFilter
from graphene_django_plus.types import ModelType
from graphene_django_plus.mutations import (
    ModelCreateMutation,
    ModelUpdateMutation
)

from .utils import ExtendedConnection
from ..models.facility import Facility as FacilityModel


class FacilityType(ModelType):
    class Meta:
        model = FacilityModel
        permissions = ['tardis_portal.view_facility']
        interfaces = [relay.Node]
        connection_class = ExtendedConnection

    pk = graphene.Int(source='pk')


class FacilityTypeFilter(FilterSet):
    class Meta:
        model = FacilityModel
        fields = {
            'name': ['exact', 'contains'],
            'created_time': ['lte', 'gte']
        }

    order_by = OrderingFilter(
        # must contain strings or (field name, param name) pairs
        fields=(
github assembl / assembl / assembl / graphql / vote_session.py View on Github external
def mutate(root, args, context, info):
        cls = models.VoteProposal
        proposal_id = args.get('id')
        proposal_id = int(Node.from_global_id(proposal_id)[1])
        title_entries = args.get('title_entries')
        description_entries = args.get('description_entries')

        with cls.default_db.no_autoflush as db:
            proposal = cls.get(proposal_id)
            require_instance_permission(CrudPermissions.UPDATE, proposal, context)
            update_langstring_from_input_entries(
                proposal, 'title', title_entries)
            update_langstring_from_input_entries(
                proposal, 'description', description_entries)

            # change order if needed
            order = args.get('order')
            if order:
                proposal.source_links[0].order = order
github mirumee / saleor / saleor / graphql / wishlist / types.py View on Github external
class Wishlist(CountableDjangoObjectType):
    class Meta:
        only_fields = ["id", "created_at", "items"]
        description = "Wishlist item."
        interfaces = [graphene.relay.Node]
        model = models.Wishlist
        filter_fields = ["id"]


class WishlistItem(CountableDjangoObjectType):
    class Meta:
        only_fields = ["id", "wishlist", "product", "variants"]
        description = "Wishlist item."
        interfaces = [graphene.relay.Node]
        model = models.WishlistItem
        filter_fields = ["id"]
github mytardis / mytardis / tardis / tardis_portal / graphql / user.py View on Github external
from graphql import GraphQLError

import graphql_jwt
from graphql_jwt.shortcuts import get_token

from django.contrib.auth.models import User as UserModel
from tastypie.models import ApiKey as ApiKeyModel

from .utils import ExtendedConnection


class UserType(ModelType):
    class Meta:
        model = UserModel
        fields = ('id', 'username', 'first_name', 'last_name', 'email')
        interfaces = [relay.Node]
        connection_class = ExtendedConnection


class UserSignIn(graphql_jwt.relay.JSONWebTokenMutation):
    user = graphene.Field(UserType)

    @classmethod
    def resolve(cls, self, info, **kwargs):
        return cls(user=info.context.user)


class ApiSignInInput(graphene.InputObjectType):
    key = graphene.String(required=True)


class ApiSignIn(graphene.Mutation):
github graphql-python / graphene / examples / starwars_relay / schema.py View on Github external
faction_id = graphene.String(required=True)

    ship = graphene.Field(Ship)
    faction = graphene.Field(Faction)

    @classmethod
    def mutate_and_get_payload(cls, root, info, ship_name, faction_id, client_mutation_id=None):
        ship = create_ship(ship_name, faction_id)
        faction = get_faction(faction_id)
        return IntroduceShip(ship=ship, faction=faction)


class Query(graphene.ObjectType):
    rebels = graphene.Field(Faction)
    empire = graphene.Field(Faction)
    node = relay.Node.Field()

    def resolve_rebels(self, info):
        return get_rebels()

    def resolve_empire(self, info):
        return get_empire()


class Mutation(graphene.ObjectType):
    introduce_ship = IntroduceShip.Field()


schema = graphene.Schema(query=Query, mutation=Mutation)
github assembl / assembl / assembl / graphql / synthesis.py View on Github external
from assembl import models
import assembl.graphql.docstrings as docs
from .document import Document
from .idea import IdeaUnion
from .langstring import (
    LangStringEntry, resolve_langstring, resolve_langstring_entries)
from .types import SecureObjectType
from .utils import DateTime


class Synthesis(SecureObjectType, SQLAlchemyObjectType):
    __doc__ = docs.Synthesis.__doc__

    class Meta:
        model = models.Synthesis
        interfaces = (Node, )
        only_fields = ('id', )

    subject = graphene.String(lang=graphene.String(), description=docs.Synthesis.subject)
    subject_entries = graphene.List(LangStringEntry, description=docs.Synthesis.subject_entries)
    introduction = graphene.String(lang=graphene.String(), description=docs.Synthesis.introduction)
    introduction_entries = graphene.List(LangStringEntry, description=docs.Synthesis.introduction_entries)
    conclusion = graphene.String(lang=graphene.String(), description=docs.Synthesis.conclusion)
    conclusion_entries = graphene.List(LangStringEntry, description=docs.Synthesis.conclusion_entries)
    ideas = graphene.List(lambda: IdeaUnion, description=docs.Synthesis.ideas)
    img = graphene.Field(Document, description=docs.Synthesis.img)
    creation_date = DateTime(description=docs.Synthesis.creation_date)
    post = graphene.Field("assembl.graphql.post.Post", description=docs.Synthesis.post)

    def resolve_subject(self, args, context, info):
        return resolve_langstring(self.subject, args.get('lang'))
github graphql-python / graphene / graphene-django / examples / starwars / schema.py View on Github external
ship = graphene.Field(Ship)
    faction = graphene.Field(Faction)

    @classmethod
    def mutate_and_get_payload(cls, input, context, info):
        ship_name = input.get('shipName')
        faction_id = input.get('factionId')
        ship = create_ship(ship_name, faction_id)
        faction = get_faction(faction_id)
        return IntroduceShip(ship=ship, faction=faction)


class Query(graphene.ObjectType):
    rebels = graphene.Field(Faction)
    empire = graphene.Field(Faction)
    node = relay.Node.Field()
    ships = relay.ConnectionField(Ship, description='All the ships.')

    @resolve_only_args
    def resolve_ships(self):
        return get_ships()

    @resolve_only_args
    def resolve_rebels(self):
        return get_rebels()

    @resolve_only_args
    def resolve_empire(self):
        return get_empire()


class Mutation(graphene.ObjectType):
github ian13456 / Gooseberries / deprecated / backend / schemas / queries.py View on Github external
payload = jwt_payload(self)
        return jwt_encode(payload)

class PostFilter(django_filters.FilterSet):
    class Meta:
        model = Post
        fields = {
            'title': ['icontains'],
            'content': ['icontains'],
        }

class PostNode(DjangoObjectType):
    class Meta:
        model = Post
        interfaces = (graphene.relay.Node, )

class ThreadFilter(django_filters.FilterSet):
    class Meta:
        model = Thread
        fields = {
            'name': ['icontains', 'istartswith', 'iendswith'],
            'description': ['icontains'],
        }

class ThreadNode(DjangoObjectType):
    class Meta:
        model = Thread
        interfaces = (graphene.relay.Node, )