Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom model addapters #34

Open
kito99 opened this issue Apr 8, 2019 · 4 comments
Open

Add support for custom model addapters #34

kito99 opened this issue Apr 8, 2019 · 4 comments

Comments

@kito99
Copy link
Contributor

kito99 commented Apr 8, 2019

I'm customizing the template in order to change how the Java code is generated. However, there are a couple of things I'd like to do that can't be done without modifying STDModel.java (which I would like to avoid doing). I noticed that one way around this is to use StringTemplate model adaptor (https://github.com/antlr/stringtemplate4/blob/master/doc/adaptors.md). It'd be great if this project had support for adding custom model generators; it would make it quite extensible.

@brimworks
Copy link
Contributor

I'm not following on how model adaptors would be useful. Do you have some example code?

@kito99
Copy link
Contributor Author

kito99 commented Apr 8, 2019

I don't have example code, but the scenario is pretty simple. I'm just trying to determine if a particular type is a Query. I don't see that information in the GraphQL model for the AST, but I could do something silly like check the name of the type or look for a special comment. However, since StringTemplate doesn't allow arbitrary expressions, the only option is to call a method on STDModel that returns a boolean value. Rather than modifying the class directly, if I could register a model adapter, I could add a new boolean value like isQuery that I could use in the template.

@brimworks
Copy link
Contributor

Ah, I think I understand... do you want to add an isQuery() method to the STModel? We always appreciate pull requests :).

@kito99
Copy link
Contributor Author

kito99 commented Apr 9, 2019

Well, adding the model adapter would allow extending the model in ways that aren't generally useful to other teams. In this case, though, is there any way to tell if a type is a query other than looking at the name or a comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants