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

Fixed default values of enums #4129

Merged
merged 5 commits into from
Aug 27, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,4 +1,5 @@
using System;
using HotChocolate.Internal;
using HotChocolate.Language;
using HotChocolate.Properties;
using HotChocolate.Types.Descriptors.Definitions;
Expand Down Expand Up @@ -102,9 +103,11 @@ public void DefaultValue(object value)
}
else
{
Definition.SetMoreSpecificType(
Context.TypeInspector.GetType(value.GetType()),
TypeContext.Input);
IExtendedType type = Context.TypeInspector.GetType(value.GetType());
ExtendedTypeReference reference = TypeReference.Create(type, TypeContext.Input);

Definition.SetMoreSpecificType(type, TypeContext.Input);
Definition.Dependencies.Add(new(reference, TypeDependencyKind.Completed));
PascalSenn marked this conversation as resolved.
Show resolved Hide resolved
Definition.RuntimeDefaultValue = value;
Definition.DefaultValue = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,15 @@ public class InputWithDefault
[DefaultValue(null)]
public string WithNullDefault { get; set; }

[DefaultValue(FooEnum.Bar)]
public FooEnum Enum { get; set; }

public string WithoutDefault { get; set; }
}

public enum FooEnum
{
Bar, Baz
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ type Query {
input InputWithDefaultInput {
withStringDefault: String = "abc"
withNullDefault: String
enum: FooEnum! = BAR
withoutDefault: String
}

enum FooEnum {
BAR
BAZ
}

"The `@defer` directive may be provided for fragment spreads and inline fragments to inform the executor to delay the execution of the current fragment to indicate deprioritization of the current fragment. A query with `@defer` directive will cause the request to potentially return multiple responses, where non-deferred data is delivered in the initial response and data deferred is delivered in a subsequent response. `@include` and `@skip` take precedence over `@defer`."
directive @defer("If this argument label has a value other than null, it will be passed on to the result of this defer directive. This label is intended to give client applications a way to identify to which fragment a deferred result belongs to." label: String "Deferred when true." if: Boolean) on FRAGMENT_SPREAD | INLINE_FRAGMENT

Expand Down