Ejemplo n.º 1
0
        public static string?ObsoleteReason(this Directive obsoleteDirective, GraphQLGenerationOptions options, Document document)
        {
            var reason = obsoleteDirective.Arguments.FirstOrDefault(a => a.Name == "reason")?.Value;

            if (reason != null)
            {
                return(options.Resolve(reason, new TypeName("String", new LocationRange()), document));
            }
            return(null);
        }
Ejemplo n.º 2
0
        public string GetParameterWithDefault()
        {
            var fieldName     = FieldName;
            var inputTypeName = TypeName;
            var nullable      = options.TypeResolver.IsNullable(arg.TypeNode, options, document);

            var getValue = nullable
                ? $"(parameters.HasParameter(\"{fieldName}\") ? parameters.GetParameter<{inputTypeName}>(\"{fieldName}\") : null)"
                : $"parameters.GetParameter<{inputTypeName}>(\"{fieldName}\")";
            var defaultValueExpression = arg.DefaultValue != null ? $" ?? {options.Resolve(arg.DefaultValue, arg.TypeNode, document)}" : "";

            return($"{fieldName}: {getValue}{defaultValueExpression}");
        }
Ejemplo n.º 3
0
 public virtual string Resolve(IValueNode value, ITypeNode typeNode, GraphQLGenerationOptions options, Document document)
 {
     return(value switch
     {
         ArrayValue array when typeNode is ListType list =>
         $"new {options.Resolve(list.ElementType, document)} [] {{ {string.Join(", ", array.Values.Select(v => Resolve(v, list.ElementType, options, document)))} }}",
         BooleanValue booleanValue =>
         booleanValue.TokenValue == true ? "true" : "false",
         EnumValue enumValue when typeNode is TypeName typeName => RenderEnumValue(enumValue, typeName, document, options),
         FloatValue floatValue =>
         floatValue.TokenValue,
         IntValue intValue =>
         intValue.TokenValue,
         NullValue _ => "null",
         ObjectValue objectValue when typeNode is TypeName typeName => RenderObjectInstantiation(objectValue, typeName, options, document),
         StringValue stringValue => $@"@""{stringValue.Text.Replace("\"", "\"\"")}""",
         TripleQuotedStringValue stringValue => $@"@""{stringValue.Text.Replace("\"", "\"\"")}""",
         _ => throw new InvalidOperationException($"Cannot render a C# representation for the default value of type {value.Kind.ToString("g")} for type {options.Resolve(typeNode, document, nullable: false)}"),
     });