Search code examples
goormgraphqlgqlgen

How can I set the type for model.fields?


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?


Solution

  • 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