graphql icon indicating copy to clipboard operation
graphql copied to clipboard

Question: How to implement an enumeration type

Open carstenmichel opened this issue 4 years ago • 1 comments

Hello, the private API that I want to access needs an enumeration type in one of the parameters. https://graphql.org/learn/schema/#enumeration-types Is there a way to implement this with this library? Many thanks

carstenmichel avatar Feb 09 '21 15:02 carstenmichel

Yes, enumeration types are supported. You can either define types and consts that correspond to the private API schema, for example:

type Episode string

const (
	EpisodeNewHope Episode = "NEWHOPE"
	EpisodeEmpire  Episode = "EMPIRE"
	EpisodeJedi    Episode = "JEDI"
)

And then use the type and individual values. Or you can use the const values directly.

Package githubv4, which builds on top of this general-purpose graphql package, defines Go identifiers for the GitHub API schema via code generation, see its enum.go file.

dmitshur avatar Feb 11 '21 04:02 dmitshur