Closed
Description
We should support code-first approach to type definition in addition to current schema-first one. My original idea was to do this through decorator (like how Strawberry does it) but my current idea is to use universal base types for both code-first and schema-first approaches to GraphQL schema definition. The differentiation factor between those two would be a presence of __schema__
atribute on the type:
# Schema first object
class Query(ObjectType):
__schema__ = gql(
"""
type Query {
message: String!
year: Int!
}
"""
)
@field
def message(*_):
return "Hello world!"
@field
def year(*_):
return date.today().year
# Code first object
class Query(ObjectType):
@field
def message(*_) -> str:
return "Hello world!"
@field
def year(*_) -> str:
return date.today().year