Hey there,
not sure if this is the right category but I’ll give it a shot.
I’m currently using Dgraph solely via a GraphQL Schema, meaning that I have a schema.graphl
file which looks something like this:
type Person {
id: ID!
slug: String! @id
firstName: String!
lastName: String!
posts: [Post] @hasInverse(field: author)
}
type Post {
id: ID!
slug: String! @id
author: Person
}
# ... Other type definitions
Spinning up Dgraph and mutating / querying via the GraphQL endpoint works flawlessly.
However given that I have a lot more data to ingest, inserting it via GraphQL mutations isn’t feasible. Live Loader seems to be the correct option here. In particular I need to rely on the --upsertPredicate
option to ensure that re-runs won’t overwrite the already present data in the future.
I followed the docs in https://dgraph.io/docs/deploy/fast-data-loading/live-loader/ but I just can’t make the connection between the upserPredicate
example and the GraphQL Schema I wrote.
After fiddling around a little bit I came up with this data.rdf
file:
<jdoe> <Blockchain.slug> "jdoe" .
<jdoe> <Blockchain.firstName> "John" .
<jdoe> <Blockchain.lastName> "Doe" .
<jdoe> <dgraph.type> "Person" .
I can now run this script via the following Live Loader command: dgraph live --files data.rdf --upsertPredicate "Person.slug"
It will only ever create one node given that the slug
is used as the --upsertPredicate
.
Now the downside is that this only works because I prefixed slug
with Person
(Person.slug
) which means that there’s no way to have a single .rdf
file with multiple different types in it while still using the --upsertPredicate
flag that way.
Can someone please explain how Live Loader should be used with an existing GraphQL Schema and the --upsertPredicate
flag (a full example with edges between nodes would be super helpful!)?
Is using the slug
fine or should I add xid
to the GraphQL types? Is xid
just a convention one should follow to provide own ids or is it relied upon by Dgraph internally?
And what’s the difference between:
<foobar>
<_:foobar>
_:foobar
Thanks a lot for working on Dgraph and taking the time to answer this question!