コード例 #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!
#   }
コード例 #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: {
コード例 #3
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(
コード例 #4
0
ファイル: schema.py プロジェクト: sjhewitt/graphql-relay-py

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!
#   }
#
コード例 #5
0
ファイル: fields.py プロジェクト: jhgg/graphene
 def get_field(self, schema):
     return global_id_field(self.object_type._meta.type_name)
コード例 #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:
コード例 #7
0
ファイル: schema.py プロジェクト: faassen/relaypy
_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: