use of graphql.schema.GraphQLNamedInputType in project graphql-java by graphql-java.
the class SchemaGeneratorHelper method buildAdditionalTypes.
/**
* We build the query / mutation / subscription path as a tree of referenced types
* but then we build the rest of the types specified and put them in as additional types
*
* @param buildCtx the context we need to work out what we are doing
*
* @return the additional types not referenced from the top level operations
*/
Set<GraphQLType> buildAdditionalTypes(BuildContext buildCtx) {
TypeDefinitionRegistry typeRegistry = buildCtx.getTypeRegistry();
Set<String> detachedTypeNames = getDetachedTypeNames(buildCtx);
Set<GraphQLType> additionalTypes = new LinkedHashSet<>();
// recursively record detached types on the ctx and add them to the additionalTypes set
typeRegistry.types().values().stream().filter(typeDefinition -> detachedTypeNames.contains(typeDefinition.getName())).forEach(typeDefinition -> {
TypeName typeName = TypeName.newTypeName().name(typeDefinition.getName()).build();
if (typeDefinition instanceof InputObjectTypeDefinition) {
if (buildCtx.hasInputType(typeDefinition) == null) {
buildCtx.putInputType((GraphQLNamedInputType) buildInputType(buildCtx, typeName));
}
additionalTypes.add(buildCtx.inputGTypes.get(typeDefinition.getName()));
} else {
if (buildCtx.hasOutputType(typeDefinition) == null) {
buildCtx.putOutputType(buildOutputType(buildCtx, typeName));
}
additionalTypes.add(buildCtx.outputGTypes.get(typeDefinition.getName()));
}
});
typeRegistry.scalars().values().stream().filter(typeDefinition -> detachedTypeNames.contains(typeDefinition.getName())).forEach(scalarTypeDefinition -> {
if (ScalarInfo.isGraphqlSpecifiedScalar(scalarTypeDefinition.getName())) {
return;
}
if (buildCtx.hasInputType(scalarTypeDefinition) == null && buildCtx.hasOutputType(scalarTypeDefinition) == null) {
buildCtx.putOutputType(buildScalar(buildCtx, scalarTypeDefinition));
}
if (buildCtx.hasInputType(scalarTypeDefinition) != null) {
additionalTypes.add(buildCtx.inputGTypes.get(scalarTypeDefinition.getName()));
} else if (buildCtx.hasOutputType(scalarTypeDefinition) != null) {
additionalTypes.add(buildCtx.outputGTypes.get(scalarTypeDefinition.getName()));
}
});
return additionalTypes;
}
Aggregations