Introduce smarter logic to create object strings for arguments

Created on 23 August 2023, about 1 year ago

Problem/Motivation

GraphQL can be quite picky about types. :-) The API we have to consume has arguments that need objects as values. Currently JSON encoding is used to turn an array into a string representation of an object that can be used with \GraphQL\RawObject to create an argument value. At least in our case that is not correct as it casts integer values in the object to strings, freaking the API out. :-p

Example config:

  query:
    search:
      listings:
        arguments:
          customer:
            id: 123456
          locale: nl_BE
          metadata:
            size: 400
          publication:
            changedDateFrom: '2023-08-12T00:00:00.000Z'

it modelled as

query {
  search {
    listings(
      customer: { id: "27299431" }
      locale: nl_BE
      metadata: { size: 400 }
      publication: { changedDateFrom: "2023-08-12T00:00:00.000Z" }
    ) {

where the API expects

query {
  search {
    listings(
      customer: { id: 27299431 }
      locale: nl_BE
      metadata: { size: 400 }
      publication: { changedDateFrom: "2023-08-12T00:00:00.000Z" }
    ) {

The customer ID, which is an int, is send as a string.

Steps to reproduce

TBD

Proposed resolution

Introduce a helper function for creating the object string, wrapping some smart logic that is more respectful to types.

Remaining tasks

- Design smarter logic for creating the object string
- Create MR
- Review MR
- Merge MR

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Feature request
Status

Closed: works as designed

Version

2.0

Component

Code

Created by

🇳🇱Netherlands ricovandevin

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

Comments & Activities

  • Issue created by @ricovandevin
  • Status changed to Closed: works as designed about 1 year ago
  • 🇳🇱Netherlands ricovandevin

    This actually seems to work properly. I was adding the customer ID in PHP (in a plugin deriver). I first thought that explicit typecasting in the code did not work. But apparently I forgot to rebuild the caches after adding typecasting of the customer ID to an integer.

    Closing this issue as "works as designed" for now.

Production build 0.71.5 2024