24hoursmedia-craftcms / views-work

Craft CMS views plugin
Other
1 stars 2 forks source link

GraphQL support #58

Open ThinkGraphical opened 3 years ago

ThinkGraphical commented 3 years ago

When I try accessing the Views Work field through GraphQL in the following way:

query feed {
  entry {
    ... on feed_articles_Entry {
      id
      views
    }
  }
}

I get the following message:

{
  "errors": [
    {
      "message": "String cannot represent value: instance of twentyfourhoursmedia\\viewswork\\models\\ViewRecording",
      "extensions": {
        "category": "graphql"
      }
    }
  ],
  "data": {
    "entry": {
      "id": "174",
      "views": null
    }
  }
}

Is Views Work not supporting GraphQL or am I missing something? If not: is this added any time soon? Or tips on how to implement it ourselves? Same for the 'orderByPopular',... twig helpers in the GraphQL query.

24hoursmedia-craftcms commented 3 years ago

@ThinkGraphical I have not tested with GraphQL.

But the problem seems that 'views' is a model (object), not a number. I think you should query something like views.today, views.total, views.thisMonth, views.thisWeek (but don't know the exact graphql syntax to get properties from objects)