question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flags enums are not correctly inferred.

See original GitHub issue

Describe the bug If we infer a enum type form a flags enum like HotChocolate.Types.EnumType<System.Reflection.TypeAttributes we will run in to an error that the value names cannot be correctly inferred since each value can have multiple states leading to names like:

AUTOLAYOUT, ANSICLASS, CLASS, PUBLIC

To Reproduce

var schema = SchemaBuilder.New()
                .AddQueryType(c => c
                    .Name("Query")
                    .Field("foo")
                    .Type<StringType>()
                    .Resolver("bar"))
                .AddType<HotChocolate.Types.EnumType<System.Reflection.TypeAttributes>>()
                .Create();

Expected behavior This still has to be defined. Do we infer those as a list of enums. Leading to things like [[MyFlagsEnum]]?

Environment (please complete the following information):

  • Version 10.0.1

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
PascalSenncommented, Jun 3, 2022

Plans yes, but it’s not a trivial change and there are a couple of other things before it in the backlog.

Essentially it would make sense to map the flag enum into a type:

[Flags]
public enum Foo { Bar=0,  Baz=1, Qux =2}

public class FooType : ObjectType<Foo> {
  protected override void Configure(IObjectTypeDescriptor<Foo> descriptor) 
  {
      descriptor.Field("isBar").Resolve(x => x.Parent<Foo>() & Foo.Bar == Foo.Bar);
      descriptor.Field("isBaz").Resolve(x => x.Parent<Foo>() &Foo.Baz == Foo.Baz);
      descriptor.Field("isQux").Resolve(x => x.Parent<Foo>() &Foo.Qux == Foo.Qux);
  }
} 

I guess as a workaround you could just define this type yourself

1reaction
jonmillcommented, Jun 5, 2020

Gotcha; so it sounds like the guidance right now is to add a converter to treat it (from the client perspective) as a numeric value, but the converter can convert it to the enum flags?

Is there a list of work to do for this? We use flags for a bunch of things in my company’s product, so I’d be interested in helping out 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flags enums are not correctly inferred. · Issue #1020
Describe the bug If we infer a enum type form a flags enum like HotChocolate.Types. ... Flags enums are not correctly inferred. #1020....
Read more >
c# - Enum Flags Negative Value
All I am given is a int property with the reason, and an SDK that says check this reason against a bit mask...
Read more >
The trouble with TypeScript enums
In TypeScript, enums have a few surprising limitations. In particular, it can be challenging to check whether or not a value is in...
Read more >
How To Use Enums in TypeScript
In TypeScript, enums, or enumerated types, are data structures of constant length that hold a set of constant values.
Read more >
design patterns - Is it a good practice to use List of Enums?
When some enum member is not a valid flag in some scenario, consider splitting the enum into multiple distinct enums.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found