Skip to content

Commit

Permalink
Fix issue with querying value on EmbedBlock (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubMastalerz authored Aug 14, 2024
1 parent 07edf85 commit 0d20a8c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
17 changes: 8 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Unreleased

### Fixed

- `value` not being queryable on `EmbedBlock` ([#399](https://github.com/torchbox/wagtail-grapple/pull/399))@JakubMastalerz

## [0.26.0] - 2024-06-26

### Changed
Expand All @@ -23,7 +27,6 @@

- Support for Django < 4.2, Wagtail < 5.2


## [0.24.0] - 2024-01-05

### Changed
Expand All @@ -35,8 +38,7 @@

### Fixed

- `test_src_set_invalid_format` not working with Wagtail 5.2 and above. ([#378](https://github.com/torchbox/wagtail-grapple/pull/378)) @JakubMastalerz

- `test_src_set_invalid_format` not working with Wagtail 5.2 and above. ([#378](https://github.com/torchbox/wagtail-grapple/pull/378)) @JakubMastalerz

## [0.23.0] - 2023-09-29

Expand All @@ -49,7 +51,6 @@
- `preserveSVG` is true by default ([#371](https://github.com/torchbox/wagtail-grapple/pull/371)) @mgax
- Improvements to the CI pipelines


## [0.22.0] - 2023-09-18

### Added
Expand All @@ -58,7 +59,6 @@
- Allow defining additional interfaces via `graphql_interfaces` ([#366](https://github.com/torchbox/wagtail-grapple/pull/366)) @mgax, @zerolab
This applies to all models, including StreamField blocks


## [0.21.0] - 2023-09-04

### Added
Expand All @@ -74,10 +74,9 @@
- Pass the `GraphQLResolveInfo` object to the StreamField callables ([#356](https://github.com/torchbox/wagtail-grapple/pull/356)) @zerolab
This is passed as the `info` kwarg.
- The image rendition query will now surface any errors when:
- using filters not present in the `ALLOWED_IMAGE_FILTERS` Grapple setting,
- there are no filters to apply (for example you are requesting an SVG rendition but supply raster image operations)
- the source image is not present

- using filters not present in the `ALLOWED_IMAGE_FILTERS` Grapple setting,
- there are no filters to apply (for example you are requesting an SVG rendition but supply raster image operations)
- the source image is not present

## [0.20.0] - 2023-07-10

Expand Down
13 changes: 9 additions & 4 deletions grapple/types/streamfield.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import inspect

from typing import Optional

import graphene

# TODO: use specific imports
Expand Down Expand Up @@ -355,20 +357,23 @@ class EmbedBlock(graphene.ObjectType):
class Meta:
interfaces = (StreamFieldInterface,)

def resolve_url(self, info, **kwargs):
def resolve_url(self: EmbedValue, info, **kwargs) -> str:
return get_embed_url(self)

def resolve_raw_value(self, info, **kwargs):
def resolve_raw_value(self: EmbedValue, info, **kwargs) -> str:
if isinstance(self, EmbedValue):
return self
return StreamFieldInterface.resolve_raw_value(info, **kwargs)

def resolve_embed(self, info, **kwargs):
def resolve_value(self: EmbedValue, info, **kwargs) -> str:
return EmbedBlock.resolve_raw_value(self, info, **kwargs)

def resolve_embed(self: EmbedValue, info, **kwargs) -> Optional[str]:
embed = get_embed_object(self)
if embed:
return embed.html

def resolve_raw_embed(self, info, **kwargs):
def resolve_raw_embed(self: EmbedValue, info, **kwargs) -> Optional[str]:
embed = get_embed_object(self)
if embed:
return {
Expand Down
8 changes: 6 additions & 2 deletions tests/test_blog.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def test_blog_embed(self):
url
embed
rawEmbed
value
rawValue
}
}
Expand All @@ -506,11 +507,14 @@ def test_blog_embed(self):
for block in body:
if block["blockType"] == "VideoBlock":
embed = block["youtubeLink"]
expected_raw_value = "<div>\n {}\n</div>\n".format(embed["embed"])
expected_value = "<div>\n {}\n</div>\n".format(embed["embed"])
self.assertTrue(isinstance(embed["url"], str))
self.assertEqual(embed["embed"], raw_embed["html"])
self.assertEqual(embed["rawEmbed"], json.dumps(raw_embed))
self.assertEqual(embed["rawValue"], expected_raw_value)
self.assertEqual(embed["value"], expected_value)
# For now, both `value` and `raw_value` resolve to the same HTML
# See discussion @ https://github.com/torchbox/wagtail-grapple/pull/399#discussion_r1714917129
self.assertEqual(embed["rawValue"], expected_value)
return

self.fail("VideoBlock type not instantiated in Streamfield")
Expand Down

0 comments on commit 0d20a8c

Please sign in to comment.