Skip to content

Commit

Permalink
fix: resolve arguments correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
ruisaraiva19 committed Oct 9, 2020
1 parent 76d0f95 commit d36d4bb
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
20 changes: 10 additions & 10 deletions example/images/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
class CustomImage(AbstractImage):
admin_form_fields = Image.admin_form_fields

def custom_image_property(self):
def custom_image_property(self, info, **kwargs):
return "Image Model!"

graphql_fields = (GraphQLString("custom_image_property"),)
graphql_fields = (GraphQLString("custom_image_property", required=True),)


class CustomImageRendition(AbstractRendition):
Expand All @@ -22,15 +22,15 @@ class CustomImageRendition(AbstractRendition):
class Meta:
unique_together = (("image", "filter_spec", "focal_point_key"),)

def custom_rendition_property(self):
def custom_rendition_property(self, info, **kwargs):
return "Rendition Model!"

graphql_fields = (
GraphQLString("custom_rendition_property"),
GraphQLInt("id"),
GraphQLString("url"),
GraphQLString("width"),
GraphQLString("height"),
GraphQLImage("image"),
GraphQLString("file"),
GraphQLString("custom_rendition_property", required=True),
GraphQLInt("id", required=True),
GraphQLString("url", required=True),
GraphQLString("width", required=True),
GraphQLString("height", required=True),
GraphQLImage("image", required=True),
GraphQLString("file", required=True),
)
2 changes: 1 addition & 1 deletion grapple/types/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Meta:
file_hash = graphene.String()
url = graphene.String(required=True)

def resolve_url(self, info):
def resolve_url(self, info, **kwargs):
"""
Get document file url.
"""
Expand Down
10 changes: 4 additions & 6 deletions grapple/types/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,21 @@


class BaseImageObjectType(graphene.ObjectType):
id = graphene.ID(required=True)
width = graphene.Int(required=True)
height = graphene.Int(required=True)
src = graphene.String(required=True, deprecation_reason="Use the `url` attribute")
url = graphene.String(required=True)
aspect_ratio = graphene.Float(required=True)
sizes = graphene.String(required=True)

def resolve_url(self, info):
def resolve_url(self, info, **kwargs):
"""
Get the uploaded image url.
"""
return get_media_item_url(self)

def resolve_src(self, info):
def resolve_src(self, info, **kwargs):
"""
Deprecated. Use the `url` attribute.
"""
Expand All @@ -38,14 +39,11 @@ def resolve_aspect_ratio(self, info, **kwargs):
"""
return self.width / self.height

def resolve_sizes(self, info):
def resolve_sizes(self, info, **kwargs):
return "(max-width: {}px) 100vw, {}px".format(self.width, self.width)


class ImageRenditionObjectType(DjangoObjectType, BaseImageObjectType):
id = graphene.ID(required=True)
url = graphene.String(required=True)

class Meta:
model = WagtailImageRendition

Expand Down
2 changes: 1 addition & 1 deletion grapple/types/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Meta:

url = graphene.String(required=True)

def resolve_url(self, info):
def resolve_url(self, info, **kwargs):
"""
Get Media file url.
"""
Expand Down
7 changes: 3 additions & 4 deletions grapple/types/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from wagtail_headless_preview.signals import preview_update
from graphene_django.types import DjangoObjectType
from graphql.error import GraphQLLocatedError
from graphql.execution.base import ResolveInfo

try:
from channels.routing import route_class
Expand Down Expand Up @@ -54,7 +53,7 @@ class PageInterface(graphene.Interface):
)

@classmethod
def resolve_type(cls, instance, info: ResolveInfo):
def resolve_type(cls, instance, info, **kwargs):
"""
If model has a custom Graphene Node type in registry then use it,
otherwise use base page type.
Expand All @@ -65,7 +64,7 @@ def resolve_type(cls, instance, info: ResolveInfo):
else:
return Page

def resolve_content_type(self, info: ResolveInfo):
def resolve_content_type(self, info, **kwargs):
self.content_type = ContentType.objects.get_for_model(self)
return (
self.content_type.app_label + "." + self.content_type.model_class().__name__
Expand Down Expand Up @@ -144,7 +143,7 @@ def resolve_ancestors(self, info, **kwargs):
self.get_ancestors().live().public().specific(), info, **kwargs
)

def resolve_seo_title(self, info):
def resolve_seo_title(self, info, **kwargs):
"""
Get page's SEO title. Fallback to a normal page's title if absent.
"""
Expand Down
2 changes: 1 addition & 1 deletion grapple/types/streamfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class RichTextBlock(graphene.ObjectType):
class Meta:
interfaces = (StreamFieldInterface,)

def resolve_value(self, value):
def resolve_value(self, info, **kwargs):
# Allow custom markup for RichText
return render_to_string(
"wagtailcore/richtext.html", {"html": expand_db_html(self.value.source)}
Expand Down
6 changes: 3 additions & 3 deletions grapple/types/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class TagObjectType(graphene.ObjectType):
tag_id = graphene.ID(name="id", required=True)
name = graphene.String(required=True)

def resolve_tag_id(self, info):
def resolve_tag_id(self, info, **kwargs):
return self.id

def resolve_name(self, info):
def resolve_name(self, info, **kwargs):
return self.name


Expand All @@ -32,7 +32,7 @@ class Mixin:
graphene.NonNull(TagObjectType), required=True, enable_search=False
)

def resolve_tag(self, info, id):
def resolve_tag(self, info, id, **kwargs):
try:
return Tag.objects.get(pk=id)
except BaseException:
Expand Down

0 comments on commit d36d4bb

Please sign in to comment.