jalendport / craft-preparse

Field type that parses twig when an element is saved.
MIT License
108 stars 23 forks source link

Column Suffixes #93

Open andrewfairlie opened 1 year ago

andrewfairlie commented 1 year ago

Craft introduced column suffixes for new fields, but it seems like the GraphQL queries on Preparse fields aren't querying against the field column. Unsure if this is a Craft bug or Preparse Field bug.

EG: Our test query

{
  events:entries(section:"events", calendarDatesEnd: "now", limit: 1){
    title
    ... on events_default_Entry {
      calendarDatesEnd
    }
  }
}

Returns the following SQL error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'content.field_calendarDatesEnd' in 'where clause'

The column is actually content.field_calendarDatesEnd_urqjyipm because of the suffix Craft adds.

andrewfairlie commented 1 year ago

Updating https://github.com/besteadfast/craft-preparse-field/blob/develop/src/fields/PreparseFieldType.php#L231C1-L231C1

to the following solves the suffix bug.

use craft\helpers\ElementHelper;
                $column = ElementHelper::fieldColumnFromField($this);
                $query->subQuery->andWhere(Db::parseDateParam("content.$column", $value));

However this then reveals a second bug on this part where you can't actually query based on time

Query

{
  events:entries(section:"events", calendarDatesStart: ">now"){
    title
    ... on events_default_Entry {
      calendarDatesEnd
    }
  }
}

Response

  "errors": [
    {
      "debugMessage": "SQLSTATE[HY000]: General error: 1525 Incorrect DATETIME value: 'now'",
      "message": "Internal server error",
      "extensions": {
        "category": "internal"
      },
andrewfairlie commented 1 year ago

@jalendport is this one you would be able to look into please?