Skip to content

Commit

Permalink
python markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Nina Bernick committed Jul 11, 2024
1 parent 4d60975 commit 727a17b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions docs/custom_code.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ Platformics will generate a GraphQL API that exposes CRUD operations for each en
## Adding root-level queries and mutations
Platformics will generate basic read and aggregate queries in `api/queries.py`. These are inherited by a query class in `custom_queries.py`, which will gain access to all the codegenned queries as well as allow you to implement your own queries. To add a new root level field (query), add the field to the query class in `custom_queries.py`:

```
```python
@strawberry.type
class Query(BaseQuery):
foo: str = my_custom_field
```
The resolver for the custom field should be decorated with `@strawberry.field`:
```
```python
@strawberry.field
def my_custom_field(self) -> str:
return "foo"
```

Similarly, for custom mutations, root level mutations can be added to the `Mutation` class in `custom_mutations.py`, which inherits from the codegenned `Mutation` class in `api/mutations.py`

```
```python
@strawberry.type
class Mutation(BaseMutation):
bar: str = my_custom_mutation
```
The resolver for the custom mutation should be decorated with `@strawberry.mutation`:
```
```python
@strawberry.mutation
def my_custom_mutation(self) -> str:
return "bar"
```
Both the custom query and mutation classes are imported into `main.py` and used by Strawberry to generate an API at runtime:
```
```python
from custom_mutations import Mutation
from custom_queries import Query

Expand All @@ -39,7 +39,7 @@ schema = strawberry.Schema(query=Query, mutation=Mutation, config=get_strawberry

### Overriding queries and mutations
By creating a field with the same name as an existing codegenned query or mutation, you can override the codegenned resolver.
```
```python
@strawberry.mutation
def my_override_mutation(self) -> str:
return "Sorry, I overrode the mutation"
Expand Down

0 comments on commit 727a17b

Please sign in to comment.