2

How can I set the type for model.fields in gqlgen?

I used model.Fields[0].Type here and I want just to use string here:

// Defining mutation function
func mutateHook(b *modelgen.ModelBuild) *modelgen.ModelBuild {
    for _, model := range b.Models {
        for _, field := range model.Fields {
            field.Tag += ` orm_binding:"` + model.Name + `.` + field.Name + `"`
        }
        model.Fields = append(model.Fields, &modelgen.Field{
            Description: "ex",
            Name:        "ex",
            Type:        model.Fields[0].Type,
        })
    }
    return b
}

I think I should implement the types.Type interface, but is there an easier way to do it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131

1 Answers1

2

After a lot of search I found the solution:

typ = types.Typ[types.String].Underlying()

This is the magic code that I was looking for.

Answer added on behalf of OP

Dharman
  • 30,962
  • 25
  • 85
  • 135