Skip to content

Commit

Permalink
Custom Scalar Specification URLs (#2614)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelstaib committed Nov 19, 2020
1 parent 8d65cda commit 283ad9b
Show file tree
Hide file tree
Showing 48 changed files with 461 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public IActivityScope ExecuteRequest(IRequestContext context)
{
var scopes = new IActivityScope[_listeners.Length];

for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
scopes[i] = _listeners[i].ExecuteRequest(context);
}
Expand All @@ -31,7 +31,7 @@ public IActivityScope ExecuteRequest(IRequestContext context)

public void RequestError(IRequestContext context, Exception exception)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].RequestError(context, exception);
}
Expand All @@ -41,7 +41,7 @@ public IActivityScope ParseDocument(IRequestContext context)
{
var scopes = new IActivityScope[_listeners.Length];

for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
scopes[i] = _listeners[i].ParseDocument(context);
}
Expand All @@ -51,7 +51,7 @@ public IActivityScope ParseDocument(IRequestContext context)

public void SyntaxError(IRequestContext context, IError error)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].SyntaxError(context, error);
}
Expand All @@ -61,7 +61,7 @@ public IActivityScope ValidateDocument(IRequestContext context)
{
var scopes = new IActivityScope[_listeners.Length];

for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
scopes[i] = _listeners[i].ValidateDocument(context);
}
Expand All @@ -71,7 +71,7 @@ public IActivityScope ValidateDocument(IRequestContext context)

public void ValidationErrors(IRequestContext context, IReadOnlyList<IError> errors)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].ValidationErrors(context, errors);
}
Expand All @@ -86,7 +86,7 @@ public IActivityScope ResolveFieldValue(IMiddlewareContext context)

var scopes = new IActivityScope[_resolverListener.Length];

for (int i = 0; i < _resolverListener.Length; i++)
for (var i = 0; i < _resolverListener.Length; i++)
{
scopes[i] = _resolverListener[i].ResolveFieldValue(context);
}
Expand All @@ -96,7 +96,7 @@ public IActivityScope ResolveFieldValue(IMiddlewareContext context)

public void ResolverError(IMiddlewareContext context, IError error)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].ResolverError(context, error);
}
Expand All @@ -111,7 +111,7 @@ public IActivityScope RunTask(IExecutionTask task)

var scopes = new IActivityScope[_resolverListener.Length];

for (int i = 0; i < _resolverListener.Length; i++)
for (var i = 0; i < _resolverListener.Length; i++)
{
scopes[i] = _resolverListener[i].RunTask(task);
}
Expand All @@ -121,71 +121,71 @@ public IActivityScope RunTask(IExecutionTask task)

public void TaskError(IExecutionTask task, IError error)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].TaskError(task, error);
}
}

public void AddedDocumentToCache(IRequestContext context)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].AddedDocumentToCache(context);
}
}

public void RetrievedDocumentFromCache(IRequestContext context)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].RetrievedDocumentFromCache(context);
}
}

public void RetrievedDocumentFromStorage(IRequestContext context)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].RetrievedDocumentFromStorage(context);
}
}

public void AddedOperationToCache(IRequestContext context)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].AddedDocumentToCache(context);
}
}

public void RetrievedOperationFromCache(IRequestContext context)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].RetrievedDocumentFromCache(context);
}
}

public void BatchDispatched(IRequestContext context)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].BatchDispatched(context);
}
}

public void ExecutorCreated(string name, IRequestExecutor executor)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].ExecutorCreated(name, executor);
}
}

