Skip to content

Commit 4c2326d

Browse files
committed
Merge branch 'main' into gai/fix-analyzer-errors
2 parents d8d0d1d + a437900 commit 4c2326d

File tree

59 files changed

+3179
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3179
-392
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Definitions/CacheControlMutableDirectiveDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace HotChocolate.Fusion.Definitions;
55

6-
public sealed class CacheControlMutableDirectiveDefinition : MutableDirectiveDefinition
6+
internal sealed class CacheControlMutableDirectiveDefinition : MutableDirectiveDefinition
77
{
88
public CacheControlMutableDirectiveDefinition(
99
MutableScalarTypeDefinition intType,

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Definitions/CacheControlScopeMutableEnumTypeDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace HotChocolate.Fusion.Definitions;
44

5-
public sealed class CacheControlScopeMutableEnumTypeDefinition : MutableEnumTypeDefinition
5+
internal sealed class CacheControlScopeMutableEnumTypeDefinition : MutableEnumTypeDefinition
66
{
77
public CacheControlScopeMutableEnumTypeDefinition()
88
: base(WellKnownTypeNames.CacheControlScope)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using HotChocolate.Types;
2+
using HotChocolate.Types.Mutable;
3+
using static HotChocolate.Fusion.WellKnownArgumentNames;
4+
using static HotChocolate.Fusion.WellKnownDirectiveNames;
5+
6+
namespace HotChocolate.Fusion.Definitions;
7+
8+
internal sealed class McpToolAnnotationsMutableDirectiveDefinition : MutableDirectiveDefinition
9+
{
10+
public McpToolAnnotationsMutableDirectiveDefinition(MutableScalarTypeDefinition booleanType)
11+
: base(McpToolAnnotations)
12+
{
13+
Arguments.Add(new MutableInputFieldDefinition(DestructiveHint, booleanType));
14+
Arguments.Add(new MutableInputFieldDefinition(IdempotentHint, booleanType));
15+
Arguments.Add(new MutableInputFieldDefinition(OpenWorldHint, booleanType));
16+
Locations = DirectiveLocation.FieldDefinition;
17+
}
18+
19+
public static McpToolAnnotationsMutableDirectiveDefinition Create(ISchemaDefinition schema)
20+
{
21+
if (!schema.Types.TryGetType<MutableScalarTypeDefinition>(SpecScalarNames.Boolean.Name, out var booleanType))
22+
{
23+
booleanType = BuiltIns.Boolean.Create();
24+
}
25+
26+
return new McpToolAnnotationsMutableDirectiveDefinition(booleanType);
27+
}
28+
}

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Definitions/ScalarSerializationTypeMutableEnumTypeDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace HotChocolate.Fusion.Definitions;
44

5-
public sealed class ScalarSerializationTypeMutableEnumTypeDefinition : MutableEnumTypeDefinition
5+
internal sealed class ScalarSerializationTypeMutableEnumTypeDefinition : MutableEnumTypeDefinition
66
{
77
public ScalarSerializationTypeMutableEnumTypeDefinition()
88
: base(WellKnownTypeNames.ScalarSerializationType)

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Definitions/SerializeAsMutableDirectiveDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace HotChocolate.Fusion.Definitions;
55

6-
public sealed class SerializeAsMutableDirectiveDefinition : MutableDirectiveDefinition
6+
internal sealed class SerializeAsMutableDirectiveDefinition : MutableDirectiveDefinition
77
{
88
public SerializeAsMutableDirectiveDefinition(
99
ScalarSerializationTypeMutableEnumTypeDefinition scalarSerializationTypeType,

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Definitions/TagMutableDirectiveDefinition.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace HotChocolate.Fusion.Definitions;
55

6-
public sealed class TagMutableDirectiveDefinition : MutableDirectiveDefinition
6+
internal sealed class TagMutableDirectiveDefinition : MutableDirectiveDefinition
77
{
88
public TagMutableDirectiveDefinition(MutableScalarTypeDefinition stringType)
99
: base(DirectiveNames.Tag.Name)
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
using System.Collections.Immutable;
2+
using HotChocolate.Fusion.Definitions;
3+
using HotChocolate.Fusion.Directives;
4+
using HotChocolate.Fusion.Extensions;
5+
using HotChocolate.Fusion.Options;
6+
using HotChocolate.Types;
7+
using HotChocolate.Types.Mutable;
8+
using ArgumentNames = HotChocolate.Fusion.WellKnownArgumentNames;
9+
using DirectiveNames = HotChocolate.Fusion.WellKnownDirectiveNames;
10+
11+
namespace HotChocolate.Fusion.DirectiveMergers;
12+
13+
internal class McpToolAnnotationsDirectiveMerger(DirectiveMergeBehavior mergeBehavior)
14+
: DirectiveMergerBase(mergeBehavior)
15+
{
16+
public override string DirectiveName => DirectiveNames.McpToolAnnotations;
17+
18+
public override MutableDirectiveDefinition GetCanonicalDirectiveDefinition(ISchemaDefinition schema)
19+
{
20+
return McpToolAnnotationsMutableDirectiveDefinition.Create(schema);
21+
}
22+
23+
public override void MergeDirectives(
24+
IDirectivesProvider mergedMember,
25+
ImmutableArray<IDirectivesProvider> memberDefinitions,
26+
MutableSchemaDefinition mergedSchema)
27+
{
28+
if (MergeBehavior is DirectiveMergeBehavior.Ignore)
29+
{
30+
return;
31+
}
32+
33+
if (!mergedSchema.DirectiveDefinitions.TryGetDirective(DirectiveName, out var directiveDefinition))
34+
{
35+
// Merged definition not found.
36+
return;
37+
}
38+
39+
var mcpToolAnnotationsDirectives =
40+
memberDefinitions
41+
.SelectMany(d => d.Directives.Where(dir => dir.Name == DirectiveNames.McpToolAnnotations))
42+
.Select(McpToolAnnotationsDirective.From)
43+
.ToArray();
44+
45+
if (mcpToolAnnotationsDirectives.Length == 0)
46+
{
47+
return;
48+
}
49+
50+
var isMutationField = ((IFieldDefinition)memberDefinitions[0]).DeclaringMember is IObjectTypeDefinition
51+
{
52+
Name: WellKnownTypeNames.Mutation
53+
};
54+
55+
var argumentAssignments = new List<ArgumentAssignment>();
56+
57+
if (!mcpToolAnnotationsDirectives.All(d => d.DestructiveHint is null))
58+
{
59+
var destructiveHint =
60+
mcpToolAnnotationsDirectives.Any(
61+
d => isMutationField
62+
? d.DestructiveHint is null or true
63+
: d.DestructiveHint is true);
64+
65+
argumentAssignments.Add(
66+
new ArgumentAssignment(ArgumentNames.DestructiveHint, destructiveHint));
67+
}
68+
69+
if (!mcpToolAnnotationsDirectives.All(d => d.IdempotentHint is null))
70+
{
71+
var idempotentHint =
72+
mcpToolAnnotationsDirectives.All(
73+
d => isMutationField
74+
? d.IdempotentHint is true
75+
: d.IdempotentHint is null or true);
76+
77+
argumentAssignments.Add(
78+
new ArgumentAssignment(ArgumentNames.IdempotentHint, idempotentHint));
79+
}
80+
81+
if (!mcpToolAnnotationsDirectives.All(d => d.OpenWorldHint is null))
82+
{
83+
var openWorldHint =
84+
mcpToolAnnotationsDirectives.Any(d => d.OpenWorldHint is null or true);
85+
86+
argumentAssignments.Add(
87+
new ArgumentAssignment(ArgumentNames.OpenWorldHint, openWorldHint));
88+
}
89+
90+
var mcpToolAnnotationsDirective = new Directive(directiveDefinition, argumentAssignments);
91+
92+
mergedMember.AddDirective(mcpToolAnnotationsDirective);
93+
}
94+
}

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Directives/CacheControlDirective.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace HotChocolate.Fusion.Directives;
66

7-
public sealed class CacheControlDirective(
7+
internal sealed class CacheControlDirective(
88
int? maxAge = null,
99
CacheControlScope? scope = null,
1010
bool? inheritMaxAge = null,
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using HotChocolate.Types;
2+
3+
namespace HotChocolate.Fusion.Directives;
4+
5+
internal sealed class McpToolAnnotationsDirective(
6+
bool? destructiveHint = null,
7+
bool? idempotentHint = null,
8+
bool? openWorldHint = null)
9+
{
10+
public bool? DestructiveHint { get; set; } = destructiveHint;
11+
12+
public bool? IdempotentHint { get; set; } = idempotentHint;
13+
14+
public bool? OpenWorldHint { get; set; } = openWorldHint;
15+
16+
public static McpToolAnnotationsDirective From(IDirective directive)
17+
{
18+
var destructiveHint =
19+
(bool?)directive.Arguments.GetValueOrDefault(WellKnownArgumentNames.DestructiveHint)?.Value;
20+
var idempotentHint =
21+
(bool?)directive.Arguments.GetValueOrDefault(WellKnownArgumentNames.IdempotentHint)?.Value;
22+
var openWorldHint =
23+
(bool?)directive.Arguments.GetValueOrDefault(WellKnownArgumentNames.OpenWorldHint)?.Value;
24+
25+
return new McpToolAnnotationsDirective(destructiveHint, idempotentHint, openWorldHint);
26+
}
27+
}

src/HotChocolate/Fusion-vnext/src/Fusion.Composition/Directives/SerializeAsDirective.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace HotChocolate.Fusion.Directives;
66

7-
public sealed class SerializeAsDirective(ScalarSerializationType type, string? pattern)
7+
internal sealed class SerializeAsDirective(ScalarSerializationType type, string? pattern)
88
{
99
public ScalarSerializationType Type { get; } = type;
1010

0 commit comments

Comments
 (0)