Skip to content

Commit

Permalink
Adding smallrye-graphQL-logVariables
Browse files Browse the repository at this point in the history
  • Loading branch information
parsharma committed Jul 14, 2021
1 parent 2a55e37 commit e497906
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public interface ConfigKey extends org.eclipse.microprofile.graphql.ConfigKey {
public static final String ERROR_EXTENSION_FIELDS = "smallrye.graphql.errorExtensionFields";
public static final String FIELD_VISIBILITY = "smallrye.graphql.fieldVisibility";
public static final String UNWRAP_EXCEPTIONS = "smallrye.graphql.unwrapExceptions";

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class GraphQLConfig implements Config {

@Inject
@ConfigProperty(name = ConfigKey.LOG_PAYLOAD, defaultValue = "false")
private boolean logPayload;
private logPayloadOption logPayload;

@Inject
@ConfigProperty(name = ConfigKey.FIELD_VISIBILITY, defaultValue = Config.FIELD_VISIBILITY_DEFAULT)
Expand Down Expand Up @@ -182,7 +182,7 @@ public boolean isIncludeScalarsInSchema() {
}

@Override
public boolean logPayload() {
public logPayloadOption logPayload() {
return logPayload;
}

Expand Down Expand Up @@ -254,7 +254,7 @@ public void setIncludeIntrospectionTypesInSchema(boolean includeIntrospectionTyp
this.includeIntrospectionTypesInSchema = includeIntrospectionTypesInSchema;
}

public void setLogPayload(boolean logPayload) {
public void setLogPayload(logPayloadOption logPayload) {
this.logPayload = logPayload;
}

Expand Down Expand Up @@ -286,4 +286,5 @@ private Optional<List<String>> mergeList(Optional<List<String>> currentList, Opt
return Optional.empty();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.smallrye.graphql.bootstrap;

import static io.smallrye.graphql.bootstrap.Config.logPayloadOption.OFF;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -75,8 +77,22 @@ default boolean shouldEmitEvents() {
return isTracingEnabled() || isMetricsEnabled() || isValidationEnabled() || isEventsEnabled();
}

default boolean logPayload() {
return false;
public enum logPayloadOption {
OFF("false"),
TRUE("true"),
FALSE("false"),
WITHOUTVARIABLE("withoutvariable"),
WITHVARIABLE("withvariable");

private String logPayload;

logPayloadOption(String logPayload) {
this.logPayload = logPayload;
}
}

default logPayloadOption logPayload() {
return OFF;
}

default String getFieldVisibility() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static io.smallrye.graphql.SmallRyeGraphQLServerLogging.log;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicLong;

import javax.json.JsonObject;
Expand Down Expand Up @@ -77,11 +79,12 @@ public ExecutionResponse execute(JsonObject jsonInput) {

try {
String query = context.getQuery();
Optional<Map<String, Object>> variables = context.getVariables();

if (query == null || query.isEmpty()) {
throw new RuntimeException("Query can not be null");
}
if (config.logPayload()) {
if (config.logPayload().equals(Config.logPayloadOption.TRUE)) {
log.payloadIn(query);
}

Expand Down Expand Up @@ -121,7 +124,7 @@ public ExecutionResponse execute(JsonObject jsonInput) {
eventEmitter.fireAfterExecute(context);

ExecutionResponse executionResponse = new ExecutionResponse(executionResult, config);
if (config.logPayload()) {
if (config.logPayload().equals(Config.logPayloadOption.TRUE)) {
log.payloadOut(executionResponse.toString());
}

Expand Down

0 comments on commit e497906

Please sign in to comment.