Пример #1
0
        public ScalarFieldTypeDescription GetCustomScalarFieldType(GraphQlGeneratorConfiguration configuration,
                                                                   GraphQlType baseType,
                                                                   GraphQlTypeBase valueType,
                                                                   string valueName)
        {
            valueType = valueType is GraphQlFieldType fieldType?fieldType.UnwrapIfNonNull() : valueType;

            // DateTime and Byte
            switch (valueType.Name)
            {
            case "Uuid": return(new ScalarFieldTypeDescription {
                    NetTypeName = "Guid?", FormatMask = "N"
                });

            case "Uuid!": return(new ScalarFieldTypeDescription {
                    NetTypeName = "Guid", FormatMask = "N"
                });

            case "Long": return(new ScalarFieldTypeDescription {
                    NetTypeName = "long?", FormatMask = null
                });

            case "DateTime": return(new ScalarFieldTypeDescription {
                    NetTypeName = "DateTime?", FormatMask = null
                });

            case "DateTime!": return(new ScalarFieldTypeDescription {
                    NetTypeName = "DateTime", FormatMask = null
                });
            }

            // fallback - not needed if all fields and arguments are resolved or the expected type is of "object" type
            return(DefaultScalarFieldTypeMappingProvider.Instance.GetCustomScalarFieldType(configuration, baseType, valueType, valueName));
        }
        public static string DefaultScalarFieldTypeMapping(GraphQlType baseType, string valueName)
        {
            var propertyName = NamingHelper.ToPascalCase(valueName);

            if (propertyName == "From" || propertyName == "ValidFrom" || propertyName == "CreatedAt" ||
                propertyName == "To" || propertyName == "ValidTo" || propertyName == "ModifiedAt" || propertyName.EndsWith("Timestamp"))
            {
                return("DateTimeOffset?");
            }

            return("string");
        }
            public ScalarFieldTypeDescription GetCustomScalarFieldType(GraphQlGeneratorConfiguration configuration, GraphQlType baseType, GraphQlTypeBase valueType, string valueName)
            {
                var isNotNull     = valueType.Kind == GraphQlTypeKind.NonNull;
                var unwrappedType = valueType is GraphQlFieldType fieldType?fieldType.UnwrapIfNonNull() : valueType;

                var nullablePostfix = isNotNull ? null : "?";

                if (unwrappedType.Name == "ID")
                {
                    return new ScalarFieldTypeDescription {
                               NetTypeName = "Guid" + nullablePostfix, FormatMask = "N"
                    }
                }
                ;

                if (valueName == "before" || valueName == "after" || unwrappedType.Name == "DateTimeOffset")
                {
                    return new ScalarFieldTypeDescription {
                               NetTypeName = "DateTimeOffset" + nullablePostfix, FormatMask = "yyyy-MM-dd\"T\"HH:mm"
                    }
                }
                ;

                return(DefaultScalarFieldTypeMappingProvider.Instance.GetCustomScalarFieldType(configuration, baseType, valueType, valueName));
            }
        }
            public ScalarFieldTypeDescription GetCustomScalarFieldType(GraphQlGeneratorConfiguration configuration, GraphQlType baseType, GraphQlTypeBase valueType, string valueName) =>
            valueType.Name == "Boolean"
                    ? new ScalarFieldTypeDescription
            {
                NetTypeName = "bool"
            }

                    : DefaultScalarFieldTypeMappingProvider.Instance.GetCustomScalarFieldType(configuration, baseType, valueType, valueName);
Пример #5
0
 public GraphQlField(string name, GraphQlType type, GraphQlResolution resolution)
 {
     this.name = name;
     this.type = type;
     this.resolution = resolution;
 }
Пример #6
0
 public void GivenIHaveAStringType()
 {
     currentType = new GraphQlString();
 }
Пример #7
0
 public void GivenIHaveAnObjectTypeThatContainsThatField()
 {
     currentType = new GraphQlObject(currentFields.ToArray());
     currentFields = new List<GraphQlField>();
 }
Пример #8
0
        public ScalarFieldTypeDescription GetCustomScalarFieldType(GraphQlGeneratorConfiguration configuration, GraphQlType baseType, GraphQlTypeBase valueType, string valueName)
        {
            valueName = NamingHelper.ToPascalCase(valueName);

            if (valueName == "From" || valueName == "ValidFrom" || valueName == "To" || valueName == "ValidTo" ||
                valueName == "CreatedAt" || valueName == "UpdatedAt" || valueName == "ModifiedAt" || valueName == "DeletedAt" ||
                valueName.EndsWith("Timestamp"))
            {
                return new ScalarFieldTypeDescription {
                           NetTypeName = "DateTimeOffset?"
                }
            }
            ;

            return(GetFallbackFieldType(configuration, valueType));
        }