Skip to content

[5.9] Undefined array key "type" in GraphQL resolver #64

@mtwalsh

Description

@mtwalsh

Environment

  • Craft CMS: 5.9.8
  • PHP: 8.2
  • Plugin: verbb/tablemaker 5.0.6

Description

When querying a Table Maker field via GraphQL that includes the rows sub-field, the server returns an internal error:

Undefined array key "type"

Column headings render correctly, but row data fails to resolve.

Steps to reproduce

  1. Install Craft CMS 5.x with verbb/tablemaker 5.0.6
  2. Create a Table Maker field with standard text columns (no Date or Time column types)
  3. Add data to the table in the control panel
  4. Query the field via GraphQL:
... on table_Entry {
  typeHandle
  table {
    columns {
      align
      heading
      width
    }
    rows
  }
  caption
}
  1. The query returns an internal server error instead of row data

Root cause

In vendor/verbb/tablemaker/src/fields/TableMakerField.php at line 277, the rows resolver iterates over columns and accesses $column['type'] without checking if the key exists:

// Line 275-283
foreach ($source['rows'] as $rowKey => $row) {
    foreach ($source['columns'] as $columnKey => $column) {
        if ($column['type'] === 'date' || $column['type'] === 'time') {
            $value = $row[$columnKey] ?? null;
            $source['rows'][$rowKey][$columnKey] = DateTimeHelper::toIso8601($value);
        }
    }
}

Columns that are plain text (or were created before the type property was introduced) do not have a type key in their data. On PHP 8.0+, accessing an undefined array key triggers a warning/error, which causes the GraphQL query to fail.

Craft CMS version

5.9.8

Plugin version

5.0.6

Multi-site?

No

Additional context

Suggested fix

Add an isset() guard before accessing $column['type']:

foreach ($source['rows'] as $rowKey => $row) {
    foreach ($source['columns'] as $columnKey => $column) {
        if (isset($column['type']) && ($column['type'] === 'date' || $column['type'] === 'time')) {
            $value = $row[$columnKey] ?? null;
            $source['rows'][$rowKey][$columnKey] = DateTimeHelper::toIso8601($value);
        }
    }
}

I've tested manually patching the vendor folder file with the fix above and that appears to resolve the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions