class Book(SqlAlchemyObjectType):
    __model__ = BookRecord

    id = column_field(column=BookRecord.c_id)
    title = column_field(column=BookRecord.c_title)
    author_id = column_field(column=BookRecord.c_author_id)
    author = single(lambda: sql_join(Author))
    books_by_same_author = extract(author, "books")

    sales = single(
        lambda: sql_value_join(Sales, {Book.title: Sales.book_title}))
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)
Exemple #3
0
 class Root(RootType):
     author = single(
         lambda: select(Author),
         args={
             "nameStartsWith": String,
         },
     )
Exemple #4
0
    class Book(SqlAlchemyObjectType):
        __model__ = BookRecord

        id = column_field(BookRecord.id)
        title = column_field(BookRecord.title)
        genre = column_field(BookRecord.genre)
        author_id = column_field(BookRecord.author_id)
        author = single(lambda: sql_join(Author))
Exemple #5
0
    class Root(RootType):
        author = single(lambda: StaticDataObjectType.select(Author))

        @author.arg("nameStartsWith", Boolean)
        def author_arg_starts_with(records, _, context):
            return list(
                filter(
                    lambda record: record.name.startswith(context),
                    records,
                ))
Exemple #6
0
    class Root(RootType):
        author = single(lambda: StaticDataObjectType.select(Author))

        @author.arg("nameStartsWith", String)
        def author_arg_starts_with(records, prefix):
            return list(
                filter(
                    lambda record: record.name.startswith(prefix),
                    records,
                ))
Exemple #7
0
    class Root(RootType):
        author = single(lambda: StaticDataObjectType.select(Author))

        @author.arg("selection", AuthorSelection)
        def author_arg_selection(records, selection):
            return list(
                filter(
                    lambda record: record.name.startswith(selection.
                                                          name_starts_with),
                    records,
                ))
Exemple #8
0
    class Book(StaticDataObjectType):
        __records__ = [
            BookRecord("PGW", "Leave it to Psmith"),
            BookRecord("PGW", "The Code of the Woosters"),
        ]

        author_id = field(type=String, internal=True)
        author = single(lambda: StaticDataObjectType.select(
            Author,
            join={Book.author_id: Author.id},
        ))
        title = field(type=String)
Exemple #9
0
 class Root(RootType):
     author = single(lambda: self._join_to_authors(count=2))
Exemple #10
0
    class Root(RootType):
        selection = single(lambda: StaticDataObjectType.select(Selection))

        @selection.arg("selection", SelectionInput)
        def selection_arg_selection(records, selection):
            return [SelectionRecord(str(selection.name))]
Exemple #11
0
 class Root(RootType):
     author = single(lambda: StaticDataObjectType.select(Author))
Exemple #12
0
 class Root(RootType):
     fields = field_set(
         author=single(lambda: StaticDataObjectType.select(Author)),
         book=single(lambda: StaticDataObjectType.select(Book)),
     )
Exemple #13
0
 class Root(RootType):
     box = single(lambda: select(Box))