@@ -35,21 +35,7 @@ import com.squareup.javapoet.JavaFile
35
35
import com.squareup.javapoet.TypeSpec
36
36
import com.squareup.kotlinpoet.FileSpec
37
37
import com.squareup.kotlinpoet.KModifier
38
- import graphql.language.Definition
39
- import graphql.language.DirectivesContainer
40
- import graphql.language.Document
41
- import graphql.language.EnumTypeDefinition
42
- import graphql.language.FieldDefinition
43
- import graphql.language.InputObjectTypeDefinition
44
- import graphql.language.InterfaceTypeDefinition
45
- import graphql.language.NamedNode
46
- import graphql.language.ObjectTypeDefinition
47
- import graphql.language.ObjectTypeExtensionDefinition
48
- import graphql.language.ScalarTypeDefinition
49
- import graphql.language.Type
50
- import graphql.language.TypeDefinition
51
- import graphql.language.TypeName
52
- import graphql.language.UnionTypeDefinition
38
+ import graphql.language.*
53
39
import graphql.parser.InvalidSyntaxException
54
40
import graphql.parser.MultiSourceReader
55
41
import graphql.parser.Parser
@@ -63,6 +49,8 @@ import java.io.Reader
63
49
import java.lang.annotation.RetentionPolicy
64
50
import java.nio.file.Path
65
51
import java.nio.file.Paths
52
+ import java.util.*
53
+ import java.util.jar.JarFile
66
54
import java.util.zip.ZipFile
67
55
import javax.lang.model.element.Modifier
68
56
import com.squareup.kotlinpoet.AnnotationSpec as KAnnotationSpec
@@ -83,6 +71,8 @@ class CodeGen(private val config: CodeGenConfig) {
83
71
)
84
72
85
73
fun generate (): CodeGenResult {
74
+ loadTypeMappingsFromDependencies()
75
+
86
76
val codeGenResult = when (config.language) {
87
77
Language .JAVA -> generateJava()
88
78
Language .KOTLIN -> generateKotlin()
@@ -156,9 +146,30 @@ class CodeGen(private val config: CodeGenConfig) {
156
146
}
157
147
}
158
148
}
149
+
159
150
return document
160
151
}
161
152
153
+ private fun loadTypeMappingsFromDependencies () {
154
+ // process type mappings from dependencies
155
+ config.schemaJarFilesFromDependencies.forEach { file ->
156
+ JarFile (file).use { jarFile ->
157
+ val typeMappingsFile = jarFile.getJarEntry(" META-INF/dgs.codegen.typemappings" )
158
+ if (typeMappingsFile != null ) {
159
+ jarFile.getInputStream(typeMappingsFile).use { typeMappingInput ->
160
+ val props = Properties ()
161
+ props.load(typeMappingInput)
162
+
163
+ // Add the new type mappings from dependencies to existing type mappings.
164
+ // The user provided config overrides mappings from the dependencies.
165
+ @Suppress(" UNCHECKED_CAST" )
166
+ config.typeMapping = (props as Map <String , String >).plus(config.typeMapping)
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+
162
173
/* *
163
174
* Loads the given [MultiSourceReader.Builder] references with the sources that will be used to provide
164
175
* the schema information for the parser.
0 commit comments