Please Add Further Support for FastAPI or Pydantic ObjectTypes
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 20/100
- issue の種類
- 機能追加
- 明瞭さ
- 説明が足りない
- 活発さ
- 停滞
- 領域
- api, backend, backend-api-design
調査の方向性
この例は graphql/mutations.py、graphql/types.py、graphql/queries.py、models/customers.py にまたがり、TortoiseORM の pydantic_model_creator を使用しています。まず、Graphene ObjectTypes と mutation の引数が現在どのように宣言されているかを追跡してください。実装を提案する前に、サポートする FastAPI/Pydantic 統合とその完了基準を定義してください。この issue では対象のエントリーポイントもテストも指定されていないためです。
索引モデルが issue の本文から書いたものです。
説明
I want to avoid repeating code fragments between the mutations and types with graphene in a FastAPI app.
Not a very polished example but please see below sample scenario.
graphql\mutations.py
import graphene
from models.customers import CustomerLogin, CustomerLogin_PydanticIn
from graphql.types import CustomerLoginType
class CreateUserMutation(graphene.Mutation):
class Arguments:
id = graphene.Int()
shard_id = graphene.Decimal()
seq_num = graphene.Decimal()
event_timedate = graphene.DateTime()
user_id = graphene.UUID()
device_token = graphene.UUID()
user_ip = graphene.String()
user_agent = graphene.String()
client_id = graphene.String()
process = graphene.String()
auth_result = graphene.String()
auth_fail_cause = graphene.String()
plain_email = graphene.String()
user = graphene.Field(CustomerLoginType)
@staticmethod
async def mutate(parent, info, user: CustomerLogin_PydanticIn):
user = await CustomerLogin.create(**user.dict())
return CreateUserMutation(user=user)
graphql\types.py
import graphene
# Fields should coincide with model.CustomerLogin
class CustomerLoginType(graphene.ObjectType):
id = graphene.Int()
shard_id = graphene.Decimal()
seq_num = graphene.Decimal()
event_timedate = graphene.DateTime()
user_id = graphene.UUID()
device_token = graphene.UUID()
user_ip = graphene.String()
user_agent = graphene.String()
client_id = graphene.String()
process = graphene.String()
auth_result = graphene.String()
auth_fail_cause = graphene.String()
plain_email = graphene.String()
graphql\queries.py
import graphene
from models.customers import CustomerLogin
from graphql.types import CustomerLoginType
class Query(graphene.ObjectType):
all_customer_logins = graphene.List(CustomerLoginType)
single_customer_login = graphene.Field(CustomerLoginType, id=graphene.Int())
@staticmethod
async def resolve_all_customer_logins(parent, info):
users = await CustomerLogin.all()
return users
@staticmethod
async def resolve_single_customer_login(parent, info, id):
user = await CustomerLogin.get(id=id)
return user
Then the ORM model using TortoiseORM
models\customers.py
from tortoise import fields
from tortoise.contrib.pydantic import pydantic_model_creator
from tortoise.models import Model
from models.events import ShardID, SequenceNum
class CustomerLogin(Model):
shard_id: fields.ForeignKeyNullableRelation[ShardID] = \
fields.ForeignKeyField(model_name='models.ShardID',
related_name='customerlogin_shardid',
to_field='shard_id',
on_delete=fields.RESTRICT,
null=True)
seq_num: fields.ForeignKeyNullableRelation[SequenceNum] = \
fields.ForeignKeyField(model_name='models.SequenceNum',
related_name='customerlogin_seqnum',
to_field='seq_num',
on_delete=fields.RESTRICT,
null=True)
event_timedate = fields.DatetimeField(null=True)
user_id = fields.UUIDField(null=True)
device_token = fields.UUIDField(null=True)
user_ip = fields.CharField(256, null=True)
user_agent = fields.CharField(1024, null=True)
client_id = fields.CharField(256, null=True)
process = fields.CharField(256, null=True)
auth_result = fields.CharField(256, null=True)
auth_fail_cause = fields.CharField(256, null=True)
plain_email = fields.CharField(256, null=True)
CustomerLogin_Pydantic = pydantic_model_creator(CustomerLogin, name='CustomerLogin')
CustomerLogin_PydanticIn = pydantic_model_creator(CustomerLogin, name='CustomerLoginIn', exclude_readonly=True)
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 818
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
graphql-python/graphene のほかの issue
-
Tutorial mistakes オープン🐛 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
graphql-python/graphene#1389 · コメント 5 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 support オープン✨ enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
graphql-python/graphene#1601 · コメント 2 件 ·
-
✨ enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
graphql-python/graphene#1593 ·
graphql-python/graphene の issue をすべて見る
似ている issue
-
agent-ready documentation needs-triage
難易度 1/5 1〜3時間 初心者へのやさしさ 88/100
-
documentation
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
-
workflow-status page template still says reusable workflows are "triggered only by workflow_call:" オープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
-
instance instance add
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
searxng/searx-instances#939 · コメント 1 件 ·
-
area-deployment area-integrations triage:bot-seen
難易度 2/5 半日 初心者へのやさしさ 86/100