graphene-django: Unknown Argument ValueError Issue - Unable to Diagnose Cause
I’ve been having issues with one of my passed mutation arguments that keeps triggering the middleware exception leak checker on graphiql interface load. Migrations and server start are just fine, but loading the url for the interface delivers a "ValueError at /graphql/ Unknown argument “assignee”. " error about.
The following are the directly relevant code snippets.
So I’ve build a “chores” model as such:
class Chore(models.Model):
name = models.TextField(blank=True)
description = models.TextField(blank=True)
isAllDay = models.BooleanField(blank=False)
points = models.IntegerField(blank=False)
status = models.IntegerField(blank=False, null=False)
recurrence_pattern = models.IntegerField(null=False, blank=False)
recurrence_enddate = models.DateTimeField(null=True, blank=False)
deadline = models.DateTimeField(blank=False)
created_by = models.ForeignKey(
'users.User',
related_name='chores_created',
on_delete=models.SET_NULL,
null=True,
)
assigned_to = models.ForeignKey(
'users.User',
related_name='chores_assigned',
on_delete=models.SET_NULL,
null=True,
)
belongs_to = models.ForeignKey(
'households.Household',
related_name="chores",
on_delete=models.SET_NULL,
null=True,
)
Below is the relevant schema portion, including the Type decleration and the InputObjectType I’m utilizing within that same query. I’ve included these portions as I have a strong hunch that the “assignee” value has nothing to do with the actual error, alas, I cannot figure out what it may be.
class ChoreType(DjangoObjectType):
class Meta:
model = Chore
class ResourceCreateInput(graphene.InputObjectType):
name = graphene.String(required = True)
checked = graphene.Boolean(required = True)
class AddChore(graphene.Mutation):
chore = graphene.Field(ChoreType)
class Arguments:
name = graphene.String(),
description= graphene.String(),
isAllDay= graphene.Boolean,
points= graphene.Int(),
status= graphene.Int(),
recurrence_pattern= graphene.Int(),
recurrence_enddate= graphene.DateTime(),
deadline= graphene.DateTime(),
creator= graphene.Int(), # userid
assignee= graphene.Int(), # userid
resources= graphene.List(ResourceCreateInput)
def mutate(self, info, isAllDay, points, status, recurrence_pattern, recurrence_enddate, deadline, creator, assignee = None, resources = None, name = None, description = None):
cUser = User.objects.filter(id=creator).first()
if not cUser:
raise GraphQLError('Invalid Link!')
if assignee != None:
aUser = User.objects.filter(id=assignee).first()
if not aUser:
raise GraphQLError('Invalid Link!')
else:
aUser = None
household = Household.objects.filter(id = 1)
chore = Chore(
name = name,
description = description,
isAllDay = isAllDay,
points = points,
status = status,
recurrence_pattern = recurrence_pattern,
recurrence_enddate = recurrence_enddate,
deadline = deadline,
created_by = cUser,
assigned_to = aUser,
)
chore.save()
if resources != None:
for x in resources:
resource = Resource(
name = x.name,
checked = x.checked,
assigned_to = Chore.objects.get(id__exact = chore.id)
)
resource.save()
return AddChore(
id = chore.id,
)
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 18 (12 by maintainers)
Oh, and a big caveat here: This is only setting up CORS here, and CSRF consideration is important when you approach deploying to the wild. This is a good local development solution, but before you deploy, be absolutely sure to read up on both CORS and CSRF, and the security implications involved.
I’ll check it out!
I’m not positive, but you may be in luck. I just now solved my own CORS issues. I have not had a chance to test it live, but I’ve incorporated the changes I made to my own project which solved CORS being a jerk. I’ve submitted a PR to your project and you can try it out. Let me know if it works for you, but don’t see your frontend stuff in the repo, so can’t confirm or deny that it works.
NOTE: You might want to create a new branch to merge the PR into. If you do, and need me to redirect the PR, lemme know.
HEADS UP: You may need to play around with the
CORS_ORIGIN_WHITELISTsettings, but they’re currently handling my own React-Relay frontend just fine.Also note that, in my
Environment.jsfile, thenetworkdeclaration looks like this:Yeah, that’s one of those dmmit-it’s-named-differently package things.
django-cors-headersinstallscorsheadersand notdjango-cors-headers, though I believe you should havedjango_cors_headers-3.0.1.dist-infosomewhere in there. If you don’t see either one, double- and triple-check that you’re installing them with yourvenvactivated, and not system-wide.Hand given. 😃 Maybe.
Last note: I’m happy, if I have time, to help on occasion, but from here forward, it’s prolly best if you contact me via github rather than in this issue, to avoid spamming here. I’m addressing this one because I’m just about to add the CORS thingie to the
graphene-djangowiki, so it seems to fit.Cheers! And do let us know if this works or not. Pretty sure that’d be fine here.
Glad I could help! I’m becoming pretty attached to this project, and digging into other folks issues is part of getting my head around it all. 😃
@changeling well done / thank you for helping out!
I took another look, and there are actually two types named ResourceCreateInput, one in
resources/schema.pyand one inchores/schema.py.I renamed one to
ResourceCreateInputTypeand now your project loads, withgraphiqlopening, so it all looks good.Added the change to my PR on your repository. Cheers!