You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I haven't fully tested this. But the AST I've needed to print has printed correctly. Thought maybe to contribute. Are there other plans for a printer?
Regarding the implementation/style, the way it is now, it could use some double dispatch with Node. But the big switch works. Also, I considered/attempted/aborted writing a reducing visitor as in LB's JS implementation, but the approach I took was just much simpler for me.
Reacted by Yurii Rashkovskii, Bojan Tomić, Arnold Schrijver and Dean Chapman
I think this would be a very valuable addition as it helps figuring out what went wrong with the design of the schema much faster than reading a JSON representation of the introspection query result.
@danielkwinsor this printer is for printing GraphQL AST Java Objects (graphql.language) into a GraphQL string. The use case for me is to manipulate input GraphQL AST and then print it back out into GraphQL string as a request to an upstream service.
@yrashk this is actually not a schema printer. This is an AST node printer. A schema printer is needed, too though, for the purpose you mention. Should also be pretty simple, but with tests.
@dminkovsky Your gist would be best. The ObjectMapper approach would be opinionated, leading to a Jackson dependency, just one of the popular Json parsers around.
While I am using Jackson myself in most of my projects, you would probably be forcing this on, say 50 to 60% (just guessing) of developers using other json libraries.
(Only problem is its Java 8, now turn the rest into 8 as well 😉)
I'm still confused regarding the mentions of JSON and specifically Jackson here. This printer produces GraphQL Documents from AST nodes. Is JSON relevant to this?
I just reacted on @danielkwinsor code snippet which used Jackson ObjectMapper. Json has not much to do with it except Jackson started originally as a json library (can now handle many formats)
Activity
yrashk commentedon May 6, 2016
I think this would be a very valuable addition as it helps figuring out what went wrong with the design of the schema much faster than reading a JSON representation of the introspection query result.
danielkwinsor commentedon May 21, 2016
For printing, I set a jackson mapper to indent and let it do the work on the json introspection:
Looks like
How is the output of your printer different from the json introspection result? Can you show an example output?
dminkovsky commentedon May 21, 2016
@danielkwinsor this printer is for printing GraphQL AST Java Objects (graphql.language) into a GraphQL string. The use case for me is to manipulate input GraphQL AST and then print it back out into GraphQL string as a request to an upstream service.
dminkovsky commentedon Aug 17, 2016
@yrashk this is actually not a schema printer. This is an AST node printer. A schema printer is needed, too though, for the purpose you mention. Should also be pretty simple, but with tests.
dminkovsky commentedon Aug 17, 2016
Closing this for now. Can revisit with pull request.
dminkovsky commentedon Aug 17, 2016
Re-opening because we definitely want a printer. Just want it to be tested and on a PR.
aschrijver commentedon Aug 17, 2016
@dminkovsky Your gist would be best. The
ObjectMapperapproach would be opinionated, leading to a Jackson dependency, just one of the popular Json parsers around.While I am using Jackson myself in most of my projects, you would probably be forcing this on, say 50 to 60% (just guessing) of developers using other json libraries.
(Only problem is its Java 8, now turn the rest into 8 as well 😉)
andimarek commentedon Aug 18, 2016
A direct jackson dependency is not an option, imho: We should add only dependencies we really need or want.
dminkovsky commentedon Aug 18, 2016
I'm still confused regarding the mentions of JSON and specifically Jackson here. This printer produces GraphQL Documents from AST nodes. Is JSON relevant to this?
aschrijver commentedon Aug 18, 2016
I just reacted on @danielkwinsor code snippet which used Jackson
ObjectMapper. Json has not much to do with it except Jackson started originally as a json library (can now handle many formats)zhbrass commentedon Sep 14, 2016
I modified the gist by @dminkovsky to use pre-Java 8 features. Feel free to use.
https://gist.github.com/zhbrass/1fd7fbabad852a323740682065708b1b
bbakerman commentedon Apr 21, 2017
The PR here now adds a pretty printer for reverse decompiling a schema
#386
dminkovsky commentedon Apr 24, 2017
Makes sense to close this then!
RusticFlare commentedon Sep 14, 2017
(Because I still had to go looking for this)
You can print by using the
SchemaPrinterclass.