如何使用graphene-django在GraphQL中创建自定义参数?
我目前在schema.py中具有此配置:
class Post(DjangoObjectType):
class Meta:
model = FeedPost
interfaces = (graphene.relay.Node,)
filter_fields = ['id']
class Query(graphene.ObjectType):
post = graphene.Node.Field(Post)
def resolve_post(self, info, **kwargs):
username = kwargs.get('username')
u = User.objects.get(username=username)
users_sources = FeedSource.objects.filter(user=u)
return FeedPost.objects.filter(feed__feedsource__in=users_sources).annotate(
source_title=F('feed__feedsource__title')
)
schema = graphene.Schema(query=Query)
但是我无法弄清楚如何在“ post”上的实际GraphQL查询中将“ username”作为必需参数。