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.1.tar.gz
.
File metadata
- Download URL: graphql_pydantic_transformer-0.0.1.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 | 6ea6567cecdbf05b53d88a4f4701ef4e081a4265bcdacce93b2038a3a5c88355 |
|
MD5 | 8b3e7a79d93dd37433e248a7d3031d4a |
|
BLAKE2b-256 | 2b54f5f4343849825ea651dd276d5c796f79db36ace1a7ce758b1662def0adc5 |
File details
Details for the file graphql_pydantic_transformer-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: graphql_pydantic_transformer-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.2 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 | bcd0d22b001505526447cf1a98ac3b70e631136222332300ee16d1284d6d4d7d |
|
MD5 | f81d5adff2a22d722d816a5733aaa40a |
|
BLAKE2b-256 | 51c081e7a131724cf6fa37bafdd9ccb0aec4be14a52892833f43809b480a4913 |