GraphQL - How to correctly pass a GUID to a query

Hello, as the title claims, I wold pass an element id to a GraphQL query.
The query involved, due to my implementation, expects the id as a string, to retrieve a specific element as result. When the query beings called, I receive this exception:

‘GraphQL error: Variable “$idArticle” of type “String!” used in position expecting type “Guid!”.’

in which $idArticle is the id I want to pass as query variable to fetch data:

query Article($idArticle: String!) {
      findArticleContent(id: $idArticle) {
        ...ArticlesFragmentsArticleId // <--- as its name suggests
        data {
          ...ArticlesFragmentsArticle // <--- this fragment returns my data schema
        }
      }
    }

${Articles.fragments.articleId}
${Articles.fragments.article}

How can I solve this one? I mean, which is the correct data format I should pass from the front-end client in order to run the query successfully? I never worked with guid before, so any tip or advice will be appreciated.

Thanks in advance for your help.

I would try to define the variable as Guid! and then use a string value.

Due to the fact that actually GraphQL supports ID data type parsed as String, even if it represents a base64 encoding, at last I opted to refactor it by querying data through a slug field.
I’m not so enthusiast about this, but let’s say that for now it could fit with no more problems.

Thanks anyway for your suggestions.

1 Like