GraphQL Operations
The code must be placed in a file named graphql.py
or within a folder named graphql
located in the Application directory.
import zmag
# Create your API (GraphQL) here.
@zmag.gql
class Graphql:
class Meta: ...
class Query: ...
class Mutation: ...
Operations Tools — Reference
Meta
Query
Mutation
Meta (Optional)
The Meta
class can be used to customize the naming and behavior of these GraphQL operations.
app
(str | bool | None
): Specifies the application name or identifier.model
(str | type | None
): Associates the GraphQL operations with a model. This can be a string representing the model name or an actualtype
class.
Examples
Without Meta
(default)
When the Meta
class is not used:
GraphQL Field Name:
Explanation: The GraphQL field name is automatically generated based on the method name detail
and package/application name demo
.
With model
When the Meta
class specifies a model
:
GraphQL Field Name:
Explanation: The GraphQL field name is prefixed with the model name (Book
), resulting in demoBookDetail
.
With app
Set to None
When the Meta
class specifies app
as None
:
GraphQL Field Name:
Explanation: The app
value is ignored, so the GraphQL field name is based directly on the method name detail
.
With custom app
GraphQL Field Name:
Explanation: The GraphQL field name is automatically generated based on the method name detail
and provided app name custom
.