Open pierrebiver opened 6 years ago
What do your resolvers look like?
There is the full code:
type descriptorResolver struct {
Descriptor model.Descriptor
}
func (d *descriptorResolver) ID() graphql.ID {
return d.Descriptor.ID
}
func (d *descriptorResolver) Name() string {
return d.Descriptor.Name
}
func (d *descriptorResolver) Description() *string {
return &d.Descriptor.Description
}
func (d *descriptorResolver) Example() *string {
return &d.Descriptor.Example
}
func (d *descriptorResolver) Tags() []string {
return d.Descriptor.Tags
}
func (r *Resolver) Descriptors() *[]*descriptorResolver {
descriptors, _ := mongo.Descriptors()
descriptorResolvers := make([]*descriptorResolver, 0)
for _, d := range descriptors {
descriptorResolvers = append(descriptorResolvers, &descriptorResolver{d})
}
return &descriptorResolvers
}
Hmm I wonder if the struct itself has to be exported in addition to the fields? I.e. would it need to be DescriptorResolver
instead of descriptorResolver
?
I tried and there is no difference. In addition, when I don't put the result of the query as mandatory, it works perfectly fine.
I am trying to create a many to many relation between "Products" and "RelatedProductGroup" These are the schema definitions of both the structures.
type Product { id: ID! name: String! group: String! relprogroups: [RelatedProductGroup!]! }
input ProductInput {
id: ID!
name: String!
group: String!
relprogroups: [RelatedProductGroupInput!]!
}
type RelatedProductGroup {
id: ID!
grouptype: String!
product: [Product!]!
}
input RelatedProductGroupInput {
id: ID!
grouptype: String!
product: [ProductInput!]!
}
//function for create Product
func (r Resolver) CreateProduct(args struct { Product productInput }) productResolver {
var createdRelatedproductgroup []*x_related_product_group
for _,v:=range args.Product.Relprogroups{
createdRelatedproductgroup=append(createdRelatedproductgroup,&x_related_product_group{
id: v.ID,
grouptype: v.Grouptype,
//missing relatedproductgroup field // (ISSUE)
},)
}
product := &x_product{
id: args.Product.ID,
name: args.Product.Name,
group: args.Product.Group,
relprogroups: createdRelatedproductgroup,
}
productData[product.id] = product
return &productResolver{productData[product.id]}
}
Now when i am trying to create Products (considering 1 product has many (1-many) relatedProductGroups) with query:
mutation{ createProduct(product:{id:"1100",name:"Heater-2",group:"Electronics",relprogroups:{id:"2"}}){ id grouptype product{ id name group } } }
IT THROWS AN ERROR at RUNTIME: Argument \"product\" has invalid value {id: \"1100\", name: \"Heater-2\", group: \"Electronics\", relprogroups: {id: \"2\"}}.\nIn field \"relprogroups\": In field \"grouptype\": Expected \"String!\", found null. //since the relation is many to many , it is expecting further product in relprogroups in the query and so on.....
So basically how can i omit a field while creating a record in my query ??
Hi @pierrebiver are you have found the reasons behind this error?
I have a query as such:
I declared properly the resolver but I got the following error:
But If I remove the "!" to show that array and array's content shall not be empty, the error disappears. Any idea why it behaves this way?