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;
}
Aggregations