|
22 | 22 | import graphql.language.Type; |
23 | 23 | import graphql.language.TypeDefinition; |
24 | 24 | import graphql.language.TypeExtensionDefinition; |
25 | | -import graphql.language.TypeName; |
26 | 25 | import graphql.language.UnionTypeDefinition; |
27 | 26 | import graphql.language.Value; |
28 | 27 | import graphql.schema.DataFetcher; |
|
42 | 41 | import graphql.schema.PropertyDataFetcher; |
43 | 42 | import graphql.schema.TypeResolver; |
44 | 43 | import graphql.schema.TypeResolverProxy; |
| 44 | +import graphql.schema.idl.errors.NotAnInputTypeError; |
| 45 | +import graphql.schema.idl.errors.NotAnOutputTypeError; |
45 | 46 | import graphql.schema.idl.errors.SchemaProblem; |
46 | 47 |
|
47 | 48 | import java.util.Collections; |
@@ -135,7 +136,9 @@ public SchemaGenerator() { |
135 | 136 | * |
136 | 137 | * @param typeRegistry this can be obtained via {@link SchemaCompiler#compile(String)} |
137 | 138 | * @param wiring this can be built using {@link RuntimeWiring#newRuntimeWiring()} |
| 139 | + * |
138 | 140 | * @return an executable schema |
| 141 | + * |
139 | 142 | * @throws SchemaProblem if there are problems in assembling a schema such as missing type resolvers or no operations defined |
140 | 143 | */ |
141 | 144 | public GraphQLSchema makeExecutableSchema(TypeDefinitionRegistry typeRegistry, RuntimeWiring wiring) throws SchemaProblem { |
@@ -184,6 +187,7 @@ private GraphQLObjectType buildOperation(BuildContext buildCtx, OperationTypeDef |
184 | 187 | * |
185 | 188 | * @param buildCtx the context we need to work out what we are doing |
186 | 189 | * @param rawType the type to be built |
| 190 | + * |
187 | 191 | * @return an output type |
188 | 192 | */ |
189 | 193 | @SuppressWarnings("unchecked") |
@@ -213,8 +217,11 @@ private <T extends GraphQLOutputType> T buildOutputType(BuildContext buildCtx, T |
213 | 217 | outputType = buildUnionType(buildCtx, (UnionTypeDefinition) typeDefinition); |
214 | 218 | } else if (typeDefinition instanceof EnumTypeDefinition) { |
215 | 219 | outputType = buildEnumType((EnumTypeDefinition) typeDefinition); |
216 | | - } else { |
| 220 | + } else if (typeDefinition instanceof ScalarTypeDefinition){ |
217 | 221 | outputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition); |
| 222 | + } else { |
| 223 | + // typeDefinition is not a valid output type |
| 224 | + throw new NotAnOutputTypeError(typeDefinition); |
218 | 225 | } |
219 | 226 |
|
220 | 227 | buildCtx.put(outputType); |
@@ -243,8 +250,11 @@ private GraphQLInputType buildInputType(BuildContext buildCtx, Type rawType) { |
243 | 250 | inputType = buildInputObjectType(buildCtx, (InputObjectTypeDefinition) typeDefinition); |
244 | 251 | } else if (typeDefinition instanceof EnumTypeDefinition) { |
245 | 252 | inputType = buildEnumType((EnumTypeDefinition) typeDefinition); |
246 | | - } else { |
| 253 | + } else if (typeDefinition instanceof ScalarTypeDefinition){ |
247 | 254 | inputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition); |
| 255 | + } else { |
| 256 | + // typeDefinition is not a valid InputType |
| 257 | + throw new NotAnInputTypeError(typeDefinition); |
248 | 258 | } |
249 | 259 |
|
250 | 260 | buildCtx.put(inputType); |
@@ -331,7 +341,9 @@ private GraphQLUnionType buildUnionType(BuildContext buildCtx, UnionTypeDefiniti |
331 | 341 | builder.typeResolver(getTypeResolver(buildCtx, typeDefinition.getName())); |
332 | 342 |
|
333 | 343 | typeDefinition.getMemberTypes().forEach(mt -> { |
334 | | - builder.possibleType(new GraphQLTypeReference(((TypeName) mt).getName())); |
| 344 | + TypeDefinition memberTypeDef = buildCtx.getTypeDefinition(mt); |
| 345 | + GraphQLObjectType objectType = buildObjectType(buildCtx, (ObjectTypeDefinition) memberTypeDef); |
| 346 | + builder.possibleType(objectType); |
335 | 347 | }); |
336 | 348 | return builder.build(); |
337 | 349 | } |
|
0 commit comments