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

GraphQL 4 query response weirdness with fresh fluent install #768

Open
oetiker opened this issue Jul 8, 2022 · 6 comments
Open

GraphQL 4 query response weirdness with fresh fluent install #768

oetiker opened this issue Jul 8, 2022 · 6 comments
Labels
type/question User help questions

Comments

@oetiker
Copy link
Contributor

oetiker commented Jul 8, 2022

We have added fluent to an existing site, without migrating pages to a default locale yet ... the presence of fluent does not seem to negatively affect site, except for one thing. The query below returns a huge amount of pages, seemingly ignoring the filter condition.
If I pick a parentID other than 0, all is well again.

Once we migrated the existing pages to the default language the behavior reverted to returning only pages matching the filter.

I have not tried this on a fresh install, but we are using all the latest ss4, graphql4 and fluent 5 bits. Maybe this problem does ring a bell with someone who knows about fluent GraphQL interaction.

query { 
    readPages(
        sort: { sort: ASC }
        filter: { parentID: { eq: 0 }, showInMenus: { eq: true } }
    ) {
        nodes {
            title
            link
            showInMenus
            className
            parentID
        }
    }
}
@tractorcow
Copy link
Collaborator

At the moment the fluent middleware doesn't know how to pull locale from graphql queries.

I typically bake all of my queries with a $locale parameter, and manually set the locale in my resolver.

    public function initialiseLocale($locale): Locale
    {
        // Get locale by region / langauge
        $localeObject = Locale::getCached()->find('Locale', $locale);
        if (!$localeObject) {
            throw new HTTPResponse_Exception("No locale {$locale} exists");
        }

        // Initialise state
        FluentState::singleton()
            ->setIsFrontend(true)
            ->setIsDomainMode(false)
            ->setLocale($localeObject->Locale);

        i18n::set_locale($localeObject->Locale);
        return $localeObject;
    }

@tractorcow
Copy link
Collaborator

By the way, if you wanted to do this globally for all graphql queries, you could override DetectLocaleMiddleware::getLocale, and manually extract the "locale" graphql parameter there. You'd just need to make sure you were capturing graphql requests explicitly.

@tractorcow tractorcow added the type/question User help questions label Jul 11, 2022
@oetiker
Copy link
Contributor Author

oetiker commented Jul 11, 2022

Hi @tractorcow We have not even looked at the problem of how to handle locales in the graphql queries yet, so thanks for the tipps, this will come in very handy.

What we observed though, is that the response to the query cited above is totally not as expected as soon as fluent was installed. As long as the existing pages had not been migrated to the default locale, the query would return all sorts of pages which DO NOT match the filter ... is this an expected behavior ?

@tractorcow
Copy link
Collaborator

It's not really expected; Perhaps there's something that still needs to be flushed / migrated?

Have you checked that you've marked a locale as default?

If you've only just installed fluent, you would need to setup a list of locales with at least one value set as the global default.

Do you have a domain setup, but did not specify a default locale for that domain?

@tractorcow tractorcow reopened this Jul 11, 2022
@tractorcow
Copy link
Collaborator

I've leave the ticket open since there still seems to be some odd behaviour about the default locale being assigned.

@oetiker
Copy link
Contributor Author

oetiker commented Jul 12, 2022

We had not setup anything ... just added the fluent package to an existing site ... it did not have any ill effects ... except for the strange results from the query above ... we also tried what happens when we added a default locale ... the strange results kept coming ...

once we ran the InitialPageLocalisationTask all was well ... so for us the problem is solved. It`s just that it took us quite some time to suspect fluent as the culprit, so I thought I report it, because maybe it is a symptom of another problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/question User help questions
Projects
None yet
Development

No branches or pull requests

2 participants