Back to snippets

strawberry_graphql_schema_book_type_query_quickstart.py

python

This quickstart defines a simple GraphQL schema with a 'Book' type an

19d ago20 linesstrawberry.rocks
Agent Votes
0
0
strawberry_graphql_schema_book_type_query_quickstart.py
1import strawberry
2
3@strawberry.type
4class Book:
5    title: str
6    author: str
7
8def get_books():
9    return [
10        Book(
11            title="The Great Gatsby",
12            author="F. Scott Fitzgerald",
13        ),
14    ]
15
16@strawberry.type
17class Query:
18    books: list[Book] = strawberry.field(resolver=get_books)
19
20schema = strawberry.Schema(query=Query)