Search in sources :

Example 1 with ScalarExtensionType

use of com.graphql_java_generator.plugin.language.impl.ScalarExtensionType in project graphql-maven-plugin-project by graphql-java-generator.

the class DocumentParser method readScalarExtensionType.

/**
 * Reads a GraphQL Custom Scalar, from its definition. This method checks that the CustomScalar has already been
 * defined, in the plugin configuration.
 *
 * @param node
 *            The {@link CustomScalarType} that represents this Custom Scalar
 * @return
 */
ScalarExtensionType readScalarExtensionType(ScalarTypeExtensionDefinition node) {
    String name = node.getName();
    // The current node is an extension of a GraphQL scalar. We must find the entry in the scalar list, to replace
    // it by the scalar extension definition
    boolean found = false;
    ScalarType scalarType = null;
    for (ScalarType t : scalarTypes) {
        if (t.getName().equals(name)) {
            found = true;
            scalarType = t;
        }
    }
    // for
    if (!found) {
        throw new RuntimeException("[Internal error] The '" + name + "' scalar definition was not properly initialized");
    }
    ScalarExtensionType scalarExtensionType = new ScalarExtensionType(name, scalarType.getPackageName(), scalarType.getClassSimpleName(), configuration, this);
    scalarExtensionType.setAppliedDirectives(readAppliedDirectives(node.getDirectives()));
    scalarExtensionType.setComments(node.getComments());
    // We replace the definition for the original GraphQL scalar by this one
    scalarTypes.remove(scalarType);
    scalarTypes.add(scalarExtensionType);
    return scalarExtensionType;
}
Also used : ScalarType(com.graphql_java_generator.plugin.language.impl.ScalarType) CustomScalarType(com.graphql_java_generator.plugin.language.impl.CustomScalarType) ScalarExtensionType(com.graphql_java_generator.plugin.language.impl.ScalarExtensionType)

Aggregations

CustomScalarType (com.graphql_java_generator.plugin.language.impl.CustomScalarType)1 ScalarExtensionType (com.graphql_java_generator.plugin.language.impl.ScalarExtensionType)1 ScalarType (com.graphql_java_generator.plugin.language.impl.ScalarType)1