use of com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration in project graphql-maven-plugin-project by graphql-java-generator.
the class GenerateCodeDocumentParser method initScalarTypes.
/**
* This method initializes the {@link #scalarTypes} list. This list depends on the use case
*/
@Override
protected void initScalarTypes(Class<?> notUsed) {
initConfiguration();
// Let's load the standard Scalar types
if (configuration.getMode().equals(PluginMode.server)) {
try {
super.initScalarTypes(Class.forName(((GenerateServerCodeConfiguration) configuration).getJavaTypeForIDType()));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
}
} else {
// In client mode, ID type is managed as a String
super.initScalarTypes(String.class);
}
// ////////////////////////////////////////////////////////////////////////////////////////
// Add of all GraphQL custom scalar implementations must be provided by the plugin configuration
logger.debug("Storing custom scalar's implementations [START]");
if (configuration.getCustomScalars() != null) {
for (CustomScalarDefinition customScalarDef : configuration.getCustomScalars()) {
CustomScalarType type = new CustomScalarType(customScalarDef, configuration, this);
getCustomScalars().add(type);
getTypes().put(type.getName(), type);
}
}
logger.debug("Storing custom scalar's implementations [END]");
}
use of com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration in project graphql-maven-plugin-project by graphql-java-generator.
the class GenerateCodeJsonSchemaPersonalization method loadGraphQLSchemaPersonalization.
/**
* Let's load the schema personalization from the configuration json file.
*
* @return
*
* @throws IOException
* @throws ProcessingException
* When the JSON file is not valid
* @throws URISyntaxException
* If we can't process the JSON URIs. It would be an internal error.
*/
public SchemaPersonalization loadGraphQLSchemaPersonalization() throws IOException, URISyntaxException {
if (((GenerateServerCodeConfiguration) configuration).getSchemaPersonalizationFile() == null) {
return null;
} else {
// Let's check that the JSON is valid
JsonValidationService service = JsonValidationService.newInstance();
// Reads the JSON schema
//
// There is an issue in reading the json schema, when the project is built with Gradle 7
// It seems to be linked to https://issues.apache.org/jira/browse/JOHNZON-147 (solved in Johnzon 1.1.6, in
// february 2018)
// A workaround is to first read the schema in a string, then call the readSchema
BufferedReader br = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("/" + JSON_SCHEMA_FILENAME), Charset.forName("UTF-8")));
String text = br.lines().collect(Collectors.joining("\n"));
// readSchema should directly read the InputStream
JsonSchema schema = service.readSchema(new StringReader(text));
// Problem handler which will print problems found
ProblemHandler handler = service.createProblemPrinter(this::logParsingError);
// Reads the JSON instance by javax.json.JsonReader
nbErrors = 0;
try (JsonReader reader = service.createReader(new FileInputStream(((GenerateServerCodeConfiguration) configuration).getSchemaPersonalizationFile()), schema, handler)) {
// JsonValue value =
reader.readValue();
// Do something useful here
}
if (nbErrors > 0) {
throw new RuntimeException("The json file '" + ((GenerateServerCodeConfiguration) configuration).getSchemaPersonalizationFile().getAbsolutePath() + "' is invalid. See the logs for details");
}
// Let's read the flow definition
logger.info("Loading file " + ((GenerateServerCodeConfiguration) configuration).getSchemaPersonalizationFile().getAbsolutePath());
ObjectMapper objectMapper = new ObjectMapper();
SchemaPersonalization ret;
try (InputStream isFlowJson = new FileInputStream(((GenerateServerCodeConfiguration) configuration).getSchemaPersonalizationFile())) {
ret = objectMapper.readValue(isFlowJson, SchemaPersonalization.class);
}
return ret;
}
}
Aggregations