shurcooL / graphql

Package graphql provides a GraphQL client implementation.
MIT License
709 stars 282 forks source link

Question: How to implement an enumeration type #67

Open carstenmichel opened 3 years ago

carstenmichel commented 3 years ago

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

dmitshur commented 3 years ago

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.