Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessing slug variables #13

Open
Ximore opened this issue Feb 25, 2019 · 2 comments
Open

Accessing slug variables #13

Ximore opened this issue Feb 25, 2019 · 2 comments
Assignees
Labels

Comments

@Ximore
Copy link

Ximore commented Feb 25, 2019

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.

@judehunter
Copy link

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

@aheinze aheinze self-assigned this May 4, 2019
@aheinze aheinze added the bug label May 4, 2019
@aheinze
Copy link
Member

aheinze commented May 6, 2019

should be fixed now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants