Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
denisart committed Dec 14, 2023
1 parent 3ec150f commit e6ef484
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
66 changes: 66 additions & 0 deletions docs/from_data_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,70 @@ assert generated == [
Field(name="name", fields=[]),
Field(name="friends", fields=[Field(name="name", fields=[])]),
]

Field(name="human", fields=generated).render()
"""human {
name
height(
unit: FOOT
)
}"""
```

We can use arguments for your queries

```python
from pydantic import Field as PydanticField
from graphql_query import Argument, Field, GraphQLQueryBaseModel

class Human(GraphQLQueryBaseModel):
name: str
height: float = PydanticField(graphql_arguments=[Argument(name="unit", value="FOOT")])

generated = Human.graphql_fields()

assert generated == [
Field(name="name", fields=[]), Field(name="height", arguments=[Argument(name="unit", value="FOOT")])
]

Field(name="human", fields=generated).render()
"""human {
name
height(
unit: FOOT
)
}"""
```

For multiply union we have inline fragments

```python
from typing import Union
from graphql_query import Field, GraphQLQueryBaseModel, InlineFragment

class Droid(GraphQLQueryBaseModel):
primaryFunction: str

class Human(GraphQLQueryBaseModel):
height: float

class Hero(GraphQLQueryBaseModel):
name: str
type: Union[Human, Droid]


generated = Hero.graphql_fields()

Field(name="hero", fields=generated).render()
"""hero {
name
type {
... on Human {
height
}
... on Droid {
primaryFunction
}
}
}"""
```
2 changes: 1 addition & 1 deletion graphql_query/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.2.1"
__version__ = "1.2.2"

0 comments on commit e6ef484

Please sign in to comment.