Upsert with multiple UIDs

At this point, I’m able to validate that I can see the data in Dgraph. So, back to the upsert, I’m getting an exception when I attempt to run the upsert.

It says:

Caused by: io.grpc.StatusRuntimeException: UNKNOWN: while parsing query: "query {\n    {\n        var(func: has(products)){\n            productsUid as uid\n            productNode as products @filter(eq(productId, 19610626)){\n                optionNode as options @filter(eq(optionId, 32661491)){\n                uid\n                }\n            }\n        }\n        getVals(func: uid(productsUid)) @normalize {\n            productsUid : uid\n                products @filter(uid(productNode)){\n                    productUid : uid\n                    options @filter(uid(optionNode)){\n                        optionUid : uid\n                    }\n                }\n            }\n        }\n  }": line 2 column 4: Expected some name. Got: lex.Item [6] "{" at 2:4

Here’s how I’m building the upsert:

String query = "query {\n" +
                    "    {\n" +
                    "        var(func: has(products)){\n" +
                    "            productsUid as uid\n" +
                    "            productNode as products @filter(eq(productId, $productID)){\n" +
                    "                optionNode as options @filter(eq(optionId, $optionID)){\n" +
                    "                uid\n" +
                    "                }\n" +
                    "            }\n" +
                    "        }\n" +
                    "        getVals(func: uid(productsUid)) @normalize {\n" +
                    "            productsUid : uid\n" +
                    "                products @filter(uid(productNode)){\n" +
                    "                    productUid : uid\n" +
                    "                    options @filter(uid(optionNode)){\n" +
                    "                        optionUid : uid\n" +
                    "                    }\n" +
                    "                }\n" +
                    "            }\n" +
                    "        }\n" +
                    "  }";

            Map<String, String> map = new HashMap<String, String>();
            map.put("$productID", inputMessage.getProductId().toString());
            map.put("$optionID", inputMessage.getOptionId().toString());

            for (Map.Entry<String, String> entry : map.entrySet()) {
                query = query.replace(entry.getKey(), entry.getValue());
            }

            DgraphProto.Mutation mu =
                    DgraphProto.Mutation.newBuilder()
                            .setSetNquads(ByteString.copyFromUtf8("uid(productsUid) <products> uid(productUid) ."))
                            .setSetNquads(ByteString.copyFromUtf8("uid(productsUid) <dgraph.type> \"Products\" ."))
                            .setSetNquads(ByteString.copyFromUtf8("uid(productUid) <productId> \"" + inputMessage.getProductId().toString() + "\" ."))
                            .setSetNquads(ByteString.copyFromUtf8("uid(productUid) <options> uid(optionUid) ."))
                            .setSetNquads(ByteString.copyFromUtf8("uid(productUid) <dgraph.type> \"Product\" ."))
                            .setSetNquads(ByteString.copyFromUtf8("uid(optionUid) <dgraph.type> \"Option\" ."))
                            .setSetNquads(ByteString.copyFromUtf8("uid(optionUid) <color> \"" + inputMessage.getColor().toString() + "\" ."))
                            .setSetNquads(ByteString.copyFromUtf8("uid(optionUid) <optionId> \"" + inputMessage.getOptionId().toString() + "\" ."))
                            .build();

Is there an obvious syntax error that I’m just not seeing?