Skip to content

Commit 9339433

Browse files
committed
Ensured scalar SDL printing includes all scalars, fixed enum and union definition builders (was using getters to add to new lists that were ignored) (#164)
1 parent 1c694c9 commit 9339433

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

src/main/com/intellij/lang/jsgraphql/ide/editor/GraphQLIntrospectionHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,10 @@ public String printIntrospectionJsonAsGraphQL(String introspectionJson) {
168168
}
169169
}
170170
final Document schemaDefinition = new GraphQLIntrospectionResultToSchema().createSchemaDefinition(introspectionAsMap);
171-
final SchemaPrinter.Options options = SchemaPrinter.Options.defaultOptions().includeScalarTypes(true).includeSchemaDefintion(true);
171+
final SchemaPrinter.Options options = SchemaPrinter.Options.defaultOptions().includeScalarTypes(false).includeSchemaDefintion(true);
172172
final StringBuilder sb = new StringBuilder(new SchemaPrinter(options).print(schemaDefinition));
173173

174-
// graphql-java currently appears to discard custom scalars as part of the schema that the printer constructs, so include them manually here
174+
// graphql-java only prints scalars that are used by fields since it visits fields to discover types, so add the scalars here manually
175175
final Set<String> knownScalars = Sets.newHashSet();
176176
for (Node definition : schemaDefinition.getChildren()) {
177177
if (definition instanceof ScalarTypeDefinition) {

src/main/com/intellij/lang/jsgraphql/ide/editor/GraphQLIntrospectionResultToSchema.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -128,32 +128,26 @@ private TypeDefinition createScalar(Map<String, Object> input) {
128128
UnionTypeDefinition createUnion(Map<String, Object> input) {
129129
assertTrue(input.get("kind").equals("UNION"), "wrong input");
130130

131-
UnionTypeDefinition unionTypeDefinition = UnionTypeDefinition.newUnionTypeDefinition()
132-
.name((String) input.get("name"))
133-
.description(getDescription(input))
134-
.build();
135-
136-
List<Map<String, Object>> possibleTypes = (List<Map<String, Object>>) input.get("possibleTypes");
137-
131+
final List<Map<String, Object>> possibleTypes = (List<Map<String, Object>>) input.get("possibleTypes");
132+
final List<Type> memberTypes = Lists.newArrayList();
138133
for (Map<String, Object> possibleType : possibleTypes) {
139134
TypeName typeName = new TypeName((String) possibleType.get("name"));
140-
unionTypeDefinition.getMemberTypes().add(typeName);
135+
memberTypes.add(typeName);
141136
}
142137

143-
return unionTypeDefinition;
138+
return UnionTypeDefinition.newUnionTypeDefinition()
139+
.name((String) input.get("name"))
140+
.description(getDescription(input))
141+
.memberTypes(memberTypes)
142+
.build();
144143
}
145144

146145
@SuppressWarnings("unchecked")
147146
EnumTypeDefinition createEnum(Map<String, Object> input) {
148147
assertTrue(input.get("kind").equals("ENUM"), "wrong input");
149148

150-
EnumTypeDefinition enumTypeDefinition = EnumTypeDefinition.newEnumTypeDefinition()
151-
.name((String) input.get("name"))
152-
.description(getDescription(input))
153-
.build();
154-
155-
List<Map<String, Object>> enumValues = (List<Map<String, Object>>) input.get("enumValues");
156-
149+
final List<Map<String, Object>> enumValues = (List<Map<String, Object>>) input.get("enumValues");
150+
final List<EnumValueDefinition> enumValueDefinitions = Lists.newArrayList();
157151
for (Map<String, Object> enumValue : enumValues) {
158152

159153
EnumValueDefinition enumValueDefinition = EnumValueDefinition.newEnumValueDefinition()
@@ -162,10 +156,14 @@ EnumTypeDefinition createEnum(Map<String, Object> input) {
162156
.directives(createDeprecatedDirective(enumValue))
163157
.build();
164158

165-
enumTypeDefinition.getEnumValueDefinitions().add(enumValueDefinition);
159+
enumValueDefinitions.add(enumValueDefinition);
166160
}
167161

168-
return enumTypeDefinition;
162+
return EnumTypeDefinition.newEnumTypeDefinition()
163+
.name((String) input.get("name"))
164+
.description(getDescription(input))
165+
.enumValueDefinitions(enumValueDefinitions)
166+
.build();
169167
}
170168

171169
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)