I’d like to write a GraphQL query that creates an event with an optional location. So my schema is like this:
type Event {
id: ID!
title: String!
location: Point @search
}
And I wanted to add an event with this mutation:
const ADD_EVENT = gql`
mutation addEvent(
$title: String!
$latitude: Float
$longitude: Float
) {
addEvent(
input: [{
title: $title
location: {
latitude: $latitude
longitude: $longitude
}
}]
) {
id
title
location
}
}
`
The above mutation doesn’t work and I get errors saying it expects latitude and longitude to be required, whereas in my mutation they aren’t required. Based on the documentation it looks like the built-in Point type has latitude and longitude as required fields, so that’s why Dgraph thinks those values should be required. But what’s the best way to approach it when the entire Point is optional?
I worked around it by adding zero values as latitude and longitude, but of course that makes it harder to filter based on which events have a location or not, so it seems messier that way.