Fork me on GitHub

Do any folks here have some tips on the best location to handle GraphQLs expectations of ID types and the ways they may differ from Integer-type expectations from relational databases for example?

Lennart Buit20:10:43

We have defined a custom parser for the :ID scalar that enforces our ‘format’ for node ids

Lennart Buit20:10:01

It throws a coercion failure if its expectations are not met

Lennart Buit20:10:24

(Oh, I am assuming lacinia here, you were not so specific)


Yep, I'm using Lacinia.

Lennart Buit20:10:28

Yeah, so we just defined {`{:scalars {:ID {:parse :parse/id :serialize :serialize/id}}}` in our schema, and the rest of our application only deals with parsed ids 🙂

Lennart Buit20:10:59

Does that help 🙂?


That makes sense! That was the direction I was headed.


Thanks for the quick reply!

Lennart Buit20:10:18

Take a look at the object identification relay spec, if you haven’t already encountered that 🙂

Lennart Buit20:10:10

Bit seperate tho, but is good to consider when designing the ‘internal’ structure of your ids


The longer form is that my database tables use integers for their IDs, but GraphQL certainly wants its ID types to be serialized as Strings.


If you want to use GraphQL’s ID type. The reasoning is that database ids are often 64 bit integers, which are wider than what JSON supports for numbers, so a (implicitly numeric) string is a lossless representation.


Or, you could use a UUID type (you’d have to define that as a scalar, but that’s not too hard).


I’m pretty sure Postgres has a UUID type suitable for a primary key, and can generate that UUID on insert using a database function. I’m a bit rusty on the Postgres front, however.


It’s good to eat your own dog-food. I’ve discovered that in directive arguments (and perhaps field arguments) the SDL parser can’t parse a default value that’s boolean. Very strange.


true/false/null seem to be the problem


Anyone know Anltr4 better than me? Here’s the problem I’m stuck on:


StackOverflow to the rescue! Got a fix working.

Lennart Buit23:10:57

Just throwing stuff at the wall here: Your grammar specifies that directive arguments may have directives, is that something that could be problematic?

Lennart Buit23:10:12

Hmm, nevermind

Lennart Buit23:10:44

Anyhow, since you are saying its true, false and null that are issues. I’m expecting ANTLR to somehow interpret those not as keywords, but as a name

Lennart Buit23:10:12

There are IDE integrations for ANTLR btw, maybe those can shed some light on how antlr is attempting to parse the SDL