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)

Most upvoted comments

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.

You should check it out in its current state, it’s about complete.

I’ll check it out!

I’m actually having a bit of a CORS error on the client side with a redirect issue going on. Here’s the error I’m getting: “Access to fetch at ‘http://localhost:8000/gql’ from origin ‘http://localhost:3000’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: Redirect is not allowed for a preflight request.”.

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_WHITELIST settings, but they’re currently handling my own React-Relay frontend just fine.

Also note that, in my Environment.js file, the network declaration looks like this:

  const network = Network.create((operation, variables) => {
    // 4
    return fetch('http://localhost:8004/graphql', {
      method: 'POST',
      credentials: 'include',
      headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
      },
      body: JSON.stringify({
        query: operation.text,
        variables
      }),
    }).then(response => {
      return response.json()
    })
  })

I hear you can fix that by using corsheaders in the venv but unfortunately my pip install django-cors-headers doesn’t actually generate a django-corsheaders in the venv and my entire thing fails to load.

Yeah, that’s one of those dmmit-it’s-named-differently package things. django-cors-headers installs corsheaders and not django-cors-headers, though I believe you should have django_cors_headers-3.0.1.dist-info somewhere in there. If you don’t see either one, double- and triple-check that you’re installing them with your venv activated, and not system-wide.

Could you give me a hand patching the last thing on?

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-django wiki, so it seems to fit.

Cheers! And do let us know if this works or not. Pretty sure that’d be fine here.

@changeling well done / thank you for helping out!

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.py and one in chores/schema.py.

I renamed one to ResourceCreateInputType and now your project loads, with graphiql opening, so it all looks good.

Added the change to my PR on your repository. Cheers!