Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

There's some way to set the `source` field param for nested fields?

オープン
#1,439 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
python
領域
api, backend

調査の方向性

参照されている source 解決コードがある graphene/types/field.py から始め、DjangoObjectType フィールドが source 値をどのように使用するかを追跡します。actor__login の例を現在のカスタム resolver の代替方法と比較します。目的のネストされたリレーションシップの動作がサポートされるか、制限事項と想定される resolver のアプローチが文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Context

I'm currently trying to set my model user User subfield user.actor.id as field source of my DjangoObjectType.

This happens because there's other kind of users within the application like an Organization or even a Bot (all of them are actors).

Example

Lets define a custom Type:

class User(DjangoObjectType):
    class Meta:
        model = UserModel
        exclude = ['actor']
        filter_fields = ['actor__login']
        interfaces = [graphene.relay.Node]
        skip_registry = True

    # The login field is originated from `actor` relationship, not from the user model itself.
    # It doesn't work, actor__login is interpreted as user field [user.actor__login] not [user.actor.login].
    login = graphene.Field(graphene.String, source='actor__login')
    # ...

In the example above I define the login field source as source='actor__login' but I saw that here we're using getattr function to resolve the source so it's currently impossible to set the field without defining a custom resolver.

https://github.com/graphql-python/graphene/blob/dfece7f65d4bad51a87a8e9f03f9acef1e25d3f8/graphene/types/field.py#L16-L20

I would like to know if there's an alternative solution to select a subfield like the example or we're forced to create a custom resolver by using the resolver=lambda _, __: ... arg or the class method declaration.

Thanks for the hard work and the library!

主要言語
Python
スター
8.2k
フォーク
818
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphql-python/graphene のほかの issue

graphql-python/graphene の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。