-
Notifications
You must be signed in to change notification settings - Fork 20
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
spring support for graphQl schema generator #33
Open
PeretzNadav
wants to merge
6
commits into
Distelli:master
Choose a base branch
from
PeretzNadav:spring-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
524825d
spring support for graphQl schema generator
PeretzNadav edb9292
spring support for graphQl schema generator
PeretzNadav a4bffdc
spring support for graphQl schema generator
PeretzNadav c1e6cb2
- add enum support (spring style - taken from other pull request)
PeretzNadav ae35416
- fix bug when replaceResolved invoked
PeretzNadav 6356410
implement default value string int
PeretzNadav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ public class ApiGen { | |
private Path outputDirectory; | ||
private STGroup stGroup; | ||
private String guiceModuleName; | ||
private String springModuleName; | ||
private String defaultPackageName; | ||
private Map<String, TypeEntry> generatedTypes = new LinkedHashMap<>(); | ||
private Map<String, TypeEntry> referenceTypes = new HashMap<>(); | ||
|
@@ -36,6 +37,7 @@ public static class Builder { | |
private Path outputDirectory; | ||
private STGroup stGroup; | ||
private String guiceModuleName; | ||
private String springModuleName; | ||
private String defaultPackageName; | ||
|
||
/** | ||
|
@@ -67,6 +69,11 @@ public Builder withGuiceModuleName(String guiceModuleName) { | |
return this; | ||
} | ||
|
||
public Builder withSpringModuleName(String springModuleName) { | ||
this.springModuleName = springModuleName; | ||
return this; | ||
} | ||
|
||
public Builder withDefaultPackageName(String defaultPackageName) { | ||
this.defaultPackageName = defaultPackageName; | ||
return this; | ||
|
@@ -89,6 +96,8 @@ private ApiGen(Builder builder) throws IOException { | |
throw new NullPointerException("The ApiGen outputDirectory must be specified"); | ||
} | ||
guiceModuleName = builder.guiceModuleName; | ||
springModuleName = builder.springModuleName; | ||
|
||
defaultPackageName = builder.defaultPackageName; | ||
outputDirectory = builder.outputDirectory; | ||
stGroup = ( null == builder.stGroup ) | ||
|
@@ -200,7 +209,7 @@ public void generate() throws IOException { | |
String content = stGroup.getInstanceOf(generatorName+"Generator") | ||
.add("model", model) | ||
.render(); | ||
if ( stGroup.isDefined(generatorName + "GuiceModule") ) { | ||
if ( guiceModuleName != null && stGroup.isDefined(generatorName + "GuiceModule") ) { | ||
moduleBuilder.append(stGroup.getInstanceOf(generatorName+"GuiceModule") | ||
.add("model", model) | ||
.render()); | ||
|
@@ -216,13 +225,42 @@ public void generate() throws IOException { | |
if ( moduleBuilder.length() > 0 && guiceModuleName != null && stGroup.isDefined("guiceModule") ) { | ||
PackageClassName packageClassName = getPackageClassName(guiceModuleName); | ||
String content = stGroup.getInstanceOf("guiceModule") | ||
.add("packageName", packageClassName.packageName) | ||
.add("className", packageClassName.className) | ||
.add("configure", moduleBuilder.toString()) | ||
.render(); | ||
.add("packageName", packageClassName.packageName) | ||
.add("className", packageClassName.className) | ||
.add("configure", moduleBuilder.toString()) | ||
.render(); | ||
writeFile(Paths.get(getDirectory(packageClassName.packageName).toString(), | ||
packageClassName.className+".java"), | ||
content); | ||
} else if (springModuleName != null && stGroup.isDefined("springModule") ) { | ||
PackageClassName packageClassName = getPackageClassName(springModuleName); | ||
final String body = " /*\n" + | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we simply put this in the string template file? |
||
" Please insert to your graphQL server class:\n" + | ||
"\n" + | ||
" @Autowired\n" + | ||
" List<Provider<? extends GraphQLType>> graphQLTypes;\n" + | ||
"\n" + | ||
" @Autowired\n" + | ||
" BeanFactory beanFactory;\n" + | ||
" Map<String, GraphQLType> graphqlTypeMap;\n" + | ||
"\n" + | ||
" @PostConstruct\n" + | ||
" public void initGraphQLServer(){\n" + | ||
" graphqlTypeMap = (Map<String, GraphQLType>)beanFactory.getBean(\"graphqlTypeMap\", graphQLTypes);\n" + | ||
" }\n" + | ||
"\n" + | ||
" Note: GraphQLServer class is not been generated because there is no one implementation for that class,\n" + | ||
" the comments above are required in-order to generate schema files\n" + | ||
" */"; | ||
|
||
String content = stGroup.getInstanceOf("springModule") | ||
.add("packageName", packageClassName.packageName) | ||
.add("className", packageClassName.className) | ||
.add("body",body) | ||
.render(); | ||
writeFile(Paths.get(getDirectory(packageClassName.packageName).toString(), | ||
packageClassName.className+".java"), | ||
content); | ||
packageClassName.className+".java"), | ||
content); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,7 @@ | ||
package com.distelli.graphql.apigen; | ||
|
||
import graphql.language.Definition; | ||
import graphql.language.EnumTypeDefinition; | ||
import graphql.language.EnumValueDefinition; | ||
import graphql.language.FieldDefinition; | ||
import graphql.language.InputObjectTypeDefinition; | ||
import graphql.language.InputValueDefinition; | ||
import graphql.language.InterfaceTypeDefinition; | ||
import graphql.language.ListType; | ||
import graphql.language.NonNullType; | ||
import graphql.language.ObjectTypeDefinition; | ||
import graphql.language.OperationTypeDefinition; | ||
import graphql.language.ScalarTypeDefinition; | ||
import graphql.language.SchemaDefinition; | ||
import graphql.language.Type; | ||
import graphql.language.TypeName; | ||
import graphql.language.UnionTypeDefinition; | ||
import graphql.language.Value; | ||
import graphql.language.*; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps your editor did this, but I'd prefer to avoid star imports :). |
||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
|
@@ -76,7 +61,7 @@ public static class Arg { | |
public String name; | ||
public String type; | ||
public String graphQLType; | ||
public String defaultValue; | ||
public Object defaultValue; | ||
public Arg(String name, String type) { | ||
this.name = name; | ||
this.type = type; | ||
|
@@ -90,9 +75,10 @@ public static class Field { | |
public String name; | ||
public String type; | ||
public DataResolver dataResolver; | ||
public boolean isStringValue; | ||
public String graphQLType; | ||
public List<Arg> args; | ||
public String defaultValue; | ||
public Object defaultValue; | ||
public Field(String name, String type) { | ||
this.name = name; | ||
this.type = type; | ||
|
@@ -289,6 +275,11 @@ private List<Field> getFields(InputObjectTypeDefinition def) { | |
Field field = new Field(fieldDef.getName(), toJavaTypeName(fieldDef.getType())); | ||
field.graphQLType = toGraphQLType(fieldDef.getType()); | ||
field.defaultValue = toJavaValue(fieldDef.getDefaultValue()); | ||
if(field.defaultValue != null && field.defaultValue instanceof String ) { | ||
field.isStringValue = true; | ||
}else { | ||
field.isStringValue = false; | ||
} | ||
fields.add(field); | ||
} | ||
return fields; | ||
|
@@ -329,7 +320,12 @@ private List<Arg> toArgs(List<InputValueDefinition> defs) { | |
return result; | ||
} | ||
|
||
private String toJavaValue(Value value) { | ||
private Object toJavaValue(Value value) { | ||
if(value instanceof StringValue){ | ||
return ((StringValue) value).getValue(); | ||
}else if(value instanceof IntValue){ | ||
return ((IntValue) value).getValue(); | ||
} | ||
// TODO: Implement me! | ||
return null; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the
groupId
get inherited from the parent?