Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane32 committed Jun 4, 2024
2 parents 29bbd00 + 72a9775 commit 44f6be8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/GraphQL.ApiTests/net50/GraphQL.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ namespace GraphQL
public bool TryRetrieve(TKey key, out TValue? value) { }
public void WithValue(TKey key, System.Action<TValue> action) { }
}
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class MapAutoClrTypeAttribute : System.Attribute
{
public MapAutoClrTypeAttribute() { }
}
public static class MemoryExtensions
{
public static System.Collections.Generic.IList<T> Constrained<T>(this T[] array, int count) { }
Expand Down
5 changes: 5 additions & 0 deletions src/GraphQL.ApiTests/net60/GraphQL.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ namespace GraphQL
public bool TryRetrieve(TKey key, out TValue? value) { }
public void WithValue(TKey key, System.Action<TValue> action) { }
}
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class MapAutoClrTypeAttribute : System.Attribute
{
public MapAutoClrTypeAttribute() { }
}
public static class MemoryExtensions
{
public static System.Collections.Generic.IList<T> Constrained<T>(this T[] array, int count) { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@ namespace GraphQL
public bool TryRetrieve(TKey key, out TValue? value) { }
public void WithValue(TKey key, System.Action<TValue> action) { }
}
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=true)]
public sealed class MapAutoClrTypeAttribute : System.Attribute
{
public MapAutoClrTypeAttribute() { }
}
public static class MemoryExtensions
{
public static System.Collections.Generic.IList<T> Constrained<T>(this T[] array, int count) { }
Expand Down
12 changes: 12 additions & 0 deletions src/GraphQL/Attributes/MapAutoClrTypeAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace GraphQL;

/// <summary>
/// Indicates that <see cref="GraphQLBuilderExtensions.AddAutoClrMappings(DI.IGraphQLBuilder, bool, bool)"/>
/// should include this class when creating auto CLR type mappings, even when <c>mapInputTypes</c>
/// or <c>mapOutputTypes</c> is <see langword="false"/>.
/// This attribute should be placed on the CLR type that comprises the mapping.
/// </summary>
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public sealed class MapAutoClrTypeAttribute : Attribute
{
}
9 changes: 9 additions & 0 deletions src/GraphQL/Extensions/GraphQLBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,15 @@ public static IGraphQLBuilder AddExecutionStrategy<TExecutionStrategy>(this IGra
/// </summary>
/// <remarks>
/// When applicable, place after calls to UseAutomaticPersistedQueries to ensure that the query document is recorded properly.
/// <br/>
/// To instruct OpenTelemetry SDK to collect the traces produced by GraphQL.NET register the
/// '<see cref="GraphQLTelemetryProvider.SourceName"/>' source name with the TracerProviderBuilder.
/// <code>
/// services
/// .AddOpenTelemetry()
/// .WithTracing(tracing =&gt; tracing
/// .AddSource(GraphQLTelemetryProvider.SourceName));
/// </code>
/// </remarks>
public static IGraphQLBuilder UseTelemetry(this IGraphQLBuilder builder, Action<GraphQLTelemetryOptions>? configure = null)
=> UseTelemetry<GraphQLTelemetryProvider>(builder, configure);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Reflection;

namespace GraphQL.Types;

/// <summary>
Expand Down Expand Up @@ -40,8 +42,8 @@ public AutoRegisteringGraphTypeMappingProvider(bool mapInputTypes, bool mapOutpu
if (preferredType != null)
return preferredType;

if (isInputType && !_mapInputTypes ||
!isInputType && !_mapOutputTypes ||
if (isInputType && !_mapInputTypes && !IsForcedType(clrType) ||
!isInputType && !_mapOutputTypes && !IsForcedType(clrType) ||
clrType.IsEnum ||
SchemaTypes.BuiltInScalarMappings.ContainsKey(clrType))
return null;
Expand All @@ -58,5 +60,7 @@ public AutoRegisteringGraphTypeMappingProvider(bool mapInputTypes, bool mapOutpu
{
return typeof(AutoRegisteringObjectGraphType<>).MakeGenericType(clrType);
}

static bool IsForcedType(Type type) => type.GetCustomAttribute<MapAutoClrTypeAttribute>() != null;
}
}

0 comments on commit 44f6be8

Please sign in to comment.