What I want to do next is create an upsert for all three of these UIDs in a way that will create the product node and option node (so the product is a child of products, and the option is a child of the product) if missing. For example, I want to do something like this:
Is there a way to do this?
I’m using the Java Client, but any upsert solution will suffice.
A requirement for the upsert is that if a product doesn’t exist, it must create a new one under the existing products collection. Similarly, if an option doesn’t exist, it must create a new one under the existing product. If neither the product nor the option exist, then it must create them both.
I am not sure I understand all the details, but your above upsert [1] will probably look like as follows in GraphQL±. There could be minor differences due to how your data model is, so check once. You can also add conditions using Conditional Upsert [2].
I (@micheldiz) marked Aman’s answer as the correct one because it is in fact what corresponds to the requested. However, if you (future reader) want to continue reading below. Please note that other topics are covered below and this here is the right answer. The conversation below is more about troubleshooting than about the title.
Awesome. Thanks! Is the 2.0.2 client backward compatible with Dgraph (Zero, Alpha, and Ratel) or is it only compatible with Dgraph after a particular version?
We updated the client version, and we’re attempting to execute a mutation to setup our local dgraph database for our integration tests, and we’re getting StatusRuntimeExecution: UNKNOWN: Empty query
[main] ERROR updates.ImInStockStatusReaderWriterTest - Showing stack trace: java.lang.RuntimeException: java.util.concurrent.CompletionException: java.lang.RuntimeException: The doRequest encountered an execution exception:
at io.dgraph.AsyncTransaction.lambda$doRequest$2(AsyncTransaction.java:173)
at java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:822)
at java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:797)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1595)
at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java)
at java.util.concurrent.CompletableFuture$AsyncSupply.exec(CompletableFuture.java:1582)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: java.util.concurrent.CompletionException: java.lang.RuntimeException: The doRequest encountered an execution exception:
at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273)
at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280)
at java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1592)
... 6 more
Caused by: java.lang.RuntimeException: The doRequest encountered an execution exception:
at io.dgraph.DgraphAsyncClient.lambda$runWithRetries$2(DgraphAsyncClient.java:212)
at java.util.concurrent.CompletableFuture$AsyncSupply.run$$$capture(CompletableFuture.java:1590)
... 6 more
Caused by: java.util.concurrent.ExecutionException: io.grpc.StatusRuntimeException: UNKNOWN: Empty query
at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1895)
at io.dgraph.DgraphAsyncClient.lambda$runWithRetries$2(DgraphAsyncClient.java:180)
... 7 more
Caused by: io.grpc.StatusRuntimeException: UNKNOWN: Empty query
at io.grpc.Status.asRuntimeException(Status.java:533)
at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:442)
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at io.grpc.internal.CensusStatsModule$StatsClientInterceptor$1$1.onClose(CensusStatsModule.java:700)
at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39)
at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23)
at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40)
at io.grpc.internal.CensusTracingModule$TracingClientInterceptor$1$1.onClose(CensusTracingModule.java:399)
at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:507)
at io.grpc.internal.ClientCallImpl.access$300(ClientCallImpl.java:66)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:627)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:515)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:686)
at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:675)
at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37)
at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:123)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
I hadn’t updated the docker container, so updating the docker container to v1.1.0 seemed to get me farther.
However, when I try to run the mutate now, my mutation doesn’t seem to be reaching Dgraph. I know my hostname and port are set correctly because I’m able to run alter to set the schema. I get UIDs back from the mutate, but there’s no evidence that the mutation actually ran in Dgraph. The alpha and zero logs don’t show anything about the mutation, and the data doesn’t show up when I query it in Ratel. I’ve triple checked that the hostname and port are configured correctly in my test method and in Ratel.
Any ideas?
This is not true. has() function is not related to type system. You’d need to specify the predicates you want to return in the response. Or, if you use the type system, then you can use expand(_all_) to fetch the predicates defined in the type.
However, we relied a lot on using _predicate_, and I’m not sure that I understand how to use expand(_all_). I tried:
{
data(func: has(products)) {
expand(_all_)
}
}
but I get no data back. Am I missing something?
For what it’s worth, I also tried querying based on the type, like this:
{
data(func: type(string)) {
expand(_all_)
}
}
but I got no data back that time either.
Regarding the type system, what exactly does that mean? Am I required to provide type information as well when I create the schema? If so, how do we do that? I’m not finding any examples on the website or in the docs for the Go or Java clients.