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

Help create GraphQL query to filter content items by culture #6136

Closed
minhdn2 opened this issue May 8, 2020 · 8 comments
Closed

Help create GraphQL query to filter content items by culture #6136

minhdn2 opened this issue May 8, 2020 · 8 comments
Labels
Milestone

Comments

@minhdn2
Copy link

minhdn2 commented May 8, 2020

Hi,

I have multiple localized content items with 2 cultures (id-ID and en-US) in each content items. Now I need to get all the localized versions for id-ID of all the content items but I'm not sure how and being blocked by LocalizationSet.

query MyQuery { sliderItems(where: {localization: {localizationSet: "", culture: "id-ID"}}) { displayText localization { culture localizationSet } } }

How can I insert multiple values for the required field LocalizationSet? Or how can I ignore this mandatory field?

Please help to check and advise,
Many thanks in advance

@hishamco
Copy link
Member

hishamco commented May 9, 2020

How can I insert multiple values for the required field LocalizationSet?

Why you need to insert multiple values there?!!

@jrestall @carlwoodhouse any idea from GraphQL point of view?

@carlwoodhouse
Copy link
Member

Possibly need to know a little more of what’s trying to be achieved here ..

Presuming it’s query by multiple localization sets or cultures ..

I’m not that familiar with the localisation stuff but I assume the filter doesn’t support it out of the box easily ...

But you could always use ‘and’ in the where clause to achieve the he same thing..

Where: { localization: { set: “”, culture: “xx” } and localization { ... }}

That been said (presuming we don’t already I haven’t checked the code) we really should make culture support the in operators

@minhdn2
Copy link
Author

minhdn2 commented May 10, 2020

Basically, I have a pace need to be implemented with localization.

I have been creating content items for this page, and each content items will have 2 localized items, which are id-ID and en-US.

In default, the page is displayed in en-US. So when user choose to display the page in id-ID, I will have to get all localized content items in id-ID to populate the page.

But I haven't able to do this because the localizationSet field is required in GraphQL query.

And since have to get all the localizationSet values from all content items, then for-each this list to get all content items in id-ID is too complicated, I'm looking for a better solution.

Please help to check and advise,
Many thanks.

@pbros
Copy link
Contributor

pbros commented May 12, 2020

Hi @minhdn2,

I'm using it like this. Don't know if this helps you or not. I basically get my main element by alias, and then get the localized version using the localizations with the culture filter.

query Page {{
    pages: page(where: {{alias: {{alias: ""{alias}""}} }}) {{
        localization {{
            localizations(culture: ""{culture}"") {{
                ... on Page {{
                    title: displayText
                    body: render
                }}
            }}
        }}
    }}
}}

@sebastienros sebastienros added this to the 1.0.x milestone May 21, 2020
@MikeKry
Copy link
Contributor

MikeKry commented Oct 29, 2020

I also need this.. it would be enough to make localizationSet optional.

UC:
Query all {language} pages for list views without having to extract localizationSet ids from default culture.

@sebastienros
Copy link
Member

We have an index for the Localization part, this should be added to graphql to query. Should be two lines of code to add it. (LocalizedContentItemIndex)

@MikeKry
Copy link
Contributor

MikeKry commented Oct 31, 2020

@sebastienros
I have tried to do it myself, but I can't find where are GraphQL content type filters are defined in Orchard.. (I am pretty new to this project). If you can point me in right direction, I can try to implement and create a PR.

Edit:
Maybe it would be enough to set nullable to true at OrchardCore.ContentLocalization.GraphQL.LocalizationInputObjectType?
Field(x => x.LocalizationSet, true).Description(S["the localization set of the content item to filter"]);

Edit 2:
Yes, it works.. Not sure how to correctly submit change to this project though.. I can not create branch in repo.

Edit 3:
after some study, I have managed to create PR. please check and if it is ok, merge?
#7470

MikeKry pushed a commit to MikeKry/OrchardCore that referenced this issue Nov 1, 2020
@agriffard agriffard changed the title Help create GrahpQL query to filter content items by culture Help create GraphQL query to filter content items by culture Nov 4, 2020
@carlwoodhouse carlwoodhouse linked a pull request Nov 4, 2020 that will close this issue
MikeKry pushed a commit to MikeKry/OrchardCore that referenced this issue Nov 4, 2020
@agriffard
Copy link
Member

Fixed by #7470

@sebastienros sebastienros modified the milestones: 1.0.x, 1.0 Sep 9, 2021
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

7 participants