Search in sources :

Example 1 with RelationImpl

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

the class GenerateCodeDocumentParser method initRelations.

/**
 * Reads all the GraphQl objects, interfaces, union... that have been read from the GraphQL schema, and list all the
 * relations between Server objects (that is: all objects out of the Query/Mutation/Subscription types and the input
 * types). The found relations are stored, to be reused during the code generation.<BR/>
 * These relations are important for the server mode of the plugin, to generate the proper JPA annotations.
 */
void initRelations() {
    for (ObjectType type : getObjectTypes()) {
        // We initiate the relations only for regular objects (not query/mutation/subscription)
        if (type.getRequestType() == null) {
            if (!type.isInputType()) {
                for (Field field : type.getFields()) {
                    if (field.getType() instanceof ObjectType) {
                        RelationType relType = field.getFieldTypeAST().getListDepth() > 0 ? RelationType.OneToMany : RelationType.ManyToOne;
                        RelationImpl relation = new RelationImpl(type, field, relType);
                        // 
                        ((FieldImpl) field).setRelation(relation);
                        relations.add(relation);
                    }
                // if (instanceof ObjectType)
                }
            // if (!type.isInputType())
            }
        // for (field)
        }
    // if (type.getRequestType()== null)
    }
// for (type)
}
Also used : RelationImpl(com.graphql_java_generator.plugin.language.impl.RelationImpl) ObjectType(com.graphql_java_generator.plugin.language.impl.ObjectType) GraphQLObjectType(com.graphql_java_generator.annotation.GraphQLObjectType) Field(com.graphql_java_generator.plugin.language.Field) GraphQLField(com.graphql_java_generator.GraphQLField) RelationType(com.graphql_java_generator.plugin.language.RelationType) FieldImpl(com.graphql_java_generator.plugin.language.impl.FieldImpl)

Aggregations

GraphQLField (com.graphql_java_generator.GraphQLField)1 GraphQLObjectType (com.graphql_java_generator.annotation.GraphQLObjectType)1 Field (com.graphql_java_generator.plugin.language.Field)1 RelationType (com.graphql_java_generator.plugin.language.RelationType)1 FieldImpl (com.graphql_java_generator.plugin.language.impl.FieldImpl)1 ObjectType (com.graphql_java_generator.plugin.language.impl.ObjectType)1 RelationImpl (com.graphql_java_generator.plugin.language.impl.RelationImpl)1