Support for NonNull GraphQL types RegexScalarFieldTypeMappingProvider
Proposal to add nullability support to RegexScalarFieldTypeMappingProvider.
Let's see an example:
{
"patternBaseType": ".+",
"patternValueType": "Long!",
"patternValueName": ".+",
"netTypeName": "long"
},
{
"patternBaseType": ".+",
"patternValueType": "Long",
"patternValueName": ".+",
"netTypeName": "long?"
},
Currently, when processing a rule, a GraphQL NonNull type is converted to Nullable type(Long! -> Long),
valueType = (valueType as GraphQlFieldType)?.UnwrapIfNonNull() ?? valueType;
so the first rule is always skipped, and the second is executed, generating a .NET type long? instead of long.
This PR will allow more flexible control over type generation and maintain backward compatibility.
This solution doesn't fully fit as there are options and/or use cases affecting nullability. I'll try to revisit this issue in more holistic approach.
Okay, that would be great. Any ideas, how I can separately generate nullable/not nullable structs in current stable version?
Which way do you use to generate the client. And nullability-wise, do we talk only about the data classes or other (input object class and query builders too)? If you generate using code you can pretty much do whatever you want by implementing your version IScalarFieldTypeMappingProvider. You should be able to access everything to resolve nullability of a member.
I use dotnet tool graphql-client-generator. I can fork and maintain version with custom MappingProvider, but I believe it's better to improve original tool.
I expect notnull support only in data classes.
@Husqvik The issue with IScalarFieldTypeMappingProvider we're currently facing is that while we're able to take NonNull into account (and strip the .NET type of a trailing '?'), there's no way to determine when the mapping is for a query parameter and when it's for a data class. What then happens is, whenever a schema says that a scalar object field is non-nullable, we would still like to have it nullable on the data class (because we might not retrieve it after all). Setting DataClassMemberNullability.AlwaysNullable doesn't help because GetCustomScalarFieldType won't get this information.
@danielcweber reworked the custom scalar type customization support. The whole thing is still WIP but you can glimpse the changes at https://github.com/Husqvik/GraphQlClientGenerator/commit/eedfdda168d1a545507e2c17bcc7dfd04ec14980
@VusalDev the latest dev version should resolve the nullability correctly. The netTypeName should be always set without ?. Also if the type is reference type it must be indicated by setting a new field in the JSON file: "isReferenceType": true.