Skip to content

Commit

Permalink
Policy directive changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NavidMitchell committed Dec 7, 2024
1 parent 4ef5a09 commit e5c5a95
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
import org.kinotic.continuum.idl.api.schema.ObjectC3Type;
import org.kinotic.continuum.idl.api.schema.PropertyDefinition;
import org.kinotic.continuum.idl.api.schema.decorators.NotNullC3Decorator;
import org.kinotic.structures.api.domain.idl.decorators.AutoGeneratedIdDecorator;
import org.kinotic.structures.api.domain.idl.decorators.DiscriminatorDecorator;
import org.kinotic.structures.api.domain.idl.decorators.IdDecorator;
import org.kinotic.structures.api.domain.idl.decorators.ReadOnlyDecorator;
import org.kinotic.structures.api.domain.idl.decorators.*;
import org.kinotic.structures.internal.endpoints.graphql.DiscriminatorTypeResolver;
import org.kinotic.structures.internal.utils.GqlUtils;

import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
import static graphql.schema.GraphQLInputObjectField.newInputObjectField;
Expand Down Expand Up @@ -116,9 +114,16 @@ public GqlTypeHolder convert(ObjectC3Type objectC3Type,

conversionContext.state().endProcessingField();

outputBuilder.field(newFieldDefinition()
.name(fieldName)
.type(fieldValue.outputType()));
if(property.containsDecorator(PolicyDecorator.class)){
outputBuilder.field(newFieldDefinition()
.name(fieldName)
.type(fieldValue.outputType())
.withDirective(GqlUtils.policy(property.findDecorator(PolicyDecorator.class).getPolicies())));
}else{
outputBuilder.field(newFieldDefinition()
.name(fieldName)
.type(fieldValue.outputType()));
}

// input type can be null in some cases such as a Union type.
// This can create a paradigm mismatch between OpenApi and GraphQL, but we cannot do anything about it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
public class GqlUtils {
private static final Logger log = LoggerFactory.getLogger(GqlUtils.class);

public static final GraphQLTypeReference federationPolicyTypeRef = new GraphQLTypeReference("federation__Policy");

public static final GraphQLScalarType FederationPolicyScalar = GraphQLScalarType.newScalar()
.name("federation__Policy")
.description("Apollo custom Scalar for the federation__Policy")
Expand All @@ -42,7 +44,7 @@ public class GqlUtils {
private static final GraphQLList nestedPolicyList = GraphQLList.list( // Define the [[federation__Policy!]!] input type
new GraphQLNonNull(
GraphQLList.list(
new GraphQLNonNull(FederationPolicyScalar)
new GraphQLNonNull(federationPolicyTypeRef)
)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,11 @@ public CompletableFuture<Participant> authenticate(Map<String, String> authentic

return CompletableFuture.completedFuture(createParticipant(authenticationInfo.get("tenantId")));
}else{
if(log.isDebugEnabled()){
log.debug("Failed to authenticate user: {}", authenticationInfo.get("login"));
}
log.debug("Failed to authenticate user: {}", authenticationInfo.get("login"));
}
}
}else{
if(log.isDebugEnabled()){
log.debug("Only Basic Auth is supported. Received {}", authorizationHeader);
}
log.debug("Only Basic Auth is supported. Received {}", authorizationHeader);
}
}

Expand Down

0 comments on commit e5c5a95

Please sign in to comment.