@abhijit-kar good ideas unfortunately I’m still having issues (probably due to my misunderstanding the problem).
Here’s the actual schema (truncated since not all of it is necessary).
type Protocol implements Location @auth(
...
) {
id: ID!
owner: OwnerOrg!
name: String! @search(by: [fulltext])
description: String! @search(by: [fulltext])
form: ProtocolForm! @hasInverse(field: protocols)
plan: Plan!
dobStart: DateTime
dobEnd: DateTime
race: [Race]
sex: [Sex]
specimens: [Specimen!]! @hasInverse(field: protocol)
}
type Plan @auth(
...
) {
id: ID!
owner: OwnerOrg!
name: String! @search(by: [fulltext])
labs: [LabOrg!]! @hasInverse(field: plans)
storages: [StorageOrg!]! @hasInverse(field: plans)
protocol: Protocol! @hasInverse(field: plan)
}
The Location
interface just has some scalar values for specific addresses and the ProtocolForm
type is another type that implements a Form
interface again with basic scalars.
In my Go code I’m doing something like this:
owner := map[string]string{
"id": ownerID,
}
protocolInputs := []map[string]interface{}{}
for _, protocolName := range protocolNames {
input := map[string]interface{}{
"street": randomString(streets),
"city": randomString(cities),
"county": randomString(counties),
"state": randomString(states),
"zip": randomInt(zips),
"country": randomString(countries),
"owner": owner,
"name": protocolName,
"description": randomString(descriptions),
"form": empty,
"plan": empty,
"dobStart": dobStart.String(),
"dobEnd": dobEnd.String(),
"race": []string{
randomString(race),
},
"sex": []string{
randomString(sex),
},
"specimens": make([]map[string]string, 0),
}
protocolInputs = append(protocolInputs, input)
}
For the empty
variable, I’ve been trying to set it to different values in order for the “add” Protocol
mutation to work (e.g. empty := make(map[string]string)
) but this seems to generate errors like:
{"errors":[{"message":"couldn't rewrite mutation addProtocol because failed to rewrite mutation payload because type ProtocolForm requires a value for field owner, but no value present"},{"message":"couldn't rewrite mutation addProtocol because failed to rewrite mutation payload because type Plan requires a value for field owner, but no value present"},{"message":"couldn't rewrite mutation addProtocol because failed to rewrite mutation payload because type ProtocolForm requires a value for field owner, but no value present"},{"message":"couldn't rewrite mutation addProtocol because failed to rewrite mutation payload because type Plan requires a value for field owner, but no value present"},{"message":"couldn't rewrite mutation addProtocol because failed to rewrite mutation payload because type ProtocolForm requires a value for field owner, but no value present"},{"message":"couldn't rewrite mutation addProtocol because failed to rewrite mutation payload because type Plan requires a value for field owner, but no value present"}]...
I also tried the suggestion of
empty := map[string]string{
"id": "0x0",
}
But got:
{"errors":[{"message":"couldn't rewrite query for mutation addProtocol because ID \"0x0\" isn't a ProtocolForm"}
Any idea what I’m doing wrong here? I definitely prefer the idea of being able to insert an “empty” value that I then update in a subsequent mutation. I don’t actually know the other object values at the time I’m inserting Protocol
in the “add” mutation.
CC @anand for reference.