GraphQL sometimes replacing hyphens and commas with underscores

default discord avatar
sesons
7 months ago
14

Hello fellas, would anyone know why the value of something in gql has hyphens and commas replaced with underscores? This does not occur when accessing data with REST

  • discord user avatar
    jmikrut
    Payload Team
    7 months ago

    This is because GraphQL doesn't allow dashes



    nothing Payload can do there unfortunately. To keep parity, I would avoid using dashes in field names



    use camelCase instead



    or undrescores, either way

  • default discord avatar
    sesons
    7 months ago

    so just to clarify, is that just for strings that are prefixed with a hyphen? i.e. i just can't start a value with a -

  • discord user avatar
    jmikrut
    Payload Team
    7 months ago

    any hyphen at all, anywhere



    doesn't need to be prefixed



    my-field

    will be turned into

    my_field
  • default discord avatar
    sesons
    7 months ago

    sorry to clarify this is for the value of a field, not a field name in itself

  • discord user avatar
    jmikrut
    Payload Team
    7 months ago

    like a select field for example?



    yep, same thing applies there as well. select values / radio values are

    enum

    s in graphql



    and enums can't have dashes either

  • default discord avatar
    sesons
    7 months ago

    ah ok makes sense



    thank you

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.