Search in sources :

Example 26 with Operation

use of io.github.microcks.domain.Operation in project microcks by microcks.

the class GraphQLImporter method extractOperations.

private List<Operation> extractOperations(ObjectTypeDefinition typeDef) {
    List<Operation> results = new ArrayList<>();
    for (FieldDefinition fieldDef : typeDef.getFieldDefinitions()) {
        Operation operation = new Operation();
        operation.setName(fieldDef.getName());
        operation.setMethod(typeDef.getName().toUpperCase());
        // Deal with input names if any.
        if (fieldDef.getInputValueDefinitions() != null && !fieldDef.getInputValueDefinitions().isEmpty()) {
            operation.setInputName(getInputNames(fieldDef.getInputValueDefinitions()));
            boolean hasOnlyPrimitiveArgs = true;
            for (InputValueDefinition inputValueDef : fieldDef.getInputValueDefinitions()) {
                Type inputValueType = inputValueDef.getType();
                if (TypeUtil.isNonNull(inputValueType)) {
                    inputValueType = TypeUtil.unwrapOne(inputValueType);
                }
                if (TypeUtil.isList(inputValueType)) {
                    hasOnlyPrimitiveArgs = false;
                }
                TypeInfo inputValueTypeInfo = TypeInfo.typeInfo(inputValueType);
                if (!ScalarInfo.isGraphqlSpecifiedScalar(inputValueTypeInfo.getName())) {
                    hasOnlyPrimitiveArgs = false;
                }
            }
            if (hasOnlyPrimitiveArgs) {
                operation.setDispatcher(DispatchStyles.QUERY_ARGS);
                operation.setDispatcherRules(extractOperationParams(fieldDef.getInputValueDefinitions()));
            }
        }
        // Deal with output names if any.
        if (fieldDef.getType() != null) {
            operation.setOutputName(getTypeName(fieldDef.getType()));
        }
        results.add(operation);
    }
    return results;
}
Also used : ResourceType(io.github.microcks.domain.ResourceType) Type(graphql.language.Type) ServiceType(io.github.microcks.domain.ServiceType) ListType(graphql.language.ListType) FieldDefinition(graphql.language.FieldDefinition) ArrayList(java.util.ArrayList) Operation(io.github.microcks.domain.Operation) InputValueDefinition(graphql.language.InputValueDefinition) TypeInfo(graphql.schema.idl.TypeInfo)

Aggregations

Operation (io.github.microcks.domain.Operation)26 Service (io.github.microcks.domain.Service)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 MockRepositoryImportException (io.github.microcks.util.MockRepositoryImportException)6 Resource (io.github.microcks.domain.Resource)5 UnidirectionalEvent (io.github.microcks.domain.UnidirectionalEvent)5 Exchange (io.github.microcks.domain.Exchange)4 RequestResponsePair (io.github.microcks.domain.RequestResponsePair)4 Response (io.github.microcks.domain.Response)4 ServiceType (io.github.microcks.domain.ServiceType)4 Test (org.junit.Test)4 Header (io.github.microcks.domain.Header)3 ServiceView (io.github.microcks.domain.ServiceView)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 FieldDefinition (graphql.language.FieldDefinition)2 InputValueDefinition (graphql.language.InputValueDefinition)2 Metadata (io.github.microcks.domain.Metadata)2