graphql-platform: Uuid values with hyphens no longer supported
Bug description
I have a project where Guids are used as identifiers. The input model looks like this:
public sealed class ProjectQueryInput
{
public Guid ProjectId { get; set; }
}
This gets translated as a Uuid! type which is fine, however, when sending an id with a GraphQL client (Insomnia in my case) as “a3a4e988-a84f-45f6-993b-ac7401222975”, we get back this error:
{
"message": "The specified value type of field `projectId` does not match the field type.",
"locations": [
{
"line": 21,
"column": 18
}
],
"path": [
"project",
"project"
],
"extensions": {
"fieldName": "projectId",
"fieldType": "Uuid!",
"locationType": "Uuid!",
"specifiedBy": "http://spec.graphql.org/June2018/#sec-Values-of-Correct-Type"
}
}
Only after removing the hyphens, the query works.
Expected behavior Guid formatted with hyphens should also be accepted as Uuid.
Desktop
- OS: Windows 10
- HotChocolate Version: 11.1.0-preview.2
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 15 (8 by maintainers)
Yes we have created a solution for the following case: Usually we get Uuids in format N (without hyphens) from the clients, but in some rare cases we get Uuids in format D (classic c# Guid with hyphens). To handle both I have registered the following class…
It first tries to parse the Uuids in the configured format and if the Uuid could not be parsed it tries the format D as alternate format. (You could hand over the alternate format also in the constructor if you want)
If you add it to the IRequestExecutorBuilder, then it overwrites the normal UuidType:
I think, anything that
Guid.Parsecan parse should be allowed.@PascalSenn Thanks
@nscheibe Looks like Guid properties in our C# class models are working correctly without any changes. We were using UuidType in a few ObjectTypeExtensions and after replacing those with GuidType, it’s working correctly now. Thank you.
Well, version 10 supported both.
For me, it’s a temporary problem as I had a lot of queries setup in my Insomnia client for testing purposes. The normal front-end doesn’t have this problem as all Guids it gets back from the HotChocolate server are formatted as
N(without hyphens).However, this can be a breaking change for others that use hard-coded Guids in their front-end application or fetch Guids from another place (like REST API, SignalR, …) formatted with hyphens.