Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,8 @@ private static bool TryGetJsonSchemaFormat(
{
"https://scalars.graphql.org/chillicream/date.html" => Formats.Date,
"https://scalars.graphql.org/chillicream/date-time.html" => Formats.DateTime,
"https://scalars.graphql.org/chillicream/duration.html" => Formats.Duration,
"https://scalars.graphql.org/chillicream/local-date.html" => Formats.Date,
"https://scalars.graphql.org/chillicream/time-span.html" => Formats.Duration,
"https://scalars.graphql.org/chillicream/uuid.html" => Formats.Uuid,
"https://scalars.graphql.org/chillicream/uri.html" => Formats.Uri,
"https://scalars.graphql.org/chillicream/url.html" => Formats.Uri,
Expand Down Expand Up @@ -304,14 +304,14 @@ private static bool TryGetJsonSchemaPattern(
=> @"^\d{4}-\d{2}-\d{2}$",
"https://scalars.graphql.org/chillicream/date-time.html"
=> @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:[Zz]|[+-]\d{2}:\d{2})$",
"https://scalars.graphql.org/chillicream/duration.html"
=> @"^-?P(?:\d+W|(?=\d|T(?:\d|$))(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?)$",
"https://scalars.graphql.org/chillicream/local-date.html"
=> @"^\d{4}-\d{2}-\d{2}$",
"https://scalars.graphql.org/chillicream/local-date-time.html"
=> @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$",
"https://scalars.graphql.org/chillicream/local-time.html"
=> @"^\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$",
"https://scalars.graphql.org/chillicream/time-span.html"
=> @"^-?P(?:\d+W|(?=\d|T(?:\d|$))(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?)$",
"https://scalars.graphql.org/chillicream/uuid.html"
=> @"^[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}$",
_ => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ private static OpenApiSchema CreateScalarSchema(IScalarTypeDefinition scalarType
{
"https://scalars.graphql.org/chillicream/date.html" => "date",
"https://scalars.graphql.org/chillicream/date-time.html" => "date-time",
"https://scalars.graphql.org/chillicream/duration.html" => "duration",
"https://scalars.graphql.org/chillicream/local-date.html" => "date",
"https://scalars.graphql.org/chillicream/time-span.html" => "duration",
"https://scalars.graphql.org/chillicream/uuid.html" => "uuid",
"https://scalars.graphql.org/chillicream/uri.html" => "uri",
"https://scalars.graphql.org/chillicream/url.html" => "uri",
Expand Down Expand Up @@ -561,14 +561,14 @@ private static OpenApiSchema CreateScalarSchema(IScalarTypeDefinition scalarType
=> @"^\d{4}-\d{2}-\d{2}$",
"https://scalars.graphql.org/chillicream/date-time.html"
=> @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?(?:[Zz]|[+-]\d{2}:\d{2})$",
"https://scalars.graphql.org/chillicream/duration.html"
=> @"^-?P(?:\d+W|(?=\d|T(?:\d|$))(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?)$",
"https://scalars.graphql.org/chillicream/local-date.html"
=> @"^\d{4}-\d{2}-\d{2}$",
"https://scalars.graphql.org/chillicream/local-date-time.html"
=> @"^\d{4}-\d{2}-\d{2}[Tt]\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$",
"https://scalars.graphql.org/chillicream/local-time.html"
=> @"^\d{2}:\d{2}:\d{2}(?:\.\d{1,9})?$",
"https://scalars.graphql.org/chillicream/time-span.html"
=> @"^-?P(?:\d+W|(?=\d|T(?:\d|$))(?:\d+Y)?(?:\d+M)?(?:\d+D)?(?:T(?:\d+H)?(?:\d+M)?(?:\d+(?:\.\d+)?S)?)?)$",
"https://scalars.graphql.org/chillicream/uuid.html"
=> @"^[\da-fA-F]{8}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{4}-[\da-fA-F]{12}$",
_ => null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ public sealed class TypeExtensionsTests
[InlineData(typeof(DateTimeType), "2011-08-30T13:22:53.1230000+03:30")]
// A DateTime with no fractional seconds.
[InlineData(typeof(DateTimeType), "2011-08-30T13:22:53+03:30")]
[InlineData(typeof(DurationType), "P18M")]
[InlineData(typeof(DurationType), "PT1H30M")]
[InlineData(typeof(DurationType), "P1Y2M3DT4H5M6S")]
[InlineData(typeof(DurationType), "PT4.567S")]
[InlineData(typeof(LocalDateTimeType), "2011-08-30T13:22:53")]
[InlineData(typeof(LocalTimeType), "13:22:53")]
[InlineData(typeof(TimeSpanType), "P18M")]
[InlineData(typeof(TimeSpanType), "PT1H30M")]
[InlineData(typeof(TimeSpanType), "P1Y2M3DT4H5M6S")]
[InlineData(typeof(TimeSpanType), "PT4.567S")]
public void ToJsonSchemaBuilder_ValidValues_MatchPattern(Type type, string value)
{
// arrange
Expand All @@ -53,11 +53,11 @@ public void ToJsonSchemaBuilder_ValidValues_MatchPattern(Type type, string value
[InlineData(typeof(DateTimeType), "2011-08-30T13:22:53.108+03:30:15")]
// A DateTime with 10 fractional digits.
[InlineData(typeof(DateTimeType), "2011-08-30T13:22:53.1234567890+03:30")]
[InlineData(typeof(DurationType), "bad")]
[InlineData(typeof(LocalDateTimeType), "2018/06/11T08:46:14 pm")]
[InlineData(typeof(LocalDateTimeType), "abc")]
[InlineData(typeof(LocalTimeType), "08:46:14 pm")]
[InlineData(typeof(LocalTimeType), "abc")]
[InlineData(typeof(TimeSpanType), "bad")]
public void ToJsonSchemaBuilder_InvalidValues_DoNotMatchPattern(Type type, string value)
{
// arrange
Expand All @@ -77,10 +77,10 @@ public void ToJsonSchemaBuilder_InvalidValues_DoNotMatchPattern(Type type, strin
public void ToJsonSchemaBuilder_TimeSpanTypeDotNetValidValues_MatchPattern(string value)
{
// arrange
var timeSpanType = new TimeSpanType(TimeSpanFormat.DotNet);
var durationType = new DurationType(DurationFormat.DotNet);

// act
var jsonSchema = timeSpanType.ToJsonSchemaBuilder().Build();
var jsonSchema = durationType.ToJsonSchemaBuilder().Build();
var regex = new Regex(jsonSchema.GetPatternValue()!);

// assert
Expand All @@ -93,10 +93,10 @@ public void ToJsonSchemaBuilder_TimeSpanTypeDotNetValidValues_MatchPattern(strin
public void ToJsonSchemaBuilder_TimeSpanTypeDotNetInvalidValues_DoNotMatchPattern(string value)
{
// arrange
var timeSpanType = new TimeSpanType(TimeSpanFormat.DotNet);
var durationType = new DurationType(DurationFormat.DotNet);

// act
var jsonSchema = timeSpanType.ToJsonSchemaBuilder().Build();
var jsonSchema = durationType.ToJsonSchemaBuilder().Build();
var regex = new Regex(jsonSchema.GetPatternValue()!);

// assert
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,7 @@ await storage.AddOrUpdateToolAsync(
{ "date", null },
{ "dateTime", null },
{ "decimal", null },
{ "duration", null },
{ "enum", null },
{ "float", null },
{ "id", null },
Expand All @@ -671,7 +672,6 @@ await storage.AddOrUpdateToolAsync(
{ "object", null },
{ "short", null },
{ "string", null },
{ "timeSpan", null },
{ "unknown", null },
{ "unsignedByte", null },
{ "unsignedInt", null },
Expand Down Expand Up @@ -712,6 +712,7 @@ await storage.AddOrUpdateToolAsync(
{ "date", "2000-01-01" },
{ "dateTime", "2000-01-01T12:00:00Z" },
{ "decimal", 79228162514264337593543950335m },
{ "duration", "PT5M" },
{ "enum", "VALUE1" },
{ "float", 1.5 },
{ "id", "test" },
Expand All @@ -725,7 +726,6 @@ await storage.AddOrUpdateToolAsync(
{ "object", new { field1A = new { field1B = new { field1C = "12:00:00" } } } },
{ "short", 1 },
{ "string", "test" },
{ "timeSpan", "PT5M" },
{ "unknown", "test" },
{ "unsignedByte", 1 },
{ "unsignedInt", 65536 },
Expand Down Expand Up @@ -769,7 +769,7 @@ await storage.AddOrUpdateToolAsync(
new OperationToolDefinition(
Utf8GraphQLParser.Parse(
await File.ReadAllTextAsync("__resources__/GetWithComplexVariables.graphql"))));
var server = await CreateTestServerAsync(storage, [new TimeSpanType(TimeSpanFormat.DotNet)]);
var server = await CreateTestServerAsync(storage, [new DurationType(DurationFormat.DotNet)]);
var mcpClient = await CreateMcpClientAsync(server.CreateClient());

// act
Expand Down Expand Up @@ -798,7 +798,7 @@ await storage.AddOrUpdateToolAsync(
{ "oneOf", new { field1 = 1 } },
{ "oneOfList", new object[] { new { field1 = 1 }, new { field2 = "test" } } },
{ "objectWithOneOfField", new { field = new { field1 = 1 } } },
{ "timeSpanDotNet", "00:05:00" }
{ "durationDotNet", "00:05:00" }
},
options: new RequestOptions { JsonSerializerOptions = JsonSerializerOptions.Default });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void CreateTool_WithDefaultedVariables_CreatesCorrectSchema()
public void CreateTool_WithComplexVariables_CreatesCorrectSchema()
{
// arrange
var schema = CreateSchema(s => s.AddType(new TimeSpanType(TimeSpanFormat.DotNet)));
var schema = CreateSchema(s => s.AddType(new DurationType(DurationFormat.DotNet)));
var document = Utf8GraphQLParser.Parse(
File.ReadAllText("__resources__/GetWithComplexVariables.graphql"));
var toolDefinition = new OperationToolDefinition(document);
Expand Down
24 changes: 12 additions & 12 deletions src/HotChocolate/Adapters/test/Adapters.Mcp.Tests/TestSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public ResultNullable GetWithNullableVariables(
[GraphQLType<DateType>] DateOnly? date,
DateTimeOffset? dateTime,
decimal? @decimal,
TimeSpan? duration,
TestEnum? @enum,
float? @float,
[GraphQLType<IdType>] string? id,
Expand All @@ -38,7 +39,6 @@ public ResultNullable GetWithNullableVariables(
Object1Nullable? @object,
short? @short,
string? @string,
TimeSpan? timeSpan,
[GraphQLType<UnknownType>] string? unknown,
byte? unsignedByte,
uint? unsignedInt,
Expand All @@ -56,6 +56,7 @@ public ResultNullable GetWithNullableVariables(
date,
dateTime,
@decimal,
duration,
@enum,
@float,
id,
Expand All @@ -68,7 +69,6 @@ public ResultNullable GetWithNullableVariables(
@object,
@short,
@string,
timeSpan,
unknown,
unsignedByte,
unsignedInt,
Expand All @@ -86,6 +86,7 @@ public ResultNonNullable GetWithNonNullableVariables(
[GraphQLType<NonNullType<DateType>>] DateOnly date,
DateTimeOffset dateTime,
decimal @decimal,
TimeSpan duration,
TestEnum @enum,
float @float,
[GraphQLType<NonNullType<IdType>>] string id,
Expand All @@ -98,7 +99,6 @@ public ResultNonNullable GetWithNonNullableVariables(
Object1NonNullable @object,
short @short,
string @string,
TimeSpan timeSpan,
[GraphQLType<NonNullType<UnknownType>>] string unknown,
byte unsignedByte,
uint unsignedInt,
Expand All @@ -116,6 +116,7 @@ public ResultNonNullable GetWithNonNullableVariables(
date,
dateTime,
@decimal,
duration,
@enum,
@float,
id,
Expand All @@ -128,7 +129,6 @@ public ResultNonNullable GetWithNonNullableVariables(
@object,
@short,
@string,
timeSpan,
unknown,
unsignedByte,
unsignedInt,
Expand All @@ -146,6 +146,7 @@ public ResultDefaulted GetWithDefaultedVariables(
[GraphQLType<NonNullType<DateType>>] DateOnly date,
DateTimeOffset dateTime,
decimal @decimal,
TimeSpan duration,
TestEnum @enum,
float @float,
[GraphQLType<NonNullType<IdType>>] string id,
Expand All @@ -158,7 +159,6 @@ public ResultDefaulted GetWithDefaultedVariables(
Object1Defaulted @object,
short @short,
string @string,
TimeSpan timeSpan,
[GraphQLType<NonNullType<UnknownType>>] string unknown,
byte unsignedByte,
uint unsignedInt,
Expand All @@ -176,6 +176,7 @@ public ResultDefaulted GetWithDefaultedVariables(
date,
dateTime,
@decimal,
duration,
@enum,
@float,
id,
Expand All @@ -188,7 +189,6 @@ public ResultDefaulted GetWithDefaultedVariables(
@object,
@short,
@string,
timeSpan,
unknown,
unsignedByte,
unsignedInt,
Expand All @@ -207,7 +207,7 @@ public ResultComplex GetWithComplexVariables(
OneOf oneOf,
OneOf[] oneOfList,
ObjectWithOneOfField objectWithOneOfField,
TimeSpan timeSpanDotNet)
TimeSpan durationDotNet)
=>
new(
list,
Expand All @@ -218,7 +218,7 @@ public ResultComplex GetWithComplexVariables(
oneOf,
oneOfList,
objectWithOneOfField,
timeSpanDotNet);
durationDotNet);

public int GetWithVariableMinMaxValues() => 1;

Expand Down Expand Up @@ -359,6 +359,7 @@ public sealed record ResultNullable(
[property: GraphQLType<DateType>] DateOnly? Date,
DateTimeOffset? DateTime,
decimal? Decimal,
TimeSpan? Duration,
TestEnum? Enum,
float? Float,
[property: GraphQLType<IdType>] string? Id,
Expand All @@ -371,7 +372,6 @@ public sealed record ResultNullable(
Object1Nullable? Object,
short? Short,
string? String,
TimeSpan? TimeSpan,
[property: GraphQLType<UnknownType>] string? Unknown,
byte? UnsignedByte,
uint? UnsignedInt,
Expand All @@ -389,6 +389,7 @@ public sealed record ResultNonNullable(
[property: GraphQLType<NonNullType<DateType>>] DateOnly Date,
DateTimeOffset DateTime,
decimal Decimal,
TimeSpan Duration,
TestEnum Enum,
float Float,
[property: GraphQLType<NonNullType<IdType>>] string Id,
Expand All @@ -401,7 +402,6 @@ public sealed record ResultNonNullable(
Object1NonNullable Object,
short Short,
string String,
TimeSpan TimeSpan,
[property: GraphQLType<NonNullType<UnknownType>>] string Unknown,
byte UnsignedByte,
uint UnsignedInt,
Expand All @@ -419,6 +419,7 @@ public sealed record ResultDefaulted(
[property: GraphQLType<NonNullType<DateType>>] DateOnly Date,
DateTimeOffset DateTime,
decimal Decimal,
TimeSpan Duration,
TestEnum Enum,
float Float,
[property: GraphQLType<NonNullType<IdType>>] string Id,
Expand All @@ -431,7 +432,6 @@ public sealed record ResultDefaulted(
Object1Defaulted Object,
short Short,
string String,
TimeSpan TimeSpan,
[property: GraphQLType<NonNullType<UnknownType>>] string Unknown,
byte UnsignedByte,
uint UnsignedInt,
Expand All @@ -450,7 +450,7 @@ public sealed record ResultComplex(
OneOf OneOf,
OneOf[] OneOfList,
ObjectWithOneOfField ObjectWithOneOfField,
TimeSpan TimeSpanDotNet);
TimeSpan DurationDotNet);

[UnionType(name: "PetUnion")]
public interface IPet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ query GetWithComplexVariables(
$oneOfList: [OneOfInput!]! = [{ field1: 1 }, { field2: "default" }]
"Object with OneOf field"
$objectWithOneOfField: ObjectWithOneOfFieldInput! = { field: { field1: 1 } }
"TimeSpan with DotNet format"
$timeSpanDotNet: TimeSpan! = "00:05:00"
"Duration with DotNet format"
$durationDotNet: Duration! = "00:05:00"
) {
withComplexVariables(
list: $list
Expand All @@ -28,7 +28,7 @@ query GetWithComplexVariables(
oneOf: $oneOf
oneOfList: $oneOfList
objectWithOneOfField: $objectWithOneOfField
timeSpanDotNet: $timeSpanDotNet
durationDotNet: $durationDotNet
) {
list {
field1A {
Expand Down Expand Up @@ -67,6 +67,6 @@ query GetWithComplexVariables(
field2
}
}
timeSpanDotNet
durationDotNet
}
}
Loading
Loading