public void ExecutorEvicted(string name, IRequestExecutor executor)
{
for (int i = 0; i < _listeners.Length; i++)
for (var i = 0; i < _listeners.Length; i++)
{
_listeners[i].ExecutorEvicted(name, executor);
}
Expand All @@ -205,7 +205,7 @@ public void Dispose()
{
if (!_disposed)
{
for (int i = 0; i < _scopes.Length; i++)
for (var i = 0; i < _scopes.Length; i++)
{
_scopes[i].Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ internal sealed class RequestExecutorResolver
, IInternalRequestExecutorResolver
, IDisposable
{
private readonly SemaphoreSlim _semaphore = new SemaphoreSlim(1, 1);
private readonly ConcurrentDictionary<string, RegisteredExecutor> _executors =
new ConcurrentDictionary<string, RegisteredExecutor>();
private readonly SemaphoreSlim _semaphore = new(1, 1);
private readonly ConcurrentDictionary<string, RegisteredExecutor> _executors = new();
private readonly IRequestExecutorOptionsMonitor _optionsMonitor;
private readonly IServiceProvider _applicationServices;
private bool _disposed;
Expand Down
3 changes: 1 addition & 2 deletions src/HotChocolate/Core/src/Fetching/BatchScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ public class BatchScheduler
: IBatchScheduler
, IBatchDispatcher
{
private readonly ConcurrentQueue<Func<ValueTask>> _queue =
new ConcurrentQueue<Func<ValueTask>>();
private readonly ConcurrentQueue<Func<ValueTask>> _queue = new();

public bool HasTasks => _queue.Count > 0;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/HotChocolate/Core/src/Types/Properties/TypeResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -644,4 +644,28 @@ Type: `{0}`</value>
<data name="NodeDescriptor_IdField_MustBePropertyOrMethod" xml:space="preserve">
<value>The ID field must be a property or a method.</value>
</data>
<data name="DeprecatedDirectiveType_TypeDescription" xml:space="preserve">
<value>The @deprecated directive is used within the type system definition language to indicate deprecated portions of a GraphQL service’s schema,such as deprecated fields on a type or deprecated enum values.</value>
</data>
<data name="DeprecatedDirectiveType_ReasonDescription" xml:space="preserve">
<value>Deprecations include a reason for why it is deprecated, which is formatted using Markdown syntax (as specified by CommonMark).</value>
</data>
<data name="IncludeDirectiveType_TypeDescription" xml:space="preserve">
<value>Directs the executor to include this field or fragment only when the `if` argument is true.</value>
</data>
<data name="IncludeDirectiveType_IfDescription" xml:space="preserve">
<value>Included when true.</value>
</data>
<data name="SkipDirectiveType_TypeDescription" xml:space="preserve">
<value>Directs the executor to skip this field or fragment when the `if` argument is true.</value>
</data>
<data name="SkipDirectiveType_IfDescription" xml:space="preserve">
<value>Skipped when true.</value>
</data>
<data name="SpecifiedByDirectiveType_TypeDescription" xml:space="preserve">
<value>The `@specifiedBy` directive is used within the type system definition language to provide a URL for specifying the behavior of custom scalar definitions.</value>
</data>
<data name="SpecifiedByDirectiveType_UrlDescription" xml:space="preserve">
<value>The specifiedBy URL points to a human-readable specification. This field will only read a result for scalar types.</value>
</data>
</root>
56 changes: 23 additions & 33 deletions src/HotChocolate/Core/src/Types/SchemaSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ public static void Serialize(ISchema schema, TextWriter textWriter)
.OfType<IDefinitionNode>()
.ToList();

if (schema.QueryType != null
|| schema.MutationType != null
|| schema.SubscriptionType != null)
if (schema.QueryType is not null
|| schema.MutationType is not null
|| schema.SubscriptionType is not null)
{
typeDefinitions.Insert(0, SerializeSchemaTypeDefinition(schema));
}
Expand Down Expand Up @@ -133,21 +133,21 @@ private static bool IsPublicAndNoScalar(INamedType type)
{
var operations = new List<OperationTypeDefinitionNode>();

if (schema.QueryType != null)
if (schema.QueryType is not null)
{
operations.Add(SerializeOperationType(
schema.QueryType,
OperationType.Query));
}

if (schema.MutationType != null)
if (schema.MutationType is not null)
{
operations.Add(SerializeOperationType(
schema.MutationType,
OperationType.Mutation));
}

if (schema.SubscriptionType != null)
if (schema.SubscriptionType is not null)
{
operations.Add(SerializeOperationType(
schema.SubscriptionType,
Expand All @@ -171,12 +171,10 @@ private static bool IsPublicAndNoScalar(INamedType type)
ObjectType type,
OperationType operation)
{
return new OperationTypeDefinitionNode
(
return new(
null,
operation,
SerializeNamedType(type)
);
SerializeNamedType(type));
}

private static ITypeDefinitionNode SerializeNonScalarTypeDefinition(
Expand Down Expand Up @@ -320,13 +318,15 @@ private static EnumValueDefinitionNode SerializeEnumValue(IEnumValue enumValue)
private static ScalarTypeDefinitionNode SerializeScalarType(
ScalarType scalarType)
{
return new ScalarTypeDefinitionNode
(
var directives = scalarType.Directives
.Select(SerializeDirective)
.ToList();

return new(
null,
new NameNode(scalarType.Name),
SerializeDescription(scalarType.Description),
Array.Empty<DirectiveNode>()
);
directives);
}

private static FieldDefinitionNode SerializeObjectField(IOutputField field)
Expand All @@ -351,18 +351,14 @@ private static FieldDefinitionNode SerializeObjectField(IOutputField field)
}

private static InputValueDefinitionNode SerializeInputField(
IInputField inputValue)
{
return new InputValueDefinitionNode
(
IInputField inputValue) =>
new(
null,
new NameNode(inputValue.Name),
SerializeDescription(inputValue.Description),
SerializeType(inputValue.Type),
inputValue.DefaultValue,
inputValue.Directives.Select(SerializeDirective).ToList()
);
}
inputValue.Directives.Select(SerializeDirective).ToList());

private static ITypeNode SerializeType(IType type)
{
Expand All @@ -384,21 +380,15 @@ private static ITypeNode SerializeType(IType type)
throw new NotSupportedException();
}

private static NamedTypeNode SerializeNamedType(INamedType namedType)
{
return new NamedTypeNode(null, new NameNode(namedType.Name));
}
private static NamedTypeNode SerializeNamedType(INamedType namedType) =>
new(null, new NameNode(namedType.Name));

private static DirectiveNode SerializeDirective(IDirective directiveType)
{
return directiveType.ToNode(true);
}
private static DirectiveNode SerializeDirective(IDirective directiveType) =>
directiveType.ToNode(true);

private static StringValueNode SerializeDescription(string description)
{
return string.IsNullOrEmpty(description)
private static StringValueNode SerializeDescription(string description) =>
string.IsNullOrEmpty(description)
? null
: new StringValueNode(description);
}
}
}

0 comments on commit 283ad9b

Please sign in to comment.