Naming rules - Dgraph vs GraphQL

Using this simple schema:

type Person {
  id: ID!
  first-name: String
}

I get this cryptic error message:

$curl -X POST localhost:8080/admin/schema -d '@test-person.graphql'
{"errors":[{"message":"couldn't rewrite mutation updateGQLSchema because input:1: Expected :, found \u003cInvalid\u003e\n","extensions":{"code":"Error"}}]}%

But with this one:

type Person {
  id: ID!
  first_name: String
}

there is no issue:

$curl -X POST localhost:8080/admin/schema -d '@test-person.graphql'
{"data":{"code":"Success","message":"Done"}}%

The difference between the two is a hyphen vs an underscore:
first-name vs first_name

Looked into Dgraph documentation and in Predicate name rules it says the allowed special characters are: ][&*()_-+=!#$% . So both hyphen and underscore and several other special characters are allowed.

GraphQL spec however is far more restrictive and allows only: [_A-Za-z][_0-9A-Za-z] . The only special character allowed here is an underscore.

Did I miss anything here in terms of the cause of the error?

The Predicate name rules doc you linked is for Dgraph’s GraphQL+- schema, which is more flexible. For GraphQL, the schema must adhere to the spec’s naming rules. So, hyphens aren’t allowed.


@pawan Can there be a better error message? input:1: Expected :, found \u003cInvalid\u003e\n is definitely cryptic.

1 Like

Thanks for confirming @dmai! I hope the error messages can be improved.

So what happens if you already have a DQL schema that has some of these allowed special characters - are those predicates, and therefore the data, not accessible via GraphQL anymore?

You can map GraphQL fields to Dgraph fields using @dgraph directives, as explained here https://dgraph.io/docs/graphql/dgraph

2 Likes

@RJKeevil I tried the @dgraph directives, and only the hyphen seems to work. Many of the other special characters throw an error (I didn’t try all …). Seems like at this point it is better to stick to the GraphQL allowed characters to maintain compatibility.

Sure, we’ll look into providing a better error message.