with a Schema like (I can’t use the actual schema - client project/NDA - so typing this made-up one in directly here but it’s hopefully close):
type Location {
id: ID!
lat: Float!
long: Float!
title: String
}
type Event {
id: ID!
title: String!
location: Location!
}
I would like to create an Event
for a new Location
.
Dgraph will automatically create Mutation fields of the form:
addLocation(input: [LocationInput!]!):LocationPayload
and a similar
addEvent(input: [EventInput!]!): EventPayload
I can call the mutations one at a time using graphiql
and something like:
mutation {
addLocation(input: [{lat: 10.5, long: 22.5, title: "fake place"}]) {
id
title
}
}
and if it returned an id of “0x7034”, I can copy and paste that into the next mutation to create the event for that location:
mutation {
addEvent(input: [{title: "Rally!", location: { id: "0x7034"} }]) {
id
title
}
}
and it will work great, but the “copy-and-paste” part is unfortunate…
What I think should be possible is to bundle the two into a single mutation
and have the id returned for the location created in the first one (or it’s ‘uid’ in the system) usable for the location field of the second mutation to create the event.
Something like:
addLocation(input: [{lat: 10.5, long: 22.5, title: "fake place"}]) {
locid as id
title
}
addEvent(input: [{title: "Rally!", location: { id: $locid }}]) {
id
title
}
}
I tried the “locid as id” as shown above (or as “uid”), from the documentation. I tried the _:name
style notation from elsewhere in the docs. I tried id @export(as: "locid")
. (“export not defined”).
No luck - Dgraph always returns an error of one kind or another.
- Is this possible? (example using graphiql would be most helpful)
- How?
Thanks in advance for any insight.