Exemplo n.º 1
0
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(
            GraphQLString,
            description='The name of the ship.',
        )
    },
    interfaces=[node_interface]
)

# We define a connection between a faction and its ships.
#
# connection_type implements the following type system shorthand:
#   type ShipConnection {
#     edges: [ShipEdge]
#     pageInfo: PageInfo!
#   }
Exemplo n.º 2
0
    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])

queryType = GraphQLObjectType(
    'Query',
    fields=lambda: {
    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]
)

queryType = GraphQLObjectType(
Exemplo n.º 4
0

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(
            GraphQLString,
            description='The name of the ship.',
        )
    },
    interfaces=[node_interface])

# We define a connection between a faction and its ships.
#
# connection_type implements the following type system shorthand:
#   type ShipConnection {
#     edges: [ShipEdge]
#     pageInfo: PageInfo!
#   }
#
Exemplo n.º 5
0
 def get_field(self, schema):
     return global_id_field(self.object_type._meta.type_name)
Exemplo n.º 6
0
node_interface, node_field = node_definitions(get_node, get_node_type)[:2]


# 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(GraphQLString, description="The name of the ship."),
    },
    interfaces=[node_interface],
)

# We define a connection between a faction and its ships.
#
# connection_type implements the following type system shorthand:
#   type ShipConnection {
#     edges: [ShipEdge]
#     pageInfo: PageInfo!
#   }
#
# connection_type has an edges field - a list of edgeTypes that implement the
# following type system shorthand:
Exemplo n.º 7
0
_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: {
        "id": global_id_field("Ship"),
        "name": GraphQLField(GraphQLString, description="The name of the ship."),
    },
    interfaces=[node_interface],
)

# We define a connection between a faction and its ships.
#
# connection_type implements the following type system shorthand:
#   type ShipConnection {
#     edges: [ShipEdge]
#     pageInfo: PageInfo!
#   }
#
# connection_type has an edges field - a list of edgeTypes that implement the
# following type system shorthand: