GraphQLError Names must only contain [_a-zA-Z0-9]

discord user avatar
alessiogr
Payload Team
9 months ago
18

Getting this error:


GraphQLError: Names must only contain [_a-zA-Z0-9] but "posts-test_gear_bundles_backpopulated" does not

1. is this check new?


2. Which symbol is a problem: the "_" or the "-"?

  • default discord avatar
    jarrod69420
    8 months ago

    From the error, seems like

    -

    is the issue, but we should be sanitizing the names behind the scenes. Wondering if there is an issue with the sanitization going on

  • discord user avatar
    alessiogr
    Payload Team
    8 months ago

    the same error did not happen in previous versions, so something definitely changed. Might be worth checking into that, or mentioning it in a changelog if I didnt miss anything



    my solution was to rewrite it all with the _ symbol instead



    though honestly, might as well leave that as a standard



    Using "-" in fields is a pain anyways as you need to make those strings

  • default discord avatar
    jarrod69420
    8 months ago

    Right, but were you just using a slug, and it was auto-generating the graphql names?



    That is where I think there

    may

    be a bug

  • discord user avatar
    alessiogr
    Payload Team
    8 months ago

    that specific one was from

    https://github.com/TimHal/pcms-backpop


    I'm not sure if it ONLY happened for that, or for others as well



    didnt specifically test that, I just assumed it would break for everything

  • default discord avatar
    jarrod69420
    8 months ago

    oh yeah, I dont think specifying with a

    -

    should be allowed, not sure that graphql allows that

  • discord user avatar
    alessiogr
    Payload Team
    8 months ago

    It (I think) did work in the past though, that's for sure

  • default discord avatar
    jarrod69420
    8 months ago

    In the past we used labels to generate the graphQL type names, then we made a breaking change to use slugs and allowed users to specifically set graphQL typenames if they would prefer. BUT it should sanitize the slug correctly, into a graphQL safe type name (which it sounds like it is not doing in some cases, maybe)

  • discord user avatar
    alessiogr
    Payload Team
    8 months ago

    Ah right didn't think of that! Maybe that was what broke it then



    but yeah it definitely wasn't sanitizing anything there



    Which I THINK is good though - for new projects. not so much for existing projects



    It'd be a bit confusing if the graphQL name differs from the name you specified automatically

  • default discord avatar
    jarrod69420
    8 months ago

    For new projects, most of them should have just worked out of the box, since the slug and label are normally the same (one is hyphenated) but for collections that used custom labels, those would break hence the breaking change. That is why we opened up the ability to set GraphQL names so users could transition their old label generated type name to the new graphql specific property and not have to adjust their frontend

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.