Skip to content

Commit

Permalink
Document graphql_type on @strawberry.field
Browse files Browse the repository at this point in the history
This documents a use case where the GraphQL type is not the same as data
being used. This is useful if you are using an ORM for your data and
building an API layer against it.
  • Loading branch information
ksylvest committed Nov 14, 2024
1 parent 37eb716 commit d178bf6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions docs/general/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,30 @@ class Query:
return "Strawberry"
```

The decorator syntax supports specifying a `graphql_type` for cases when the
return type of the function does not match the GraphQL type:

```python
class User:
id: str
name: str

def __init__(self, id: str, name: str):
self.id = id
self.name = name

@strawberry.type(name="User")
class UserType:
id: strawberry.ID
name: str

@strawberry.type
class Query:
@strawberry.field(graphql_type=UserType)
def user(self) -> User
return User(id="ringo", name="Ringo")
```

## Arguments

GraphQL fields can accept arguments, usually to filter out or retrieve specific
Expand Down

0 comments on commit d178bf6

Please sign in to comment.