Jonesus / gatsby-source-directus7

Source plugin for pulling data into GatsbyJS from Directus CMS (https://directus.io)
16 stars 14 forks source link

Filter for articles with translations seems broke #15

Closed visualcookie closed 4 years ago

visualcookie commented 5 years ago

Hey.

When requesting an article with a translations filter, to only get e.g. en, it doesn't work. It still returns all articles.

query {
  allDirectusArticle(filter: {translations: {elemMatch: {language: {eq: "en"}}}}) {
    edges {
      node {
        translations {
          title
          slug
          excerpt
          language
        }
      }
    }
  }
}
{
  "data": {
    "allDirectusArticle": {
      "edges": [
        {
          "node": {
            "translations": [
              {
                "title": "10 tips to manage your finances",
                "slug": "10-tips-to-manage-your-finances",
                "excerpt": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Qui est in parvis malis.",
                "language": "en"
              },
              {
                "title": "10 Tipps, wie Sie Ihre Finanzen verwalten können",
                "slug": "10-tipps-wie-sie-ihre-finanzen-verwalten-konnen",
                "excerpt": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Qui est in parvis malis.",
                "language": "de"
              }
            ]
          }
        }
      ]
    }
  }
}
HashemKhalifa commented 5 years ago

@visualcookie I'm having the same issue anyway!

would you mind to tell me how you managed to do the translations as it works fine with the normal graphql app and when using the plugins I'm not able to fetch the translation at all!

visualcookie commented 5 years ago

@HashemKhalifa Sure, I did some hacky stuff for now.

{articles.map(({ node }): React$Node => {
  // TODO: Remove it as soon as the filter function issue has been resolved
  const translatedArticle = node.translations.filter(
    a => a.language === intl.locale
  )

  return (
    <>
      {translatedArticle.map(article => (
        <Article
          tag={node.category}
          author={node.author}
          date={node.created_on}
          article={article}
        />
      ))}
    </>
  )
})}
HashemKhalifa commented 5 years ago

@visualcookie Thank you so much! The issue I'm currently facing is after creating the translation I can access it from the API with plain graphql for example.

{
    share_campaign{
    data{
      translation {
        language_code
        title,
        subtitle
      }
      domain{
        name
      }
      title
      subtitle    
}

  }
}

and with gatsby, I couldn't find the translations object in the response. "message": "Cannot query field \"translation\" on type \"DirectusShareCampaign\".",

visualcookie commented 5 years ago

@HashemKhalifa Have you checked the GraphiQL interface, that's provided with Gatsby if the translations are in there?

HashemKhalifa commented 5 years ago

@visualcookie yes, not even there! I can get only from the DirectusShareCampaignTranslation for example but I couldn't find it in the GraphQl interface.

I followed the docs but I'm not sure if I missed something!

HashemKhalifa commented 5 years ago

@visualcookie the problem is GSD7: warning Could not find an Many-To-One match in 'share_campaign' for item in 'share_campaign_translations'

visualcookie commented 5 years ago

@HashemKhalifa Hm, actually can't help you there. Maybe the author can help, but I don't know if he's still actively pursuing this source plugin.

HashemKhalifa commented 5 years ago

@visualcookie thanks a lot, I will try to create a pull request with the fix

Jonesus commented 4 years ago

Hi @HashemKhalifa and @visualcookie !

Sorry for the long silence, I've been quite busy with other stuff recently. As for the issue, a new official plugin has been created at https://github.com/directus/gatsby-source, and thus this project won't be maintained anymore. You should go try it out instead and see if it works out for you and if not, open a new issue in that repo :)