Skip to content

Commit 0d20a8c

Browse files
Fix issue with querying value on EmbedBlock (#399)
1 parent 07edf85 commit 0d20a8c

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

CHANGELOG.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased
22

3+
### Fixed
4+
5+
- `value` not being queryable on `EmbedBlock` ([#399](https://github.com/torchbox/wagtail-grapple/pull/399))@JakubMastalerz
6+
37
## [0.26.0] - 2024-06-26
48

59
### Changed
@@ -23,7 +27,6 @@
2327

2428
- Support for Django < 4.2, Wagtail < 5.2
2529

26-
2730
## [0.24.0] - 2024-01-05
2831

2932
### Changed
@@ -35,8 +38,7 @@
3538

3639
### Fixed
3740

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

4143
## [0.23.0] - 2023-09-29
4244

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

52-
5354
## [0.22.0] - 2023-09-18
5455

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

61-
6262
## [0.21.0] - 2023-09-04
6363

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

8281
## [0.20.0] - 2023-07-10
8382

grapple/types/streamfield.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import inspect
22

3+
from typing import Optional
4+
35
import graphene
46

57
# TODO: use specific imports
@@ -355,20 +357,23 @@ class EmbedBlock(graphene.ObjectType):
355357
class Meta:
356358
interfaces = (StreamFieldInterface,)
357359

358-
def resolve_url(self, info, **kwargs):
360+
def resolve_url(self: EmbedValue, info, **kwargs) -> str:
359361
return get_embed_url(self)
360362

361-
def resolve_raw_value(self, info, **kwargs):
363+
def resolve_raw_value(self: EmbedValue, info, **kwargs) -> str:
362364
if isinstance(self, EmbedValue):
363365
return self
364366
return StreamFieldInterface.resolve_raw_value(info, **kwargs)
365367

366-
def resolve_embed(self, info, **kwargs):
368+
def resolve_value(self: EmbedValue, info, **kwargs) -> str:
369+
return EmbedBlock.resolve_raw_value(self, info, **kwargs)
370+
371+
def resolve_embed(self: EmbedValue, info, **kwargs) -> Optional[str]:
367372
embed = get_embed_object(self)
368373
if embed:
369374
return embed.html
370375

371-
def resolve_raw_embed(self, info, **kwargs):
376+
def resolve_raw_embed(self: EmbedValue, info, **kwargs) -> Optional[str]:
372377
embed = get_embed_object(self)
373378
if embed:
374379
return {

tests/test_blog.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def test_blog_embed(self):
481481
url
482482
embed
483483
rawEmbed
484+
value
484485
rawValue
485486
}
486487
}
@@ -506,11 +507,14 @@ def test_blog_embed(self):
506507
for block in body:
507508
if block["blockType"] == "VideoBlock":
508509
embed = block["youtubeLink"]
509-
expected_raw_value = "<div>\n {}\n</div>\n".format(embed["embed"])
510+
expected_value = "<div>\n {}\n</div>\n".format(embed["embed"])
510511
self.assertTrue(isinstance(embed["url"], str))
511512
self.assertEqual(embed["embed"], raw_embed["html"])
512513
self.assertEqual(embed["rawEmbed"], json.dumps(raw_embed))
513-
self.assertEqual(embed["rawValue"], expected_raw_value)
514+
self.assertEqual(embed["value"], expected_value)
515+
# For now, both `value` and `raw_value` resolve to the same HTML
516+
# See discussion @ https://github.com/torchbox/wagtail-grapple/pull/399#discussion_r1714917129
517+
self.assertEqual(embed["rawValue"], expected_value)
514518
return
515519

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

0 commit comments

Comments
 (0)