From e6ef48439e838096055de65f3154473cbc269643 Mon Sep 17 00:00:00 2001 From: denisart Date: Thu, 14 Dec 2023 23:59:01 +0300 Subject: [PATCH] Update docs --- docs/from_data_model.md | 66 ++++++++++++++++++++++++++++++++++++ graphql_query/__version__.py | 2 +- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/docs/from_data_model.md b/docs/from_data_model.md index 704cf07..8cde020 100644 --- a/docs/from_data_model.md +++ b/docs/from_data_model.md @@ -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 + } + } +}""" ``` diff --git a/graphql_query/__version__.py b/graphql_query/__version__.py index a955fda..bc86c94 100644 --- a/graphql_query/__version__.py +++ b/graphql_query/__version__.py @@ -1 +1 @@ -__version__ = "1.2.1" +__version__ = "1.2.2"