How to use the graphene.relay 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 hballard / graphql-python-subscriptions / examples / chatapp / server / api / schema.py View on Github external
class User(graphene_sqlalchemy.SQLAlchemyObjectType):

    class Meta:
        model = UserModel
        interfaces = (graphene.relay.Node, )


class Message(graphene_sqlalchemy.SQLAlchemyObjectType):

    class Meta:
        model = MessageModel
        interfaces = (graphene.relay.Node, )


class Query(graphene.ObjectType):
    node = graphene.relay.Node.Field()
    users = graphene_sqlalchemy.SQLAlchemyConnectionField(
        User,
        active=graphene.Boolean()
    )
    messages = graphene_sqlalchemy.SQLAlchemyConnectionField(Message)

    def resolve_users(self, args, context, info):
        query = User.get_query(context)
        if args.get('active') is None:
            return query
        return query.filter_by(active=args.get('active'))


class AddUser(graphene.ClientIDMutation):

    class Input:
github ivanchoo / demo-aws-graphql-python / demo / schema.py View on Github external
last_name = graphene.String()
    avatar_url = graphene.String()
    gender = graphene.String()
    job = graphene.String()
    education = graphene.String()
    address = graphene.String()
    introduction = graphene.String()

    friends = relay.ConnectionField('demo.schema.UserConnection')

    def resolve_friends(self, info):
        friends = DataStore.instance().get_friends(self.user_id)
        return [User(**friend) for friend in friends]


class UserConnection(relay.Connection):

    class Meta:
        node = User


class Query(graphene.ObjectType):

    user = graphene.Field(User, user_id=graphene.Int())

    def resolve_user(self, info, user_id=1):
        data = DataStore.instance().get_user(user_id)
        return User(**data)


schema = graphene.Schema(
    query=Query
github graphql-python / graphene / graphene-sqlalchemy / examples / flask_sqlalchemy / schema.py View on Github external
class Employee(SQLAlchemyObjectType):

    class Meta:
        model = EmployeeModel
        interfaces = (relay.Node, )


class Role(SQLAlchemyObjectType):

    class Meta:
        model = RoleModel
        interfaces = (relay.Node, )


class Query(graphene.ObjectType):
    node = relay.Node.Field()
    all_employees = SQLAlchemyConnectionField(Employee)
    all_roles = SQLAlchemyConnectionField(Role)
    role = graphene.Field(Role)


schema = graphene.Schema(query=Query, types=[Department, Employee, Role])
github mirumee / saleor / saleor / graphql / extensions / types.py View on Github external
value = graphene.String(required=True, description="Current value of the field")
    type = graphene.Field(ConfigurationTypeFieldEnum, description="Type of the field")
    help_text = graphene.String(required=False, description="Help text for the field")
    label = graphene.String(required=False, description="Label for the field")

    class Meta:
        description = "Stores information about single configuration field"


class Plugin(CountableDjangoObjectType):
    configuration = graphene.List(ConfigurationItem)

    class Meta:
        description = "Plugin"
        model = models.PluginConfiguration
        interfaces = [graphene.relay.Node]
        only_fields = ["name", "description", "active", "configuration"]
github phalt / django-api-domains / example_domain / apis.py View on Github external
logger = logging.getLogger(__name__)


# Internal API
class BookAPI:

    @staticmethod
    def get(*, book_id: uuid.UUID) -> Dict:
        logger.info('method "get" called')
        return BookService.get_book(id=book_id)


# graphQL Entity
class BookEntity(ObjectType):
    class Meta:
        interfaces = (relay.Node,)
    name = graphene.String()
    author_name = graphene.String()


# graphQL mutation
class CreateBook(relay.ClientIDMutation):
    class Input:
        book_name = graphene.String(required=True)
        author_id = graphene.ID(required=True)

    book = graphene.Field(BookEntity)

    @classmethod
    def mutate_and_get_payload(cls, root, info, **input):
        new_book = BookService.create_book(
            name=input.get('book_name'),
github mytardis / mytardis / tardis / tardis_portal / graphql / group.py View on Github external
from graphene_django_plus.types import ModelType
from graphene_django_plus.mutations import (
    ModelCreateMutation,
    ModelUpdateMutation
)

from django.contrib.auth.models import Group as GroupModel

from .utils import ExtendedConnection


class GroupType(ModelType):
    class Meta:
        model = GroupModel
        permissions = ['auth.view_group']
        interfaces = [relay.Node]
        connection_class = ExtendedConnection

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


class GroupTypeFilter(FilterSet):
    class Meta:
        model = GroupModel
        fields = {
            'name': ['exact', 'contains']
        }

    order_by = OrderingFilter(
        # must contain strings or (field name, param name) pairs
        fields=(
            ('name', 'name')
github episodeyang / ml_logger / ml-dash-server / ml_dash / schema / files / images.py View on Github external
from os.path import split
from graphene import ObjectType, relay, String
from ml_dash import schema


class File(ObjectType):
    class Meta:
        interfaces = relay.Node,

    name = String(description='name of the directory')

    # description = String(description='string serialized data')
    # experiments = List(lambda: schema.Experiments)

    @classmethod
    def get_node(cls, info, id):
        return get_file(id)


class FileConnection(relay.Connection):
    class Meta:
        node = File
github deathbeds / jupyter-graphql / src / jupyter_graphql / schema / nbformat / notebook.py View on Github external
import graphene as G

from . import NBFormat, cells
from .metadata import NotebookMetadata


class Notebook(G.ObjectType):
    class Meta:
        interfaces = (NBFormat, G.relay.Node)

    cells = G.relay.ConnectionField(cells.CellConnection)
    nbformat = G.Int()
    nbformat_minor = G.Int()
    metadata = G.Field(NotebookMetadata)


__types__ = cells.__types__ + [Notebook]