webonyx / graphql-php

PHP implementation of the GraphQL specification based on the reference implementation in JavaScript
https://webonyx.github.io/graphql-php
MIT License
4.64k stars 566 forks source link

Enum returns incorrect case #1626

Closed martio closed 1 week ago

martio commented 1 week ago

Description: When querying an enum in the Lighthouse GraphQL API, the enum values are returned with only the first letter capitalized, which does not align with the expected uppercase format. For instance, when querying the UserStatus enum, values are returned as "Active", "Inactive", etc., instead of "ACTIVE", "INACTIVE", etc.

Expected Behavior: The enum values should be returned in uppercase, matching the convention in GraphQL specifications and our application requirements.

Steps to Reproduce:

Define a native PHP enum with lowercase values, as follows:

enum StatusEnum: string {
    case INACTIVE = 'inactive';
    case ACTIVE = 'active';
    case BANNED = 'banned';
}

Configure the enum in Lighthouse:

enum UserStatus {
    INACTIVE @enum(value: "inactive")
    ACTIVE @enum(value: "active")
    BANNED @enum(value: "banned")
}

Execute a GraphQL query that retrieves this enum:

query {
  user(id: 1) {
    id
    status
  }
}

Observe the format of the returned enum value.

Current Response:

{
  "data": {
    "user": {
      "id": 1,
      "status": "Active"
    }
  }
}

Expected Response:

{
  "data": {
    "user": {
      "id": 1,
      "status": "ACTIVE"
    }
  }
}
spawnia commented 1 week ago

Duplicate of ~https://github.com/webonyx/graphql-php/issues/1626~ https://github.com/nuwave/lighthouse/issues/2629, it is more appropriate there.

martio commented 1 week ago

@spawnia I think you provided the wrong link to the duplicate... 😉

martio commented 1 week ago

@spawnia I have posted a solution in this issue: https://github.com/nuwave/lighthouse/issues/2629