Newline-escape-hell when posting a new schema

What I want to do

POST a new schema to /admin/schema. Everything works if i just include the schema itself, but when i add the # Dgraph.Authorization line, specifically the RSA key for JWT verification, everything breaks.

What I did

As per the docs, newlines in the key have to be written as \n. I tried sending this via nodejs at first (didn’t work because javascript handles newlines differently). Then i changed these newlines to \\n. That didnt work either because the server now complains about the invalid format \\n. Then i tried using curl with the --data-binary flag. I get the same error as when using \\n to escape newlines.

Dgraph metadata

dgraph version Dgraph version : v23.0.0 Dgraph codename : dgraph Dgraph SHA-256 : aafa0fe5a65059eec94703e2ed6d5c88a80317e9ee7e8c3776a6abf60ae78fc4 Commit SHA-1 : 38980bc Commit timestamp : 2023-05-08 14:56:12 -0700 Branch : HEAD Go version : go1.19.8 jemalloc enabled : true

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

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

Code

tmp-schema.gql

type User {
    ...
}

# Dgraph.Authorization {"VerificationKey": "-----BEGIN PUBLIC KEY-----\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAseb/pbPMpVwwh/brG53X\nLX7iQPZsde0dJI05/9KQOIsnXbZXZviMMPjGtquSC5<not posting the entire key for obvious reasons>Jw99AMsCAwEAAQ==\n-----END PUBLIC KEY-----", "Header": "Authorization", "Namespace": "http://dgraphurl:8080/jwt/claims" "Algo": "RS256"}

terminal input

curl -X POST http://dgraphurl:8080/admin/schema -H "X-Dgraph-AuthToken: <...>" --data-binary '@tmp-schema.gql'

based on:

the response

{"errors":[{"message":"resolving updateGQLSchema failed because input: Invalid `Dgraph.Authorization` format: # Dgraph.Authorization {\"VerificationKey\": \"-----BEGIN PUBLIC KEY-----\\nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgK<...>tJe18zkouB\\nIUk17RiUnZ6FzIGPJw99AMsCAwEAAQ==\\n-----END PUBLIC KEY-----\", \"Header\": \"Authorization\", \"Namespace\": \"http://dgraph-dev.fileplay.me:8080/jwt/claims\" \"Algo\": \"RS256\"} (Locations: [{Line: 3, Column: 4}])","extensions":{"code":"Error"}}]}

You know how it’s often just really simple errors that make you search the internet for a solution for hours? Turns out this is what happened: I forgot a single comma at the end of the Dgraph.Authorization line. For everyone who came across this I suggest double- and triple‑checking your code for typing errors.