How to use the graphene.relay.Node.Field 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 0soft / graphene-django-plus / tests / schema.py View on Github external
class Meta:
        model = Project
        connection_class = CountableConnection
        interfaces = [relay.Node]
        filter_fields = {}


# Queries


class Query(graphene.ObjectType):
    projects = OrderableConnectionField(ProjectType)
    project = relay.Node.Field(ProjectType)

    milestones = OrderableConnectionField(MilestoneType)
    milestone = relay.Node.Field(MilestoneType)

    issues = OrderableConnectionField(IssueType)
    issue = relay.Node.Field(IssueType)


# Mutations


class ProjectCreateMutation(ModelCreateMutation):
    class Meta:
        model = Project


class ProjectUpdateMutation(ModelUpdateMutation):
    class Meta:
        model = Project
github timfeirg / flask-graphene-boilerplate / graphene_boilerplate / schema.py View on Github external
import graphene
from graphene import relay
from graphene_sqlalchemy import SQLAlchemyObjectType, SQLAlchemyConnectionField

from graphene_boilerplate.ext import db
from graphene_boilerplate.models import Item as ItemModel


class Item(SQLAlchemyObjectType):
    class Meta:
        model = ItemModel
        interfaces = (relay.Node, )


class Query(graphene.ObjectType):
    node = relay.Node.Field()
    all_items = SQLAlchemyConnectionField(Item)


class CreateItem(graphene.Mutation):
    class Arguments:
        key = graphene.String()
        value = graphene.JSONString()

    ok = graphene.Boolean()
    item = graphene.Field(lambda: Item)

    def mutate(self, info, key, value):
        item = ItemModel(key=key, value=value)
        db.session.add(item)
        db.session.commit()
        return CreateItem(ok=True, item=item)
github open-eats / openeats-api / v1 / ingredient / schema.py View on Github external
class IngredientGroupNode(DjangoObjectType):
    class Meta:
        model = IngredientGroup
        interfaces = (graphene.relay.Node, )
        filter_fields = ['id', 'title']


class IngredientNode(DjangoObjectType):
    class Meta:
        model = Ingredient
        interfaces = (graphene.relay.Node, )
        filter_fields = ['id', 'title']


class IngredientQuery(graphene.AbstractType):
    ingredient_group = graphene.relay.Node.Field(IngredientGroupNode)
    all_ingredient_groups = DjangoFilterConnectionField(IngredientGroupNode)
    ingredient = graphene.relay.Node.Field(IngredientNode)
    all_ingredients = DjangoFilterConnectionField(IngredientNode)


class IngredientGroupInput(graphene.InputObjectType):
    id = graphene.ID()
    recipe = graphene.ID()
    title = graphene.String()


class CreateIngredientGroup(graphene.Mutation):
    class Input:
        data = graphene.Argument(IngredientGroupInput)

    ingredient_group = graphene.Field(lambda: IngredientGroupNode)
github ian13456 / Gooseberries / deprecated / backend / schema.py View on Github external
import graphene
from .models import User, Post, Thread, Like
from backend.schemas.queries import (
    UserType, PostType, ThreadType, LikeType,
    UserFilter, UserNode, PostFilter, PostNode, ThreadFilter, ThreadNode)
from backend.schemas.mutations import Register, CreatePost, LikePost, LogIn, LogOut
from graphene_django.filter import DjangoFilterConnectionField


class Query(graphene.ObjectType):
    user = graphene.relay.Node.Field(UserNode)
    users = DjangoFilterConnectionField(UserNode, filterset_class=UserFilter)
    post = graphene.relay.Node.Field(PostNode)
    posts = DjangoFilterConnectionField(PostNode, filterset_class=PostFilter)
    thread = graphene.relay.Node.Field(ThreadNode)
    threads = DjangoFilterConnectionField(ThreadNode, filterset_class=ThreadFilter)
    likes = graphene.List(LikeType)
    me = graphene.Field(UserType)

    def resolve_likes(self, info, **kwargs):
        return Like.objects.all()

    def resolve_me(self, info):
        user = info.context.user
        if user.is_anonymous:
            raise Exception('Not Logged in!')
        return user
github JBEI / edd / server / main / schema.py View on Github external
class MeasurementValueNode(StudyAccessMixin, DjangoObjectType):
    _filter_joins = ["measurement", "assay", "line", "study"]

    class Meta:
        interfaces = (graphene.Node,)
        model = models.MeasurementValue


class Query:
    study = relay.Node.Field(StudyNode)
    line = relay.Node.Field(LineNode)
    assay = relay.Node.Field(AssayNode)
    measurement = relay.Node.Field(MeasurementNode)
    unit = relay.Node.Field(UnitNode)
    value = relay.Node.Field(MeasurementValueNode)

    all_studies = gfilter.DjangoFilterConnectionField(
        StudyNode, filterset_class=rest_views.StudyFilter
    )
    all_lines = gfilter.DjangoFilterConnectionField(
        LineNode, filterset_class=rest_views.LineFilter
    )
    all_assays = gfilter.DjangoFilterConnectionField(
        AssayNode, filterset_class=rest_views.AssayFilter
    )
    all_measurements = gfilter.DjangoFilterConnectionField(
        MeasurementNode, filterset_class=rest_views.MeasurementFilter
    )
    all_units = gfilter.DjangoFilterConnectionField(
        UnitNode, filterset_class=rest_views.MeasurementUnitFilter
    )
