コード例 #1
0
 def fields():
     return {
         "id": field(column_name="id", type=GraphQLInt),
         "title": field(column_name="title", type=GraphQLString),
         "genre": field(column_name="genre", type=GraphQLString),
         "authorId": field(column_name="author_id", type=GraphQLInt),
         "author": single(author_join_type, author_query, join={"authorId": "id"}),
     }
コード例 #2
0
    def fields():
        author = single(
            author_join_type,
            lambda *_: all_authors,
            join={"authorId": "id"},
        )

        return {
            "id": field(attr="id", type=GraphQLInt),
            "title": field(attr="title", type=GraphQLString),
            "authorId": field(attr="author_id", type=GraphQLInt),
            "author": author,
            "booksBySameAuthor": extract(author, "books"),
        }
コード例 #3
0
    def fields():
        author = single(
            author_join_type,
            author_query,
            join={"authorId": "id"},
        )

        return {
            "id": field(column_name="id", type=GraphQLInt),
            "title": field(column_name="title", type=GraphQLString),
            "authorId": field(column_name="author_id", type=GraphQLInt),
            "author": author,
            "booksBySameAuthor": extract(author, "books"),
        }
コード例 #4
0
def test_single_uses_type_of_target(target_type, type_matcher):
    root_type = JoinType(
        name="Root",
        fields=lambda: {"value": single(Target(target_type), None)},
        fetch_immediates=None,
    )

    graphql_type = root_type.to_graphql_type()
    graphql_type.of_type.fields
    assert_that(
        graphql_type,
        is_non_null(
            is_object_type(fields=has_entries({
                "value":
                is_field(type=type_matcher),
            }), )))
コード例 #5
0
 def fields():
     return {
         "books": many(book_join_type, lambda *_: all_books),
         "book": single(book_join_type, book_query, args={"id": GraphQLArgument(type=GraphQLInt)}),
         "author": single(author_join_type, author_query, args={"id": GraphQLArgument(type=GraphQLInt)}),
     }