This is an automated email from the ASF dual-hosted git repository.

bdelacretaz pushed a commit to branch master
in repository 
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-graphql-core.git


The following commit(s) were added to refs/heads/master by this push:
     new 23aab81  Introduce LegacyCoercingInputInterceptor in 
DefaultQueryExecutor (#43)
23aab81 is described below

commit 23aab81937d34abded59739437167ad67ce1d711
Author: Martin Schulze <[email protected]>
AuthorDate: Wed Jun 25 13:04:19 2025 +0200

    Introduce LegacyCoercingInputInterceptor in DefaultQueryExecutor (#43)
    
    Co-authored-by: Martin Schulze <[email protected]>
---
 .../graphql/core/engine/DefaultQueryExecutor.java  |  5 +++-
 .../core/engine/DefaultQueryExecutorTest.java      | 28 ++++++++++++++++++++++
 .../graphql/core/engine/ResourceQueryTestBase.java |  8 +++++--
 src/test/resources/test-schema.txt                 |  2 +-
 4 files changed, 39 insertions(+), 4 deletions(-)

diff --git 
a/src/main/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutor.java 
b/src/main/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutor.java
index ac16f15..88d87cd 100644
--- 
a/src/main/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutor.java
+++ 
b/src/main/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutor.java
@@ -63,6 +63,8 @@ import graphql.GraphQL;
 import graphql.GraphQLError;
 import graphql.ParseAndValidate;
 import graphql.ParseAndValidateResult;
+import graphql.execution.values.InputInterceptor;
+import graphql.execution.values.legacycoercing.LegacyCoercingInputInterceptor;
 import graphql.language.Argument;
 import graphql.language.Directive;
 import graphql.language.FieldDefinition;
@@ -196,7 +198,8 @@ public class DefaultQueryExecutor implements QueryExecutor {
                         .maxWhitespaceTokens(maxWhitespaceTokens)
                         .build()
             );
-            return builder -> builder.put(ParserOptions.class, parserOptions);
+            return builder -> builder.put(ParserOptions.class, 
parserOptions).put(InputInterceptor.class,
+                    LegacyCoercingInputInterceptor.migratesValues());
         }
     }
 
diff --git 
a/src/test/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutorTest.java
 
b/src/test/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutorTest.java
index 0583273..103955e 100644
--- 
a/src/test/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutorTest.java
+++ 
b/src/test/java/org/apache/sling/graphql/core/engine/DefaultQueryExecutorTest.java
@@ -61,6 +61,7 @@ import 
graphql.normalized.ExecutableNormalizedOperationFactory;
 import graphql.schema.idl.TypeDefinitionRegistry;
 
 import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasJsonPath;
+import static com.jayway.jsonpath.matchers.JsonPathMatchers.hasNoJsonPath;
 import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.equalTo;
 import static org.hamcrest.Matchers.is;
@@ -525,4 +526,31 @@ public class DefaultQueryExecutorTest extends 
ResourceQueryTestBase {
 
         assertEquals("Max field count should match the configured value", 
expectedMaxFieldCount, actualMaxFieldCount);
     }
+
+    @Test
+    public void testBooleanVariable() throws Exception {
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("boolVar", "false");
+
+        final String json = queryJSON("query($boolVar: Boolean) { 
lazyQuery(boolVar: $boolVar) { cheapCount }}", variables);
+        assertThat(json, hasNoJsonPath("$.errors"));
+    }
+
+    @Test
+    public void testIntegerVariable() throws Exception {
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("intVar", "10");
+
+        final String json = queryJSON("query($intVar: Int) { lazyQuery(intVar: 
$intVar) { cheapCount }}", variables);
+        assertThat(json, hasNoJsonPath("$.errors"));
+    }
+
+    @Test
+    public void testFloatVariable() throws Exception {
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("floatVar", "10.1");
+
+        final String json = queryJSON("query($floatVar: Float) { 
lazyQuery(floatVar: $floatVar) { cheapCount }}", variables);
+        assertThat(json, hasNoJsonPath("$.errors"));
+    }
 }
diff --git 
a/src/test/java/org/apache/sling/graphql/core/engine/ResourceQueryTestBase.java 
b/src/test/java/org/apache/sling/graphql/core/engine/ResourceQueryTestBase.java
index 34c92fc..1bc3e81 100644
--- 
a/src/test/java/org/apache/sling/graphql/core/engine/ResourceQueryTestBase.java
+++ 
b/src/test/java/org/apache/sling/graphql/core/engine/ResourceQueryTestBase.java
@@ -78,13 +78,17 @@ public abstract class ResourceQueryTestBase {
     }
 
     protected String queryJSON(String stmt) throws Exception {
-        return queryJSON(stmt, new String[]{});
+        return queryJSON(stmt, Collections.emptyMap(), new String[]{});
     }
 
     protected String queryJSON(String stmt, String ... selectors) {
+        return queryJSON(stmt, Collections.emptyMap(), selectors);  
+    }
+
+    protected String queryJSON(String stmt, Map<String, Object> variables, 
String ... selectors) {
         final QueryExecutor queryExecutor = 
context.getService(QueryExecutor.class);
         assertNotNull(queryExecutor);
-        Map<String, Object> executionResult = queryExecutor.execute(stmt, 
Collections.emptyMap(), resource, selectors);
+        Map<String, Object> executionResult = queryExecutor.execute(stmt, 
variables, resource, selectors);
         return 
Json.createObjectBuilder(executionResult).build().asJsonObject().toString();
     }
 
diff --git a/src/test/resources/test-schema.txt 
b/src/test/resources/test-schema.txt
index 3527581..d569ce6 100644
--- a/src/test/resources/test-schema.txt
+++ b/src/test/resources/test-schema.txt
@@ -33,7 +33,7 @@ type Query {
     # Test interface query
     interfaceQuery: CharactersAsInterface @fetcher(name:"character/fetcher")
 
-    lazyQuery : ExpensiveObject @fetcher(name:"lazy/fetcher")
+    lazyQuery(boolVar : Boolean, intVar : Int, floatVar: Float) : 
ExpensiveObject @fetcher(name:"lazy/fetcher")
 }
 
 interface CharacterInterface @resolver(name:"character/resolver" 
source:"CharacterInterface") {

Reply via email to