Search in sources :

Example 1 with CustomScalarDefinition

use of com.graphql_java_generator.plugin.conf.CustomScalarDefinition in project graphql-maven-plugin-project by graphql-java-generator.

the class Forum_Server_SpringConfiguration method addSpecificConfigurationParameterValue.

@Override
protected void addSpecificConfigurationParameterValue(GraphQLConfigurationTestHelper configuration) {
    List<CustomScalarDefinition> customScalars = new ArrayList<>();
    customScalars.add(new CustomScalarDefinition("Date", "java.util.Date", null, "com.graphql_java_generator.customscalars.GraphQLScalarTypeDate.Date", null));
    configuration.schemaFilePattern = "forum.graphqls";
    configuration.mode = PluginMode.server;
    configuration.schemaPersonalizationFile = new File(mavenTestHelper.getModulePathFile(), "src/test/resources/forum_personalization.json");
    configuration.customScalars = customScalars;
    configuration.separateUtilityClasses = false;
    configuration.javaTypeForIDType = "java.lang.String";
}
Also used : ArrayList(java.util.ArrayList) CustomScalarDefinition(com.graphql_java_generator.plugin.conf.CustomScalarDefinition) File(java.io.File)

Example 2 with CustomScalarDefinition

use of com.graphql_java_generator.plugin.conf.CustomScalarDefinition 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]");
}
Also used : GenerateServerCodeConfiguration(com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration) CustomScalarDefinition(com.graphql_java_generator.plugin.conf.CustomScalarDefinition) CustomScalarType(com.graphql_java_generator.plugin.language.impl.CustomScalarType)

Example 3 with CustomScalarDefinition

use of com.graphql_java_generator.plugin.conf.CustomScalarDefinition in project graphql-maven-plugin-project by graphql-java-generator.

the class GenerateGraphQLSchemaDocumentParser method getCustomScalarType.

/**
 * This class doesn't need an implementation for the Custom Scalars. So a dummy one is returned. {@inheritDoc}
 */
@Override
protected CustomScalarType getCustomScalarType(String name) {
    // If this custom scalar has already been added to the list, let's return it
    for (CustomScalarType customScalarType : customScalars) {
        if (customScalarType.getName().equals(name)) {
            return customScalarType;
        }
    }
    // The custom scalar has not been added to the list yet, let's add it first.
    CustomScalarDefinition customScalarDefinition = new CustomScalarDefinition(name, "java.lang.String", "com.graphql_java_generator.customscalars.GraphQLScalarTypeString", null, null);
    CustomScalarType customScalarType = new CustomScalarType(customScalarDefinition, configuration, this);
    customScalars.add(customScalarType);
    types.put(customScalarType.getName(), customScalarType);
    return customScalarType;
}
Also used : CustomScalarDefinition(com.graphql_java_generator.plugin.conf.CustomScalarDefinition) CustomScalarType(com.graphql_java_generator.plugin.language.impl.CustomScalarType)

Aggregations

CustomScalarDefinition (com.graphql_java_generator.plugin.conf.CustomScalarDefinition)3 CustomScalarType (com.graphql_java_generator.plugin.language.impl.CustomScalarType)2 GenerateServerCodeConfiguration (com.graphql_java_generator.plugin.conf.GenerateServerCodeConfiguration)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1