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 Root(RootType): author = single( lambda: select(Author), args={ "nameStartsWith": String, }, )
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}, ))
class Root(RootType): box = single(lambda: select(Box))
class Root(RootType): authors = many(lambda: select(Author))
class Root(RootType): labels = many(lambda: select(Label))
class Root(RootType): books = many(lambda: select(Book)) @books.arg("genre", GraphQLString) def books_arg_genre(query, genre): return query.filter(BookRecord.genre == genre)