Search in sources :

Example 1 with GraphQLInterfaceType

use of com.graphql_java_generator.annotation.GraphQLInterfaceType in project graphql-maven-plugin-project by graphql-java-generator.

the class QueryField method isScalar.

/**
 * Indicates whether this field is a scalar or not.
 *
 * @return true if this field is a scalar (custom or not), and false otherwise.
 * @throws GraphQLRequestPreparationException
 */
public boolean isScalar() throws GraphQLRequestPreparationException {
    if (scalar == null) {
        // The scalar value has not yet been calculated.
        // All the generated classes have a GraphQL annotation.
        // If no such annotation, then this type is a scalar.
        GraphQLInputType graphQLInputType = clazz.getAnnotation(GraphQLInputType.class);
        GraphQLInterfaceType graphQLInterfaceType = clazz.getAnnotation(GraphQLInterfaceType.class);
        GraphQLObjectType graphQLObjectType = clazz.getAnnotation(GraphQLObjectType.class);
        GraphQLQuery graphQLQuery = clazz.getAnnotation(GraphQLQuery.class);
        GraphQLUnionType graphQLUnionType = clazz.getAnnotation(GraphQLUnionType.class);
        // If one of these annotations is not null, then it's not a scalar. Otherwise, this type is a scalar.
        scalar = !(graphQLInputType != null || graphQLInterfaceType != null || graphQLObjectType != null || graphQLQuery != null || graphQLUnionType != null);
    }
    return scalar;
}
Also used : GraphQLInputType(com.graphql_java_generator.annotation.GraphQLInputType) GraphQLUnionType(com.graphql_java_generator.annotation.GraphQLUnionType) GraphQLObjectType(com.graphql_java_generator.annotation.GraphQLObjectType) GraphQLInterfaceType(com.graphql_java_generator.annotation.GraphQLInterfaceType) GraphQLQuery(com.graphql_java_generator.annotation.GraphQLQuery)

Example 2 with GraphQLInterfaceType

use of com.graphql_java_generator.annotation.GraphQLInterfaceType in project graphql-maven-plugin-project by graphql-java-generator.

the class GraphqlClientUtils method getGraphQLTypeNameFromClass.

/**
 * Retrieves the GraphQL type name (as defined in the GraphQL schema), from the GraphQL annotation added in the
 * generated code by the plugin.
 *
 * @param clazz
 * @return
 */
public String getGraphQLTypeNameFromClass(Class<?> clazz) {
    // Object
    GraphQLObjectType graphQLObjectType = clazz.getAnnotation(GraphQLObjectType.class);
    if (graphQLObjectType != null) {
        return graphQLObjectType.value();
    }
    // Interface
    GraphQLInterfaceType graphQLInterfaceType = clazz.getAnnotation(GraphQLInterfaceType.class);
    if (graphQLInterfaceType != null) {
        return graphQLInterfaceType.value();
    }
    // Union
    GraphQLUnionType graphQLUnionType = clazz.getAnnotation(GraphQLUnionType.class);
    if (graphQLUnionType != null) {
        return graphQLUnionType.value();
    }
    // Enum
    GraphQLEnumType graphQLEnumType = clazz.getAnnotation(GraphQLEnumType.class);
    if (graphQLEnumType != null) {
        return graphQLEnumType.value();
    }
    throw new RuntimeException("Could not find the GraphQL type for the class " + clazz.getName());
}
Also used : GraphQLUnionType(com.graphql_java_generator.annotation.GraphQLUnionType) GraphQLEnumType(com.graphql_java_generator.annotation.GraphQLEnumType) GraphQLObjectType(com.graphql_java_generator.annotation.GraphQLObjectType) GraphQLInterfaceType(com.graphql_java_generator.annotation.GraphQLInterfaceType)

Aggregations

GraphQLInterfaceType (com.graphql_java_generator.annotation.GraphQLInterfaceType)2 GraphQLObjectType (com.graphql_java_generator.annotation.GraphQLObjectType)2 GraphQLUnionType (com.graphql_java_generator.annotation.GraphQLUnionType)2 GraphQLEnumType (com.graphql_java_generator.annotation.GraphQLEnumType)1 GraphQLInputType (com.graphql_java_generator.annotation.GraphQLInputType)1 GraphQLQuery (com.graphql_java_generator.annotation.GraphQLQuery)1