Convert pydantic schema to pydantic datamodel and build request from it
Project description
GraphQL to Pydantic Transformer & Pydantic to Query Builder
Overview
The GraphQL to Pydantic Transformer is a Python package designed to simplify the process of transforming GraphQL schemas in JSON format into Pydantic models. This tool is particularly useful for developers working with GraphQL APIs who want to generate Pydantic models from GraphQL types for efficient data validation and serialization/deserialization.
Features
- Converts GraphQL schemas in JSON format into Pydantic models.
- Build query or mutation from pydantic dataclass
Installation
You can install the GraphQL to Pydantic Transformer package via pip:
pip install graphql-pydantic-transformer
Usage
Cli tool to transform GraphQL JSON to Pydantic
graphql-pydantic-converter [-h] [-i INPUT_FILE] [-o OUTPUT_FILE] [--url URL] [--headers HEADERS [HEADERS ...] ]
options:
-h, --help show this help message and exit
-i INPUT_FILE, --input-file INPUT_FILE
-o OUTPUT_FILE, --output-file OUTPUT_FILE
--url URL
--headers HEADERS [HEADERS ...] # --headers "HeaderName: HeaderValue" "HeaderName: HeaderValue"
Output from cli tool
import typing
from pydantic import Field
from graphql_pydantic_converter.graphql_types import Input
from graphql_pydantic_converter.graphql_types import Mutation
from graphql_pydantic_converter.graphql_types import Payload
Boolean: typing.TypeAlias = bool
DateTime: typing.TypeAlias = typing.Any
Float: typing.TypeAlias = float
ID: typing.TypeAlias = str
Int: typing.TypeAlias = int
JSON: typing.TypeAlias = typing.Any
String: typing.TypeAlias = str
class CreateScheduleInput(Input):
name: String
workflow_name: String = Field(alias='workflowName')
workflow_version: String = Field(alias='workflowVersion')
cron_string: String = Field(alias='cronString')
enabled: typing.Optional[Boolean]
parallel_runs: typing.Optional[Boolean] = Field(alias='parallelRuns')
workflow_context: typing.Optional[String] = Field(alias='workflowContext')
from_date: typing.Optional[DateTime] = Field(alias='fromDate')
to_date: typing.Optional[DateTime] = Field(alias='toDate')
class Schedule(Payload):
name: typing.Optional[Boolean] = Field(response='String', default=True)
enabled: typing.Optional[Boolean] = Field(response='Boolean', default=True)
parallel_runs: typing.Optional[Boolean] = Field(response='Boolean', alias='parallelRuns', default=True)
workflow_name: typing.Optional[Boolean] = Field(response='String', alias='workflowName', default=True)
workflow_version: typing.Optional[Boolean] = Field(response='String', alias='workflowVersion', default=True)
cron_string: typing.Optional[Boolean] = Field(response='String', alias='cronString', default=True)
workflow_context: typing.Optional[Boolean] = Field(response='String', alias='workflowContext', default=True)
from_date: typing.Optional[Boolean] = Field(response='DateTime', alias='fromDate', default=True)
to_date: typing.Optional[Boolean] = Field(response='DateTime', alias='toDate', default=True)
status: typing.Optional[Boolean] = Field(response='Status', default=True)
class CreateScheduleMutation(Mutation):
_name: str = Field('createSchedule', const=True)
input: CreateScheduleInput
payload: Schedule
CreateScheduleInput.update_forward_refs()
CreateScheduleMutation.update_forward_refs()
Schedule.update_forward_refs()
Query & Mutation builder
from schedule_api import Schedule, CreateScheduleMutation, CreateScheduleInput
SCHEDULE: Schedule = Schedule(
name=True,
enabled=True,
workflowName=True,
workflowVersion=True,
cronString=True,
fromDate=False,
toDate=False,
status=False
)
mutation = CreateScheduleMutation(
payload=SCHEDULE,
input=CreateScheduleInput(
name='name',
workflowName='workflowName',
workflowVersion='workflowVersion',
cronString='* * * * *',
enabled=True,
parallelRuns=False,
)
)
mutation.render()
Created query
mutation {
createSchedule(
input: {
name: "name"
workflowName: "workflowName"
workflowVersion: "workflowVersion"
cronString: "* * * * *"
enabled: true
parallelRuns: false
}
) {
name
enabled
parallelRuns
workflowName
workflowVersion
cronString
workflowContext
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file graphql_pydantic_transformer-0.0.2.tar.gz
.
File metadata
- Download URL: graphql_pydantic_transformer-0.0.2.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.9 Linux/5.15.0-79-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 17c569eeea24cc90e201fb14ebdf7056e0a7d04415ac20d8dbba649eb44e4973 |
|
MD5 | 56cece35ae231a2b7a49ba1d95748f44 |
|
BLAKE2b-256 | b2026e4b4b82c1f70532ff49624e343be33885ccb8d06125a7aaae0970281d63 |
File details
Details for the file graphql_pydantic_transformer-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: graphql_pydantic_transformer-0.0.2-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.9 Linux/5.15.0-79-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e130314658f5e20dac0d154864504d032a33d457c54719e36c08c0703b92df1 |
|
MD5 | 9c4320b420c636f6d4f79f7dc72366fd |
|
BLAKE2b-256 | 106db455679152d22d23a2e73c36a89a1e3eeef9f9b6037e45e363c9e9de3c70 |