Skip to content

Commit 41ec6f3

Browse files
authored
fork gql java stuff (#736)
1 parent a1c9239 commit 41ec6f3

8 files changed

Lines changed: 635 additions & 37 deletions

File tree

lib/src/main/java/graphql/nadel/NextgenEngine.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ internal class NextgenEngine(
325325
executionContext = executionContext,
326326
serviceExecutionContext = serviceExecutionContext,
327327
executionHydrationDetails = executionContext.hydrationDetails,
328+
forcePrintBareFields = queryTransform.forcePrintBareFields,
328329
)
329330
}
330331
if (result is NadelIncrementalServiceExecutionResult) {
@@ -375,6 +376,7 @@ internal class NextgenEngine(
375376
executionContext: NadelExecutionContext,
376377
serviceExecutionContext: NadelServiceExecutionContext,
377378
executionHydrationDetails: ServiceExecutionHydrationDetails? = null,
379+
forcePrintBareFields: Set<ExecutableNormalizedField> = emptySet(),
378380
): ServiceExecutionResult {
379381
val timer = executionContext.timer
380382

@@ -390,6 +392,7 @@ internal class NextgenEngine(
390392
topLevelFields = topLevelFields,
391393
variablePredicate = jsonPredicate,
392394
deferSupport = executionContext.hints.deferSupport(),
395+
forcePrintBareFields = forcePrintBareFields,
393396
)
394397
}
395398

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package graphql.nadel.engine.compiler;
2+
3+
import graphql.execution.directives.QueryAppliedDirective;
4+
import graphql.execution.directives.QueryAppliedDirectiveArgument;
5+
import graphql.execution.directives.QueryDirectives;
6+
import graphql.language.Argument;
7+
import graphql.language.ArrayValue;
8+
import graphql.language.NullValue;
9+
import graphql.language.ObjectField;
10+
import graphql.language.ObjectValue;
11+
import graphql.language.Value;
12+
import graphql.normalized.ExecutableNormalizedField;
13+
import graphql.normalized.NormalizedInputValue;
14+
import graphql.normalized.VariableAccumulator;
15+
import graphql.normalized.VariableValueWithDefinition;
16+
import org.jspecify.annotations.NonNull;
17+
import org.jspecify.annotations.Nullable;
18+
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
import static graphql.collect.ImmutableKit.emptyMap;
24+
import static graphql.collect.ImmutableKit.map;
25+
import static graphql.language.Argument.newArgument;
26+
27+
/**
28+
* Verbatim copy of graphql-java's package-private graphql.normalized.ArgumentMaker (pinned version
29+
* 0.0.0-2026-03-18T00-52-57-e53ab1a), re-homed into Nadel so {@link NadelExecutableNormalizedOperationToAstCompiler}
30+
* can reach it from this package. Keep in sync when bumping graphql-java.
31+
*/
32+
class NadelArgumentMaker {
33+
34+
static List<Argument> createArguments(ExecutableNormalizedField executableNormalizedField,
35+
VariableAccumulator variableAccumulator) {
36+
List<Argument> result = new ArrayList<>();
37+
Map<String, NormalizedInputValue> normalizedArguments = executableNormalizedField.getNormalizedArguments();
38+
for (String argName : normalizedArguments.keySet()) {
39+
NormalizedInputValue normalizedInputValue = normalizedArguments.get(argName);
40+
Value<?> value = argValue(executableNormalizedField, null, argName, normalizedInputValue, variableAccumulator);
41+
Argument argument = newArgument()
42+
.name(argName)
43+
.value(value)
44+
.build();
45+
result.add(argument);
46+
}
47+
return result;
48+
}
49+
50+
static List<Argument> createDirectiveArguments(ExecutableNormalizedField executableNormalizedField,
51+
QueryDirectives queryDirectives,
52+
QueryAppliedDirective queryAppliedDirective,
53+
VariableAccumulator variableAccumulator) {
54+
55+
Map<String, NormalizedInputValue> argValueMap = queryDirectives.getNormalizedInputValueByImmediateAppliedDirectives().getOrDefault(queryAppliedDirective, emptyMap());
56+
57+
List<Argument> result = new ArrayList<>();
58+
for (QueryAppliedDirectiveArgument directiveArgument : queryAppliedDirective.getArguments()) {
59+
String argName = directiveArgument.getName();
60+
if (argValueMap != null && argValueMap.containsKey(argName)) {
61+
NormalizedInputValue normalizedInputValue = argValueMap.get(argName);
62+
Value<?> value = argValue(executableNormalizedField, queryAppliedDirective, argName, normalizedInputValue, variableAccumulator);
63+
Argument argument = newArgument()
64+
.name(argName)
65+
.value(value)
66+
.build();
67+
result.add(argument);
68+
}
69+
}
70+
return result;
71+
}
72+
73+
@SuppressWarnings("unchecked")
74+
private static Value<?> argValue(ExecutableNormalizedField executableNormalizedField,
75+
QueryAppliedDirective queryAppliedDirective,
76+
String argName,
77+
@Nullable Object value,
78+
VariableAccumulator variableAccumulator) {
79+
if (value instanceof List) {
80+
ArrayValue.Builder arrayValue = ArrayValue.newArrayValue();
81+
arrayValue.values(map((List<Object>) value, val -> argValue(executableNormalizedField, queryAppliedDirective, argName, val, variableAccumulator)));
82+
return arrayValue.build();
83+
}
84+
if (value instanceof Map) {
85+
ObjectValue.Builder objectValue = ObjectValue.newObjectValue();
86+
Map<String, Object> map = (Map<String, Object>) value;
87+
for (String fieldName : map.keySet()) {
88+
Value<?> fieldValue = argValue(executableNormalizedField, queryAppliedDirective, argName, (NormalizedInputValue) map.get(fieldName), variableAccumulator);
89+
objectValue.objectField(ObjectField.newObjectField().name(fieldName).value(fieldValue).build());
90+
}
91+
return objectValue.build();
92+
}
93+
if (value == null) {
94+
return NullValue.newNullValue().build();
95+
}
96+
return (Value<?>) value;
97+
}
98+
99+
@NonNull
100+
private static Value<?> argValue(ExecutableNormalizedField executableNormalizedField,
101+
QueryAppliedDirective queryAppliedDirective,
102+
String argName,
103+
NormalizedInputValue normalizedInputValue,
104+
VariableAccumulator variableAccumulator) {
105+
if (variableAccumulator.shouldMakeVariable(executableNormalizedField, queryAppliedDirective, argName, normalizedInputValue)) {
106+
VariableValueWithDefinition variableWithDefinition = variableAccumulator.accumulateVariable(normalizedInputValue);
107+
return variableWithDefinition.getVariableReference();
108+
} else {
109+
return argValue(executableNormalizedField, queryAppliedDirective, argName, normalizedInputValue.getValue(), variableAccumulator);
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)