1

I am using version 12.16.0 and I am facing an issue with the Id field being returned as base64 encoded string instead of Guid. Is there a way to configure a custom serializer or scalar type for Guid values in the schema?

The ID is stored as a Guid in my database, but when queried through GraphQL, it is returned as a base64 encoded string. I want to customize the serialization so that the ID is returned as a Guid instead. I am using the HotChocolate library version 12.16.0, but I have not been able to find a solution that works. I was expecting to find a way to customize the serialization of the ID field so that it is returned as a Guid, but I have not been able to find a solution that works.

Stefan Wuebbe
  • 2,109
  • 5
  • 17
  • 28

1 Answers1

0

How does your base64 encoded string look like? I use this example for testing, adding a column of Guid attribute values to the model and the corresponding database.

When I query the value of Guid from database using GraphQL, it is a string (The original Guid value removes "-"):

enter image description here

enter image description here

For this, you can specify UuidType to format. To change the default format we have to register the UuidType with the specifier on the schema:

services
   .AddGraphQLServer()
   .AddType(new UuidType('D'));

Test Result:

enter image description here

For the serialization format supported by Uuid scalar, you can refer to this link.

Hope this can help you.

Chen
  • 4,499
  • 1
  • 2
  • 9
  • in the example (https://github.com/ajayhit/Asp.netCoreGraphQL) from you relay ploicy is not allowed. I have this problem at the [GraphQL Workshop] (https://github.com/ChilliCream/graphql-workshop) from ChilliCream; and I have opened a [issue] (https://github.com/ChilliCream/graphql-workshop/issues/105) – Mohammad Al Mahamid Jan 16 '23 at 09:50
  • useful links: - https://chillicream.com/docs/hotchocolate/v10/schema/relay - https://chillicream.com/docs/hotchocolate/defining-a-schema/relay -https://chillicream.com/docs/hotchocolate/defining-a-schema/relay#global-identifiers – Mohammad Al Mahamid Jan 16 '23 at 13:04