Option to skip redirect on frontpage.

Created on 29 October 2024, about 2 months ago

Problem/Motivation

Currently a route request to the frontpage will return a redirect.

query {
  route(path: "/de") {
    __typename
    ... on RedirectUrl {
      path
    }
  }
}

Results in

{
  "data": {
    "route": {
      "__typename": "RedirectUrl",
      "path": "/de/whatever-alias-or-node-id-path-the-current-frontpage-has"
    }
  }
}

I think it would be desirable to provide an option to disable the alias redirect on the frontpage in order to have the routing work like the "normal html routing".

Proposed resolution

Introduce new optional argument skipFrontpageRedirect. New argument defaults to current behavior.

Example:

query {
  route(path: "/de", skipFrontpageRedirect: true) {
    __typename
    ... on RedirectUrl {
      path
    }
  }
}

Would lead to:

  "data": {
    "route": {
      "__typename": "EntityCanonicalUrl",
      "entity": {
        "label": "My Frontpage"
      }
    }
  }

Remaining tasks

  1. Create Code
  2. Decide if desirable
  3. Review
  4. Merge

User interface changes

None

API changes

The routing query has the new optional argument skipFrontpageRedirect which allows to skip the redirect to the alias / node on the frontpage.

Data model changes

None

Feature request
Status

Active

Version

1.0

Component

Code

Created by

🇨🇭Switzerland das-peter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @das-peter
  • 🇨🇭Switzerland das-peter

    First draft created.
    Reviews and overall feedback welcome.
    Tests are currently missing - don't have the setup ready yet - still setting to "Needs Review" to get first feedback.

  • Pipeline finished with Success
    about 2 months ago
    Total: 207s
    #324023
  • 🇨🇭Switzerland ayalon

    We also found this issue but decided to not fix it in GraphQL Core Schema.
    We rely fully on Drupal Core in terms of routing. The issue is an underlying bug in Drupal core.

    You can find the issue here:
    https://www.drupal.org/project/drupal/issues/1255092 🐛 url() should return / when asked for the URL of the frontpage Needs work

    If you use for example the patch in #41, the issue is solved.
    https://www.drupal.org/files/issues/2022-03-31/1255092-41.patch

    What do you think?

  • 🇨🇭Switzerland das-peter

    @ayalon Thanks for the feedback! Was totally not aware of that core issue.
    That obviously explains why if ($value !== $target_url ... is tripped.

    Would it be better to change the routing logic in our module?

    That's a good question. If core gest fixed that's a pretty essential change in how the frontend path behaves. I guess that's also why concerns about needing a CR for this change were raised.
    That said, if the behavior changes and we transparently forward the change we probably break 3rd-party APIs that have no affiliation with Drupal. Within Drupal itself we might can handle this using version constraints - but not with API dependencies.

    This again would make me wonder if instead of being a query property this could be a routing-setting in the GraphQL Core Schema config.
    My first local implementation was actually built as a setting and not a query argument.
    A setting would allow us to maintain / toggle the behavior transparently (without the need to change the queries) - which would avoid API breaks.

    Overall I wonder how soon we can expect an official change.
    I wouldn't bet on any time soon - the need is still here thought.
    That said and with above considerations I propose to expand the current patch and add the mentioned configuration.
    In case the core change comes, the setting is in place and an update hook or another condition can take care of maintaining API behavior for all pre-existing Graphql configs.

    Let me know what you think - happy to extend the patch.

Production build 0.71.5 2024