-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
How to query all posts by an author when you have multiple authors per post #7251
Comments
it would help if you share your repo. so that i could see details and test stuff :) export const query = graphql`
query($id: String!) {
-allMarkdownRemark(filter: { frontmatter: { authors: { in: [$id] } } } ) {
+allMarkdownRemark(filter: { frontmatter: { authors: { eq: $id } } } ) {
edges {
node {
...
html
...
}
}
}
}
` |
Hi @cezarneaga, thanks for your response! I setup an example in this repo. The build is currently failing because the query in |
hmm, i think there might be an issue with implementation of the query should be of the shape:
because authors is of i would ask for guidance from @KyleAMathews on this. best, |
Please create minimal reproduction repo - I was implementing ---edit |
Hi @pieh, thanks for taking a look. Please let me know if you need any help. |
I am trying to do the exact same mapping on my project and struck while creating a query for listing posts created by a particular author. I guess #7385 might be related to this and tackled together. |
Maybe @pieh already had some time to take a look? |
Problem here is we don't create proper filter schema for mapped fields - we need to add support for that |
All right - here's is WIP working branch that enables filtering by mapped fields master...pieh:mapping-filter-schema - this need to be cleaned up and tests definitely need to be added (and maybe more tests need to be updated) |
Until the branch is accepted and merged, do we simply filter using |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! Thanks for being a part of the Gatsby community! 💪💜 |
@pieh Not sure it's the same issue, but I also have problems with elemMatch: |
@godmuahaha so this actually works correctly - but probably doesn't do what you want it to do Filter only filter outs top level nodes - so it tries to find personalJson node, that contains item with level 2. And returned node satisfy that condition. But it doesn't filter |
@pieh, got it! Thanks for explanation, that feature would be very useful, I have an array of ~300 items and need only one of them |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m Thanks again for being part of the Gatsby community! |
@freiksenet @stefanprobst is this fixable now? |
This should be working already: {
allMarkdownRemark(filter: {frontmatter: {authors: {elemMatch: {id: {eq: $id}}}}}) {
edges {
node {
frontmatter {
title
authors {
id
name
}
}
}
}
}
} Note that filtering by {
allMarkdownRemark(filter: {frontmatter: {authors: {elemMatch: {name: {eq: "Jane Doe"}}}}}) {
edges {
node {
frontmatter {
title
authors {
id
name
}
}
}
}
}
} There are other approaches to getting posts by author as well, for example you can add a @gurtjun sidenote: make sure to use |
Yup, I can also confirm this is working fine cc: @KyleAMathews @stefanprobst |
I am trying to do exactly this with a variable list and getting a specific entry by it's type and it is not working. my query is:
it is returning an array with all sections regardless of their type is there a way to use createResolve to add a getByType query to the MarkdownRemarkFrontmatterSectionsFilterListInput type? |
Summary
I'm working on a blog where one blogpost can have multiple authors. I got this working with mappings between my nodes. I can query for a markdown file and get all the linked authors.
Now I'm working on a page for each author that displays all the posts he/she contributed to. How can this be done? Below you can find the query I'm currently using, but that one's not working (
author.js
).I setup an example in this repo.
Relevant information
File contents
gatsby-config.js
:gatsby-node.js
:src/pages/blog/example-blog-post.md
src/data/author.yaml
src/templates/author.js
The text was updated successfully, but these errors were encountered: