Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed Introspection Operation Name #6057

Merged
merged 3 commits into from
Apr 17, 2023
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
7 changes: 6 additions & 1 deletion src/HotChocolate/Core/src/Execution/ErrorHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Net;
using HotChocolate.Execution.Processing;
using HotChocolate.Language;
using static HotChocolate.Execution.Properties.Resources;
Expand Down Expand Up @@ -126,7 +127,11 @@ public static IQueryResult RootTypeNotFound(OperationType operationType) =>
QueryResultBuilder.CreateError(
ErrorBuilder.New()
.SetMessage(ErrorHelper_RootTypeNotFound_Message, operationType)
.Build());
.Build(),
new Dictionary<string, object?>
{
{ WellKnownContextData.HttpStatusCode, HttpStatusCode.BadRequest }
});

public static IQueryResult StateInvalidForOperationResolver() =>
QueryResultBuilder.CreateError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public TypeSystemObjectBase CreateInstance(Type namedSchemaType)
return (TypeSystemObjectBase)constructor.Invoke(Array.Empty<object>());
}

var args = new object[parameters.Length];
var args = new object?[parameters.Length];

for (var i = 0; i < parameters.Length; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public TypeReference GetArgumentTypeRef(
}

/// <inheritdoc />
public IExtendedType GetArgumentType(
public virtual IExtendedType GetArgumentType(
ParameterInfo parameter,
bool ignoreAttributes = false)
{
Expand Down
107 changes: 53 additions & 54 deletions src/HotChocolate/Utilities/src/Utilities.Introspection/BuiltInTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,73 @@
using static HotChocolate.Utilities.Introspection.WellKnownTypes;
using static HotChocolate.Utilities.Introspection.WellKnownDirectives;

namespace HotChocolate.Utilities.Introspection
namespace HotChocolate.Utilities.Introspection;

public static class BuiltInTypes
{
public static class BuiltInTypes
{
private static readonly HashSet<string> _typeNames =
new()
{
__Directive,
__DirectiveLocation,
__EnumValue,
__Field,
__InputValue,
__Schema,
__Type,
__TypeKind,
String,
Boolean,
Float,
ID,
Int,
};
private static readonly HashSet<string> _typeNames =
new()
{
__Directive,
__DirectiveLocation,
__EnumValue,
__Field,
__InputValue,
__Schema,
__Type,
__TypeKind,
String,
Boolean,
Float,
ID,
Int,
};

private static readonly HashSet<string> _directiveNames =
new()
{
Skip,
Include,
Deprecated,
Defer,
Stream,
SpecifiedBy
};
private static readonly HashSet<string> _directiveNames =
new()
{
Skip,
Include,
Deprecated,
Defer,
Stream,
SpecifiedBy
};

public static bool IsBuiltInType(string name)
=> _typeNames.Contains(name) || _directiveNames.Contains(name);
public static bool IsBuiltInType(string name)
=> _typeNames.Contains(name) || _directiveNames.Contains(name);

public static DocumentNode RemoveBuiltInTypes(this DocumentNode schema)
public static DocumentNode RemoveBuiltInTypes(this DocumentNode schema)
{
if (schema is null)
{
if (schema is null)
{
throw new System.ArgumentNullException(nameof(schema));
}
throw new System.ArgumentNullException(nameof(schema));
}

var definitions = new List<IDefinitionNode>();
var definitions = new List<IDefinitionNode>();

foreach (var definition in schema.Definitions)
foreach (var definition in schema.Definitions)
{
if (definition is INamedSyntaxNode type)
{
if (definition is INamedSyntaxNode type)
{
if (!_typeNames.Contains(type.Name.Value))
{
definitions.Add(definition);
}
}
else if (definition is DirectiveDefinitionNode directive)
if (!_typeNames.Contains(type.Name.Value))
{
if (!_directiveNames.Contains(directive.Name.Value))
{
definitions.Add(definition);
}
definitions.Add(definition);
}
else
}
else if (definition is DirectiveDefinitionNode directive)
{
if (!_directiveNames.Contains(directive.Name.Value))
{
definitions.Add(definition);
}
}

return new DocumentNode(definitions);
else
{
definitions.Add(definition);
}
}

return new DocumentNode(definitions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,58 @@
using System.Threading.Tasks;
using HotChocolate.Language;

namespace HotChocolate.Utilities.Introspection
namespace HotChocolate.Utilities.Introspection;

/// <summary>
/// The <see cref="IIntrospectionClient"/> for introspecting a GraphQL server and
/// downloading the introspection result as GraphQL SDL.
/// </summary>
public interface IIntrospectionClient
{
public interface IIntrospectionClient
{
/// <summary>
/// Downloads the schema information from a GraphQL server
/// and writes it as GraphQL SDL to the given stream.
/// </summary>
/// <param name="client">
/// The HttpClient that shall be used to execute the introspection query.
/// </param>
/// <param name="stream">
/// The stream to which the schema shall be written to.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
Task DownloadSchemaAsync(
HttpClient client,
Stream stream,
CancellationToken cancellationToken = default);
/// <summary>
/// Downloads the schema information from a GraphQL server
/// and writes it as GraphQL SDL to the given stream.
/// </summary>
/// <param name="client">
/// The HttpClient that shall be used to execute the introspection query.
/// </param>
/// <param name="stream">
/// The stream to which the schema shall be written to.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
Task DownloadSchemaAsync(
HttpClient client,
Stream stream,
CancellationToken cancellationToken = default);

/// <summary>
/// Downloads the schema information from a GraphQL server
/// and returns the schema syntax tree.
/// </summary>
/// <param name="client">
/// The HttpClient that shall be used to execute the introspection query.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
/// <returns>Returns a parsed GraphQL schema syntax tree.</returns>
Task<DocumentNode> DownloadSchemaAsync(
HttpClient client,
CancellationToken cancellationToken = default);
/// <summary>
/// Downloads the schema information from a GraphQL server
/// and returns the schema syntax tree.
/// </summary>
/// <param name="client">
/// The HttpClient that shall be used to execute the introspection query.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
/// <returns>Returns a parsed GraphQL schema syntax tree.</returns>
Task<DocumentNode> DownloadSchemaAsync(
HttpClient client,
CancellationToken cancellationToken = default);

/// <summary>
/// Gets the supported GraphQL features from the server by doing an introspection query.
/// </summary>
/// <param name="client">
/// The HttpClient that shall be used to execute the introspection query.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
/// <returns>Returns an object that indicates what features are supported.</returns>
Task<ISchemaFeatures> GetSchemaFeaturesAsync(
HttpClient client,
CancellationToken cancellationToken = default);
}
/// <summary>
/// Gets the supported GraphQL features from the server by doing an introspection query.
/// </summary>
/// <param name="client">
/// The HttpClient that shall be used to execute the introspection query.
/// </param>
/// <param name="cancellationToken">
/// The cancellation token.
/// </param>
/// <returns>Returns an object that indicates what features are supported.</returns>
Task<ISchemaFeatures> GetSchemaFeaturesAsync(
HttpClient client,
CancellationToken cancellationToken = default);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
namespace HotChocolate.Utilities.Introspection
namespace HotChocolate.Utilities.Introspection;

/// <summary>
/// Represents the features that are supported by a GraphQL server.
/// </summary>
public interface ISchemaFeatures
{
public interface ISchemaFeatures
{
bool HasDirectiveLocations { get; }
bool HasRepeatableDirectives { get; }
bool HasSubscriptionSupport { get; }
}
/// <summary>
/// Gets a value that indicates whether the server supports the
/// newer directive locations on when introspecting.
/// </summary>
bool HasDirectiveLocations { get; }

/// <summary>
/// Gets a value that indicates whether the server supports the repeatable directives.
/// </summary>
bool HasRepeatableDirectives { get; }

/// <summary>
/// Gets a value that indicates whether the server supports subscriptions.
/// </summary>
bool HasSubscriptionSupport { get; }
}
Loading