thinky
thinky copied to clipboard
Exportable schema
This is an initial pass at exportable schema (see #234). I fully expect that this will not cover all edge cases, but I just wanted to get something up to start the discussion / iterate from. @neumino - does this seem like a good approach? Anything you'd like to see changed?
I'd personally also like to see the ability to export relationships (I'm fine if that's independent of exporting schema), but I'll address that in a separate PR most likely.
Apologies for the messy diff - I thought I skipped those hunks when adding, but I guess not.
On that thought - @neumino, would you be open to a PR that cleans up the code a bit? I.e. trims whitespace, adds missing semicolons, etc?
Hello @davewasmer
I actually don't remember what the use case for exporting schema was. Why do you need to be able to export a schema?
Your PR currently seems to export a human readable schema, but doesn't export more properties like the maximum length, if the field is required or not etc.
So you probably need export basically the whole object in each type/<type>,js
My use case is primarily around reflection. I'm trying to serialize a Thinky model into different JSON formats, without hardcoding per-model serializers. So having the ability to export the schema provides me a way to inspect the model's schema at runtime and dynamically serialize it. If there is a better approach here that I'm missing, let me know :smile:
Right now, yes, the export is human-readable. Like I mentioned, this is just a proof of concept, it should be easy to modify the .export() functions to export whatever we'd like. I just wanted to get your take on the concept first.
The basic implementation seems reasonable to me. Instead of just exporting the type, we should export the whole Type object (with all its attributes + its type).
There's also a need to import the schema after that :)
One more use case would be to assist building GraphQL schema.
Any chance to see that PR merged ?
This PR is kind of incomplete. I'll comment more on the issue.
+1 - this is also super important for us
@contra -- what is it for?
@neumino Generating redux api actions on the front-end + form validation etc.
How does this deal with relationships? It would be super helpful if those were also part of the export