My return array:
"all": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if services, ok := p.Source.([]models.Services); ok == true {
return services, nil
}
return nil, nil
},
},
frontend gives me:

in getAllServices => all, is a string, with not Key, only values.
Just checking if it's a typo or not - are you sure you want graphql.NewNonNull(graphql.String) as your type instead of graphql.NewList(..)?
Also you might want to use an Object, instead of graphql.String.
I'm not sure about your use case, so if you provide a little more context, it'll be easier to help
Update: asking for a little more context
My typen
package typen
import (
"log"
"sedhoQL_api/services/models"
"github.com/graphql-go/graphql"
)
var ServicesType = graphql.NewObject(graphql.ObjectConfig{
Name: "Services",
Fields: graphql.Fields{
"key": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if services, ok := p.Source.(*models.Services); ok == true {
return services.Key, nil
}
return nil, nil
},
},
"title": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if services, ok := p.Source.(*models.Services); ok == true {
return services.Title, nil
}
return nil, nil
},
},
"description": &graphql.Field{
Type: graphql.NewNonNull(graphql.String),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if services, ok := p.Source.(*models.Services); ok == true {
return services.Description, nil
}
return nil, nil
},
},
"all": &graphql.Field{
Type: graphql.NewList(ServicesType),
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if services, ok := p.Source.([]models.Services); ok == true {
return services, nil
}
return nil, nil
},
},
},
})
My query
package sedho
import (
// "log"
"sedhoQL_api/controllers"
"sedhoQL_api/typen"
"github.com/graphql-go/graphql"
)
func GetAllServices(field *graphql.Object) {
field.AddFieldConfig("getAllServices", &graphql.Field{
Type: typen.ServicesType,
Args: graphql.FieldConfigArgument{},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
d, err := controllers.GetAllServices()
if err != nil {
return nil, err
}
return d, err
},
})
}
And with this updated “all” field, with type graphql.NewList(ServicesType) does it return the same string instead of the array of objects?
i have "all" deleted
and the main function
func GetAllServices(field *graphql.Object) {
field.AddFieldConfig("getAllServices", &graphql.Field{
Type: graphql.NewList(typen.ServicesType),
Args: graphql.FieldConfigArgument{},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
d, err := controllers.GetAllServices()
if err != nil {
return nil, err
}
return d, err
},
})
}

i see 2 rows on response
my request from frontend

Because you try to assert the p.Source to *models.Services instead of models.Services.
The array returned by the controller is []models.Services, so the source in the resolver will be models.Service, not a pointer.
yes... that's it

Great! 🎉 If you don’t have any more issue or question, feel free to close the issue.