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

Issue with GraphQLPage model #60

Closed ruisaraiva19 closed 3 years ago

ruisaraiva19 commented 4 years ago

🐛 Bug Report

I'm having an issue with the GraphQLPage grapple model. It always returns the Wagtail core Page.

💻 Code Sample

I have a snippet with a page property that links to any Wagtail page.

@register_snippet
@register_query_field('Ad', 'Ads')
class Ad(models.Model):
    title = models.CharField(
        max_length=20,
        blank=False,
        default="",
    )
    page = models.ForeignKey(
        "wagtailcore.Page",
        null=True,
        blank=True,
    )

    panels = [
        FieldPanel("title"),
        PageChooserPanel("page"),
    ]

    graphql_fields = [
        GraphQLString("title"),
        GraphQLPage("page"),
    ]

😯 Current Behavior

But when I run the query on GraphiQL, always resolves with the wagtailcore.Page as the contentType.

Query:

{
  Ads {
    page {
      id
      __typename
      contentType
    }
  }
}

Response:

{
  "data": {
    "Ads": [
      {
        "page": {
          "id": "21",
          "__typename": "Page",
          "contentType": "wagtailcore.Page"
        }
      }
    ]
  }
}

🤔 Expected Behavior

I was expecting something like what I get when running the following for the same page.

Query:

{
  page(id: 21) {
    id
    __typename
    contentType
  }
}

Response:

{
  "data": {
    "page": {
      "id": "21",
      "__typename": "Article",
      "contentType": "news.Article"
    }
  }
}
zerolab commented 3 years ago

fixed in 37211857c7b5a1409bfc7b1dcb8320de558d85d8