Upsert with multiple UIDs

Regarding:

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());
            }

This is just a compact way to replace the placeholders (e.g. $productID and $optionID) with actual values.
The loop is actually replacing the string for each value.
It’s equivalent to replacing the string with itself after substituting $productID for an actual value and then repeating for $optionID.
In Go, it would be equivalent to this:
myText = strings.Replace(myText, "$productID", "28734602", -1)
myText = strings.Replace(myText, "$optionID", "327865", -1)

Since I’m replacing the variables with specific values in the string before executing the query, I don’t think I’m using GraphQL variables because the $ character won’t actually appear in the string when it’s submitted to Dgraph.

With this in mind, the code would look like this at runtime:

String query =      "    {\n" +
                    "        var(func: has(products)){\n" +
                    "            productsUid as uid\n" +
                    "            productNode as products @filter(eq(productId, \"28734602\")){\n" +
                    "                optionNode as options @filter(eq(optionId, \"327865\")){\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" +
                    "        }";

            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();