class Author(SqlAlchemyObjectType):
    __model__ = AuthorRecord

    id = column_field(AuthorRecord.c_id)
    name = column_field(AuthorRecord.c_name)
    books = many(lambda: sql_join(Book))
    book_titles = extract(books, "title")
    class Author(SqlAlchemyObjectType):
        __model__ = AuthorRecord

        id_1 = column_field(AuthorRecord.c_id_1)
        id_2 = column_field(AuthorRecord.c_id_2)
        name = column_field(AuthorRecord.c_name)
        books = many(lambda: sql_join(Book,
                                      join={
                                          Author.id_1: Book.author_id_1,
                                          Author.id_2: Book.author_id_2,
                                      }))
Ejemplo n.º 3
0
    class Root(RootType):
        authors = many(lambda: StaticDataObjectType.select(Author))

        @authors.arg("name", String)
        def authors_arg_selection(records, name):
            if name is not None:
                records = list(
                    filter(
                        lambda record: record.name == name,
                        records,
                    ))
            return records
Ejemplo n.º 4
0
    class Root(RootType):
        authors = many(lambda: StaticDataObjectType.select(Author))

        @authors.arg("selection", AuthorSelection)
        def authors_arg_selection(records, selection):
            if selection.name is not None:
                records = list(
                    filter(
                        lambda record: record.name == selection.name,
                        records,
                    ))
            return records
class Root(RootType):
    books = many(lambda: select(Book))
    book = single(lambda: select(Book))

    @book.arg("id", GraphQLInt)
    def book_id(query, book_id):
        return query.filter(BookRecord.c_id == book_id)

    author = single(lambda: select(Author))

    @author.arg("id", GraphQLInt)
    def author_id(query, author_id):
        return query.filter(AuthorRecord.c_id == author_id)
    class Author(SqlAlchemyObjectType):
        __model__ = AuthorRecord

        id = column_field(AuthorRecord.c_id)
        name = column_field(AuthorRecord.c_name)

        @staticmethod
        def _author_to_books(author_query, book_query):
            authors = author_query.add_columns(AuthorRecord.c_id).subquery()
            return book_query \
                .join(authors, authors.c.c_id == BookRecord.c_author_id)

        books = many(lambda: select(
            Book,
            join_query=Author._author_to_books,
            join_fields={Author.id: Book.author_id},
        ))
Ejemplo n.º 7
0
 class Root(RootType):
     books = many(lambda: StaticDataObjectType.select(Book), internal=True)
     book_titles = extract(books, lambda: Book.title)
Ejemplo n.º 8
0
 class Root(RootType):
     authors = many(lambda: StaticDataObjectType.select(Author))
     books = many(lambda: StaticDataObjectType.select(Book), internal=True)
Ejemplo n.º 9
0
 class Root(RootType):
     books = many(lambda: StaticDataObjectType.select(Book))
Ejemplo n.º 10
0
 class Root(RootType):
     authors = many(lambda: StaticDataObjectType.select(Author))
     author_names = extract(authors, lambda: Author.name)
Ejemplo n.º 11
0
 class Root(RootType):
     author_names = extract(
         many(lambda: StaticDataObjectType.select(Author)), "name")
Ejemplo n.º 12
0
 class Root(RootType):
     authors = many(lambda: _join(
         Author,
         lambda root_query, context: context.authors,
         join_fields={},
     ))
Ejemplo n.º 13
0
 class Root(RootType):
     authors = many(lambda: StaticDataObjectType.select(
         Author, filter=lambda values: values[:1]))
 class Root(RootType):
     authors = many(lambda: select(Author))
 class Root(RootType):
     labels = many(lambda: select(Label))
Ejemplo n.º 16
0
    class Root(RootType):
        books = many(lambda: select(Book))

        @books.arg("genre", GraphQLString)
        def books_arg_genre(query, genre):
            return query.filter(BookRecord.genre == genre)