Live Loader fails loading Point type from GraphQL schema

Report a Dgraph Bug

What version of Dgraph are you using?

Dgraph Version
$ dgraph version
 
Dgraph version   : v21.03.1
Dgraph codename  : rocket-1
Dgraph SHA-256   : a00b73d583a720aa787171e43b4cb4dbbf75b38e522f66c9943ab2f0263007fe
Commit SHA-1     : ea1cb5f35
Commit timestamp : 2021-06-17 20:38:11 +0530
Branch           : HEAD
Go version       : go1.16.2
jemalloc enabled : true

For Dgraph official documentation, visit https://dgraph.io/docs.
For discussions about Dgraph     , visit http://discuss.dgraph.io.
For fully-managed Dgraph Cloud   , visit https://dgraph.io/cloud.

Licensed variously under the Apache Public License 2.0 and Dgraph Community License.
Copyright 2015-2021 Dgraph Labs, Inc.

Have you tried reproducing the issue with the latest release?

Yes

What is the hardware spec (RAM, OS)?

MacOS 16GB, but I’m running the standalone docker image dgraph/dgraph:v21.03.1

Steps to reproduce the issue (command/config used to run Dgraph).

I am firing up a standalone docker dgraph instance, and pushing the following graphql schema:

type Building {
    id: String! @id
    location: Point!
}

I have a json file representing bulk data I want to import:

[{"Building.id":"100085724R","Building.location":{"longitude":22.747430860292567,"latitude":60.061069293715555}}]

I run the following command to live load the test json file into the standalone dgraph instance:

docker compose run dgraph-cli dgraph live --files /seed/test.json --zero dgraph:5080 --alpha dgraph:9080 --upsertPredicate "Building.id"

Expected behaviour and actual result.

I expect live loader to import exactly 1 node at Building.id, with a lat/long Point linked to it at Building.location as the Building type.

Instead, dgraph dies badly:

Running transaction with dgraph endpoint: dgraph:9080
Found 1 data file(s) to process
Processing data file "/seed/test.json"
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown
Error while mutating: Input for predicate "Building.location" of type scalar is uid. Edge: entity:4000004 attr:"\000\000\000\000\000\000\000\000Building.location" value_type:UID value_id:4000005  s.Code Unknown

So the following is the correct format for importing a geo in DQL compatible types (the GraphQL types aren’t compatible with live loader)

[{"Building.id":"100085724R","Building.location":{
  "type": "Point",
  "coordinates": [22.747430860292567,60.061069293715555]
  }}]

There should really be some definitive documentation about what types exist in dgraph, what their respective formats are in DGL and GraphQL, and how they can be represented in RDF and JSON.

Very frustrating to have to dig into tutorials to find an answer to this.

EDIT: Actually, this isn’t working either. The values for Building.location got imported as regular predicates. I must have imported them before I applied the graphql schema.

Can someone show me the correct JSON format for the ‘geo’ type so that live loader can correctly read it?

It is simple. In the predicate with the Geo Type. You should stringify(Escaping method) the geoJson. As far as I remember. It is true that we don’t have any example and also it is rare some user using JSON in that particular case.

It would be something like this

[{
   "Building.id":"100085724R",
   "Building.location": "{\"type\": \"Point\", \"coordinates\":[22.747430860292567,60.061069293715555]}"
}]

Ah okay, thanks… how would users normally bulk load geo data then? RDFs? What is the correct format for geos in RDF imports, is it also stringified json?

Something like this

`<%d> <%s> "{'type':'Point', 'coordinates':[%v, %v]}"^^<geo:geojson> .`

Or

_:a <loc> "{'type':'Point','coordinates':[-122.4220186,37.772318]}"^^<geo:geojson> .