torchbox / wagtail-grapple

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

ListBlock implementation incomplete? #38

Closed digitaljohn closed 4 years ago

digitaljohn commented 4 years ago

I'm trying to create a simple Gallery Block working for use within a StreamField field. For example:

body = StreamField([
    ('text', MarkdownBlock()),
    ('text_image', TextImageBlock()),
    ('image', ImageChooserBlock()),
    ('url', URLBlock()),
    ('video', VideoBlock()),
    ('code', CodeBlock()),
    ('gallery', ListBlock( ImageChooserBlock() )),
])

The item at the bottom.

Within the GraphQL response when querying, items is being returned as an object rather than array of items and the object returned is actually itself.

Is this implementation complete? I'm by far a Python expert but could it be to do with the below line of code?

https://github.com/torchbox/wagtail-grapple/blob/cb17c951b7b47a014aebccdf15358ac241acd86c/grapple/types/streamfield.py#L329

The items resolve to itself?

claudiopedrom commented 4 years ago

@digitaljohn did you find a solution?

I have the same issue, I can't resolve any of the blocks inside a ListBlock, even using a subclass of StructBlock.

Also, I have a problem using a ImageChooserBlock() inside the ListBlock:

"message": "int() argument must be a string, a bytes-like object or a number, not 'Image'",

My StreamField looks like this:

    body = StreamField([
        ('paragraph', blocks.RichTextBlock()),
        ('slider', blocks.StructBlock([
            ('author', blocks.CharBlock()),
            ('sliders', blocks.ListBlock(blocks.StructBlock([
                ('caption', blocks.CharBlock()),
                ('image', ImageChooserBlock()),
            ])))
        ])),
    ])

My query is also very verbose. Am I doing something wrong?

query Articles {
  pages {
    ... on Article {
      slug
      description
      body {
        ... on RichTextBlock {
          value
        }
        ... on StructBlock {
          blocks {
            ... on CharBlock {
              value
            }
            ... on ListBlock {
              items {
                ... on StructBlock {
                  blocks {
                    ... on CharBlock {
                      value
                    }
                    ... on ImageChooserBlock {
                      image {
                        src
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
digitaljohn commented 4 years ago

@claudiopedrom we did not find a solution and ended up making our approach less deep. It appears this functionality simply is not complete. 🤷‍♂

zerolab commented 4 years ago

@digitaljohn @claudiopedrom, @NathHorrigan maintains this in his free time, so any tweak/improvement is more than welcome.

NathHorrigan commented 4 years ago

This was fixed in https://github.com/torchbox/wagtail-grapple/pull/47

Please see this PR on how to use ListBlock

NathHorrigan commented 4 years ago

@digitaljohn @claudiopedrom

claudiopedrom commented 4 years ago

Thanks @NathHorrigan !

I'll have a look as soon as I have an opportunity.

digitaljohn commented 4 years ago

Thanks @NathHorrigan !