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?
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.
We have defined a custom parser for the :ID
scalar that enforces our ‘format’ for node ids
It throws a coercion failure if its expectations are not met
(Oh, I am assuming lacinia here, you were not so specific)
Yep, I'm using Lacinia.
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 🙂
Does that help 🙂?
That makes sense! That was the direction I was headed.
Thanks for the quick reply!
Take a look at the object identification relay spec, if you haven’t already encountered that 🙂
Bit seperate tho, but is good to consider when designing the ‘internal’ structure of your ids
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: https://stackoverflow.com/questions/64288464/parsing-graphql-schema-fails-unexpectedly
StackOverflow to the rescue! Got a fix working.
Just throwing stuff at the wall here: Your grammar specifies that directive arguments may have directives, is that something that could be problematic?
Hmm, nevermind
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
There are IDE integrations for ANTLR btw, maybe those can shed some light on how antlr is attempting to parse the SDL