chkimes / graphql-net

Convert GraphQL to IQueryable
MIT License
892 stars 86 forks source link

Support enums #19

Closed rspeele closed 7 years ago

rspeele commented 8 years ago

GraphQL enums are weird.

They're just identifiers that don't fit any of the other patterns - not variable names, not true, false, or null. We need to be able to distinguish between Color.Orange and Fruit.Orange. To avoid having to do some crazy inference thing where we leave the enum type unresolved until the point at which it's used, let's let people define a prefix with enums.

This could be something like: schema.AddEnum<Fruit>(prefix: "Fruit_")

Ideally it should work similarly to the general primitive type alias support, where if you've run that AddEnum call, you can use anonymous types with that CLR enum type in your field args without issue and with all the schema validation you'd expect.

chkimes commented 8 years ago

This is done, but we should add tests.

epitka commented 7 years ago

Could you clarify how is this used in a query? I am getting message that "...is not a member of any known enum type"

epitka commented 7 years ago

This is either not implemented fully, or I don't understand enough of what is going on but in CS.fs, ResolveEnumValue always returns null when I debug because of this line

default this.ResolveEnumValue() = Unchecked.defaultof<>

and Schema.cs does not seem to be overriding this member.

chkimes commented 7 years ago

Hmm, you're absolutely right. Seems like we're not providing a way to resolve the enum in the schema adapter, so it's just defaulting to null.

epitka commented 7 years ago

I think you can close this issue...