CockpitQL icon indicating copy to clipboard operation
CockpitQL copied to clipboard

Accessing slug variables

Open Ximore opened this issue 6 years ago • 2 comments

Let's consider I have a collection of blog posts called posts. Then I will have access to a GraphQL command called allPosts. This works perfectly fine except when dealing with slugs generated by the text fields with option "slug": true. It is indeed possible to filter using slug but you can't return the slug value as an argument in the gql request.

{
  allPosts(filter: { published: true, title_slug:"banana-test"}) {
    title
    main_image {
      path
    }
    category
    content
  }
}

This works perfectly fine. but if I add the title_slug to the variables I want returned, I get following message:

"Cannot query field \"title_slug\" on type \"posts\". Did you mean \"title\"?"

As a workaround I just reuse the same variable as I used to request the data with, but let's say you have assigned an author to the post, and need the slug of their name to link to all their posts e.g.

{
  allPosts(populate: 1, filter: { published: true, title_slug:"banana-test"}) {
    title
    main_image {
      path
    }
    category
    content
    writer {
      name
      name_slug
    }
  }
}

This won't be possible neither. But if I request the author details separately in a collections request i.e. { collection(name:"writers", filter: {_id: xxxxxxxxxxxxx}) } then I do indeed receive the slug value as part of the entire returned JSON object. I just wished I could return this as part of the nested request as above example.

Ximore avatar Feb 25 '19 17:02 Ximore

I'm also facing this issue. I'd like to get first three posts with slugs, because i use the slugs in links.

judehunter avatar May 02 '19 15:05 judehunter

should be fixed now

aheinze avatar May 06 '19 13:05 aheinze