How do I create a custom argument in GraphQL with graphene-django?
I currently have this configuration in my 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)
But I have not been able to figure out how to make "username" a required argument in the actual GraphQL query on "post".
username
as part of thePost
input type, or as another separate argument to the query. Since you don't show yourPost
model, it's not clear if username is already part of it. – Lanam