graphql

2020-10-09T20:13:20.016500Z

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?

2020-10-09T20:14:09.017200Z

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.

2020-10-09T20:14:43.017900Z

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

2020-10-09T20:15:01.018100Z

It throws a coercion failure if its expectations are not met

2020-10-09T20:15:24.018300Z

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

2020-10-09T20:15:30.018500Z

Yep, I'm using Lacinia.

2020-10-09T20:16:28.018700Z

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 🙂

2020-10-09T20:17:59.019Z

Does that help 🙂?

2020-10-09T20:18:09.019200Z

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

2020-10-09T20:18:48.019400Z

Thanks for the quick reply!

2020-10-09T20:19:18.019600Z

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

2020-10-09T20:21:10.019800Z

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

hlship 2020-10-09T21:07:41.020100Z

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.

hlship 2020-10-09T21:08:21.020300Z

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

hlship 2020-10-09T21:09:05.020500Z

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.

hlship 2020-10-09T21:21:26.021700Z

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.

hlship 2020-10-09T21:24:06.022Z

true/false/null seem to be the problem

hlship 2020-10-09T23:29:23.022700Z

Anyone know Anltr4 better than me? Here’s the problem I’m stuck on: https://stackoverflow.com/questions/64288464/parsing-graphql-schema-fails-unexpectedly

hlship 2020-10-12T16:41:51.026800Z

StackOverflow to the rescue! Got a fix working.

2020-10-09T23:34:57.023500Z

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

2020-10-09T23:37:12.023600Z

Hmm, nevermind

2020-10-09T23:38:44.023800Z

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

2020-10-09T23:44:12.024200Z

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