torchbox / wagtail-grapple

A Wagtail app that makes building GraphQL endpoints a breeze!
https://wagtail-grapple.readthedocs.io/en/latest/
Other
153 stars 57 forks source link

Pass the `GraphQLResolveInfo` object to the StreamField callables #356

Closed zerolab closed 1 year ago

zerolab commented 1 year ago

Passes the GraphQLResolveInfo object to the custom StreamField resolvers. This is more in line with the expected GraphQL resolver definitions. This would allow using the request context (info.context) for page url resolving (page.get_url(request=info.context)) in a multi-site context

Builds on #220 and #322.

[!WARNING] This is a breaking change and requires existing resolver signatures to be updated.

# before
def get_field(self, value=None):
   ...

def get_field(self, *, value=None):
   ...

# after
def get_field(self, info, value=None):
   ...

def get_field(self, *, info, value=None):
   ...

# or, type hinted
from graphql import GraphQLResolveInfo

def get_field(self, info: GraphQLResolveInfo, value: dict[str, Any] | None):
    ...
kbayliss commented 1 year ago

Suggestion: It would be good to update the testapp with a method that uses the info - perhaps to fetch the page for request?