When I mark a field in graphql schema as non-mandatory, the struct generated model contains pointers instead of actual variable.
Graphql Schema | Generated Struct |
---|---|
input NewTodo { text: String userId: String } |
type NewTodo struct { Text *string json:"text" UserID *string json:"userId" } |
When the field is marked as mandatory,
Graphql Schema | Generated Struct |
---|---|
input NewTodo { text: String! userId: String! } |
type NewTodo struct { Text string json:"text" UserID string json:"userId" } |
the struct that gets created is with reference
type NewTodo struct {
Text *string `json:"text"`
UserID *string `json:"userId"`
}
This is because, the fields when generated as mandatory -
- It should send values
- Values cannot be nil
- Else, gql will not know