Machine name with numbers

Created on 15 July 2023, about 1 year ago
Updated 25 January 2024, 8 months ago

Problem/Motivation

When we have a particular field whose machine name contains a number, the resolver throws out a different machine name thus resulting in an unknown field exception.
For example, if we create a field Test 1 title, this will result in the following machine name, field_test_1_title. And in graphql explorer, we can see it as Test1Title. The problem is when we run a graphql query, that field is then converted via the EntitySchemaHelper::toSnakeCase($fieldName) to field_test1_title. This field does not exist and generated an error

Steps to reproduce

- Create an example content type
- Create a field with machine name field_test_1_title
- Run a graphql query with that field

Proposed resolution

We should probably change the way we map machine field names and their field resolvers

🐛 Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

🇲🇺Mauritius whiz11

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

Comments & Activities

  • Issue created by @whiz11
  • 🇲🇺Mauritius whiz11

    Here's a quick fix but this is based on the assumption that integers will always be spaced out in the fields' machine names.

  • 🇨🇭Switzerland dulnan

    This is indeed a problem. It will also result in problems when there is both a field "field_a_1" and "field_a1" on the same entity.

    But as a fix for the resolver I will pass along the actual field name inside the GraphQL field description and extract it in the resolver. That way it only has to do the conversion from camel to snake when the original field name could not be extracted from the description.
    As a nice side effect it should also help making it easier finding fields in the schema using the Drupal machine name.

    • dulnan committed 21126155 on 1.0.x
      Issue #3374810: Improve snake/camel case conversion of field names
      
      
  • Status changed to Fixed 8 months ago
Production build 0.71.5 2024