Skip to content

[5.x]: label in new graphql LinkData #16637

@soerenmeier

Description

@soerenmeier

What happened?

Description

I want to start by saying, thanks for adding the new "Full data" option #16237 it's awesome.

When trying it out I found a discrepancy in the behaviour of the label field in graphql and twig.
It seems that in graphql the label is only the value of the optional label field.
But in twig if the label field is empty the label property will contain the element title or a nice representation of the url.

Steps to reproduce

  1. Create a link field and add the option for the label and url suffix (not sure if it's needed)
  2. create a graphql query to read the label field.
  3. create a twig file to read the label.
  4. create two link fields one where the label is set and one where only the entry is set.

Expected behavior

Label behaviour in twig and graphql is the same, meaning if the label field is empty it get's filled by another string derived from the value.

Actual behavior

GraphQl field value is only the content of the label field.

Workaround

In js

link.label ?? link.elementTitle ?? (link.value ? new URL(link.value).hostname : '')

Craft CMS version

5.6.5.1

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions