kensho-technologies/graphql-compiler

Implement __typename meta field for SQL backend

Opened this issue · 2 comments

I believe that uses of the __typename meta field are not supported by the SQL backend at the moment, so I'm opening a tracking issue for that.

Here's an approach that I believe would work at least for Postgres 9 and newer:

SELECT pg_class.relname, cities.name
FROM cities
INNER JOIN pg_class ON cities.tableoid = pg_class.oid;

https://www.db-fiddle.com/f/8qNJmxuD8oRhBVZUVLfLZF/0

Docs:
https://www.postgresql.org/docs/current/ddl-inherit.html

I think you sent the wrong db-fiddle link

Also we might want output post-processing to convert the table names we'll get with this method to vertex names that exist in the GraphQL schema.

Also it would make sense to implement this after we have SQL inheritance, otherwise the __typename is known at compile time.

Fixed the link, nice catch. Agreed on the other two points, I just randomly came across this feature in the Postgres docs and wanted to write it down before I forgot about it :)