mirumee / ariadne-website

The code that powers Ariadne website
https://ariadnegraphql.org
BSD 3-Clause "New" or "Revised" License
24 stars 36 forks source link

Callable fields require one extra argument for info object #171

Closed heikkiket closed 8 months ago

heikkiket commented 3 years ago

Per documentation, this should work:

type_def = """
    type User {
        username: String!
        likes: Int!
        initials(length: Int!): String
    }
"""

class UserObj:
    username = "admin"

    def likes(self):
        return count_user_likes(self)

    def initials(self, length):
        return self.username[:length]

However, when I ran this example and tried making a query like this:

{
 user {
   likes
 }
}

I got an error: likes() takes 1 positional argument but 2 were given

When I changed likes method to be: def likes(self, info) it seemed to work.

Suggested fix: callable fields don't require an extra argument

Originally posted by @heikkiket in https://github.com/mirumee/ariadne/discussions/691

rafalp commented 8 months ago

Documentation is incorrect here. We are using default resolver from the graphql-core, which has the info, **kwargs signature.