private static string BuildMethodParameterDefinition(GraphQlType baseType, GraphQlArgument argument)
        {
            var isNotNull       = argument.Type.Kind == GraphQlTypeKindNonNull;
            var unwrappedType   = UnwrapNonNull(argument.Type);
            var argumentNetType = unwrappedType.Kind == GraphQlTypeKindEnum ? $"{unwrappedType.Name}?" : ScalarToNetType(baseType, argument.Name, unwrappedType);

            if (isNotNull)
            {
                argumentNetType = argumentNetType.TrimEnd('?');
            }

            if (unwrappedType.Kind == GraphQlTypeKindInputObject)
            {
                argumentNetType = $"{unwrappedType.Name}{GraphQlGeneratorConfiguration.ClassPostfix}";
            }

            var argumentDefinition = $"{argumentNetType} {argument.Name}";

            if (!isNotNull)
            {
                argumentDefinition = $"{argumentDefinition} = null";
            }

            return(argumentDefinition);
        }
Beispiel #2
0
        private static string BuildMethodParameterDefinition(GraphQlArgument argument)
        {
            var isNotNull       = argument.Type.Kind == GraphQlTypeKindNonNull;
            var argumentNetType = UnwrapNonNull(argument.Type).Kind == GraphQlTypeKindEnum ? $"{UnwrapNonNull(argument.Type).Name}?" : ScalarToNetType(UnwrapNonNull(argument.Type).Name);

            if (isNotNull)
            {
                argumentNetType = argumentNetType.TrimEnd('?');
            }

            var argumentDefinition = $"{argumentNetType} {argument.Name}";

            if (!isNotNull)
            {
                argumentDefinition = $"{argumentDefinition} = null";
            }

            return(argumentDefinition);
        }
        private static string BuildMethodParameterDefinition(GraphQlType baseType, GraphQlArgument argument)
        {
            var isArgumentNotNull = argument.Type.Kind == GraphQlTypeKindNonNull;
            var isTypeNotNull     = isArgumentNotNull;
            var unwrappedType     = argument.Type.UnwrapIfNonNull();
            var isCollection      = unwrappedType.Kind == GraphQlTypeKindList;

            if (isCollection)
            {
                isTypeNotNull = unwrappedType.OfType.Kind == GraphQlTypeKindNonNull;
                unwrappedType = unwrappedType.OfType.UnwrapIfNonNull();
            }

            var argumentNetType = unwrappedType.Kind == GraphQlTypeKindEnum ? $"{unwrappedType.Name}?" : ScalarToNetType(baseType, argument.Name, unwrappedType);

            if (isTypeNotNull)
            {
                argumentNetType = argumentNetType.TrimEnd('?');
            }

            if (unwrappedType.Kind == GraphQlTypeKindInputObject)
            {
                argumentNetType = $"{unwrappedType.Name}{GraphQlGeneratorConfiguration.ClassPostfix}";
            }

            if (isCollection)
            {
                argumentNetType = $"IEnumerable<{argumentNetType}>";
            }

            var argumentDefinition = $"{argumentNetType} {NamingHelper.ToValidVariableName(argument.Name)}";

            if (!isArgumentNotNull)
            {
                argumentDefinition = $"{argumentDefinition} = null";
            }

            return(argumentDefinition);
        }