Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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:
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
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])
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"]
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'),
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')
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
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]