Skip to content

Composing data producer example is broken #1121

Open
@Kingdutch

Description

@Kingdutch

The code snippet that shows how $builder->compose can be used to load the currentUser is broken. The current_user data producer produces an AccountInterface instance, but the entity_load id field requires a string or an int.

The current incorrect snippet is the following part.

$builder->compose(
  $builder->produce('current_user'),
  $builder->produce('entity_load')
    ->map('type', $builder->fromValue('user'))
    ->map('id', $builder->fromParent())
);

For a query

query {
  currentUser { uuid }
}

It causes the following output

{
  "data": {
    "currentUser": null
  },
  "extensions": [
    {
      "message": "Object of class Drupal\\Core\\Session\\UserSession could not be converted to string",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "currentUser"
      ]
    }
  ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions