예제 #1
0
def get_node(global_id, *args):
    _type, _id = from_global_id(global_id)
    if _type == 'User':
        return userData[_id]
    else:
        return photoData[_id]


def get_node_type(obj, context, info):
    if isinstance(obj, User):
        return userType
    else:
        return photoType


node_interface, node_field = node_definitions(get_node, get_node_type)

userType = GraphQLObjectType('User',
                             fields=lambda: {
                                 'id': global_id_field('User'),
                                 'name': GraphQLField(GraphQLString),
                             },
                             interfaces=[node_interface])

photoType = GraphQLObjectType(
    'Photo',
    fields=lambda: {
        'id': global_id_field('Photo', lambda obj, *_: obj.photoId),
        'width': GraphQLField(GraphQLInt),
    },
    interfaces=[node_interface])
예제 #2
0
파일: schema.py 프로젝트: madejean/relaypy
    _type, _id = resolvedGlobalId.type, resolvedGlobalId.id
    if _type == 'Faction':
        return getFaction(_id)
    elif _type == 'Ship':
        return getShip(_id)
    else:
        return None


def getNodeType(obj):
    if isinstance(obj, Faction):
        return factionType
    else:
        return shipType

_node_definitions = node_definitions(getNode, getNodeType)
node_field, node_interface = (_node_definitions.node_field,
                            _node_definitions.node_interface)


# We define our basic ship type.
#
# This implements the following type system shorthand:
#   type Ship : Node {
#     id: String!
#     name: String
#   }
shipType = GraphQLObjectType(
    name='Ship',
    description='A ship in the Star Wars saga',
    fields=lambda: {
예제 #3
0
    _type, _id = from_global_id(global_id)
    if _type == 'Faction':
        return getFaction(_id)
    elif _type == 'Ship':
        return getShip(_id)
    else:
        return None


def get_node_type(obj, context, info):
    if isinstance(obj, Faction):
        return factionType
    else:
        return shipType

node_interface, node_field = node_definitions(get_node, get_node_type)


# We define our basic ship type.
#
# This implements the following type system shorthand:
#   type Ship : Node {
#     id: String!
#     name: String
#   }
shipType = GraphQLObjectType(
    name='Ship',
    description='A ship in the Star Wars saga',
    fields=lambda: {
        'id': global_id_field('Ship'),
        'name': GraphQLField(
예제 #4
0
    _type, _id = resolvedGlobalId.type, resolvedGlobalId.id
    if _type == 'Faction':
        return getFaction(_id)
    elif _type == 'Ship':
        return getShip(_id)
    else:
        return None


def getNodeType(obj):
    if isinstance(obj, Faction):
        return factionType
    else:
        return shipType

_node_definitions = node_definitions(getNode, getNodeType)
node_field, node_interface = (_node_definitions.node_field,
                            _node_definitions.node_interface)


# We define our basic ship type.
#
# This implements the following type system shorthand:
#   type Ship : Node {
#     id: String!
#     name: String
#   }
shipType = GraphQLObjectType(
    name='Ship',
    description='A ship in the Star Wars saga',
    fields=lambda: {