github vanyakosmos / memes-reposter / apps / reddit / schema.py View on Github external
class PostNode(DjangoObjectType):
    class Meta:
        model = Post
        interfaces = (relay.Node,)

    @classmethod
    @permissions(is_staff)
    def get_node(cls, info, id):
        return super().get_node(info, id)


class RedditQuery(graphene.ObjectType):
    reddit_enabled = graphene.Boolean()
    reddit_posts_number = graphene.Int(status=graphene.String(), channel=graphene.String())
    reddit_post = relay.Node.Field(PostNode)
    all_reddit_posts = DjangoFilterConnectionField(PostNode, filterset_class=PostFilter)

    @permissions(is_staff)
    def resolve_reddit_posts_number(self, info: ResolveInfo, status=None, channel=None):
        qs = Post.objects.all()
        if channel:
            qs = qs.filter(channel_uuid=channel)
        if status:
            qs = qs.filter(status=status)
        return qs.count()

    @permissions(is_staff)
    def resolve_reddit_enabled(self, info: ResolveInfo):
        return RedditConfig.get_solo().enabled

    @permissions(is_staff)
github graphql-python / 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()
    # Allow only single column sorting
    all_employees = SQLAlchemyConnectionField(
        Employee.connection, sort=Employee.sort_argument())
    # Allows sorting over multiple columns, by default over the primary key
    all_roles = SQLAlchemyConnectionField(Role.connection)
    # Disable sorting over this field
    all_departments = SQLAlchemyConnectionField(Department.connection, sort=None)


schema = graphene.Schema(query=Query)
github aeifn / savva3 / base / schema.py View on Github external
'id': ['exact'],
        'url': ['contains'],
        'title': ['contains'],
        'areas': ['exact'],
        }
        interfaces = (graphene.relay.Node, )

class VideoType(DjangoObjectType):
    class Meta:
        model = Video

class Query(object):
    url = graphene.relay.Node.Field(VideoNode)
    all_urls = DjangoFilterConnectionField(VideoNode)

    tag = graphene.relay.Node.Field(TagNode)
    all_tags = DjangoFilterConnectionField(TagNode)

    area = graphene.relay.Node.Field(AreaNode)
    all_areas = DjangoFilterConnectionField(AreaNode)
    #all_areas = graphene.Field(AreaNode)

    random_url = graphene.Field(VideoType)

    def resolve_all_areas(self,info,**kwargs):
        # Выбираем только те темы, на которые есть видео
        return Area.objects.filter(resource__video__isnull=False).distinct()

    def resolve_random_url(self,info,**kwargs):
        return Video.objects.filter(url__contains="youtube").filter(url__contains="watch").order_by("?").first()
github andela-sjames / Bookmeapi / bookme / bookmeapi / schema.py View on Github external
def mutate_and_get_payload(cls, args, context, info):

        try:
            book_instance = get_object(Book, args['id'])
            if book_instance:
                book_data = args.get('book')
                updated_book = update_create_instance(book_instance, book_data)
            return cls(updated_book=updated_book)
        except ValidationError as e:
            return cls(updated_book=None, errors=get_errors(e))


class Query(ObjectType):
    users = relay.Node.Field(UserNode) # get user by id or by field name
    all_users =  DjangoFilterConnectionField(UserNode) # get all users
    books = relay.Node.Field(BookNode)
    all_books = DjangoFilterConnectionField(BookNode)

    def resolve_users(self):
        return User.objects.all()
    
    def resolve_books(self):
        return Book.objects.all()    


class Mutation(ObjectType):
     create_user = CreateUser.Field()
     create_book = CreateBook.Field()
     update_book = UpdateBook.Field()
    

schema = graphene.Schema(
github krzysztofzuraw / blog-projects / blog_django_graphql_react_relay / film_api / film_database / films / schema.py View on Github external
response = requests.get(FILMS_ENDPOINT.format(id=id))
        data = response.json()
        return Film.create_from_data(data, id)

    def resolve_actors(self, args, context, info):
        response = requests.get(FILMS_ENDPOINT.format(id=self.id))
        data = response.json()
        return [relay.Node.get_node_from_global_id(
            to_global_id('Actor', actor_id),
            context,
            info
        ) for actor_id in data['actors']]


class Query(graphene.AbstractType):
    film = graphene.relay.Node.Field(Film)
    films = graphene.List(Film)

    def resolve_films(self, args, context, info):
        response = requests.get(ALL_FILMS_ENDPOINT)
        data = response.json()
        return [Film.create_from_data(film, film['id']) for film in data]


class ActorInput(graphene.InputObjectType):
    actor_id = graphene.ID(required=True)

class CreateFilm(relay.ClientIDMutation):

    class Input:
        title = graphene.String(required=True)
        actors = graphene.List(ActorInput)