0

I have a bunch of data, in a .NET GRaphQL API that are basically list of strings like

Public List<string> avarageMessageSize = new List<string>{
"Up to 5 KB",
"Between 5 KB and 4 MB",
Between 4 MB and 20 MB",
"20 MB and bigger"
};

When a new Entity is made with a GraphQL Mutation, for other values that are stored in Enums I have input types that let me choose and pick in a mutation to add the correct value, is this also possible for list items, to pick and choose the correct value(string) in a Mutation?

  • You can easily make the string an enum. Essentially a GraphQL enum can be represented by any object in .NET – Michael Ingmar Staib Aug 22 '22 at 09:52
  • Thanks, so you don't have the normal enum restrictions? I can make a GraphQl enum of strings? – Home of Creation Aug 22 '22 at 10:08
  • Kind of, the enum does not have to be an enum in C#. But they have to follow the GraphQL enum rules. So `Up to 5 KB` would probably be represented by `Up_to_5KB`. But in your .NET API you would just use the `Up to 5 KB` string. And the GraphQL engine would translate it to the enum in GraphQL. You also cannot have arbitrary values anymore, they must be represented by the enum values allowed. – Michael Ingmar Staib Aug 22 '22 at 10:24
  • A yes I see. Thank you! I was stuck on the concept that an enum is basically a collection of named numerical values. – Home of Creation Aug 22 '22 at 10:27

1 Answers1

1

You can easily make the string an enum. Essentially a GraphQL enum can be represented by any object in dotnet.

The strings have to follow the GraphQL enum rules. So Up to 5 KB would probably be represented by Up_to_5KB. But in your dotnet API you would just use the Up to 5 KB string.

The GraphQL engine would translate it to the enum in GraphQL. You also cannot have arbitrary values anymore, they must be represented by the enum values allowed in this case.