etugarev commented on a change in pull request #1:
URL: 
https://github.com/apache/sling-org-apache-sling-graphql-core/pull/1#discussion_r447126408



##########
File path: 
src/main/java/org/apache/sling/graphql/core/scalars/SlingScalarsProvider.java
##########
@@ -46,55 +49,17 @@
     Constants.SERVICE_VENDOR + "=The Apache Software Foundation" })
 public class SlingScalarsProvider {
 
-    private BundleContext bundleContext;
-    
-    @Activate
-    public void activate(BundleContext ctx) {
-        bundleContext = ctx;
-    }
-
-    @SuppressWarnings("unchecked")
-    private GraphQLScalarType getScalar(String name) {
-
-        // Ignore standard scalars
-        if(ScalarInfo.STANDARD_SCALAR_DEFINITIONS.containsKey(name)) {
-            return null;
-        }
-
-        SlingScalarConverter<Object, Object> converter = null;
-        final String filter = String.format("(%s=%s)", 
SlingScalarConverter.NAME_SERVICE_PROPERTY, name);
-        ServiceReference<?>[] refs= null;
-        try {
-            refs = 
bundleContext.getServiceReferences(SlingScalarConverter.class.getName(), 
filter);
-        } catch(InvalidSyntaxException ise) {
-            throw new SlingGraphQLException("Invalid OSGi filter syntax:" + 
filter);
-        }
-        if(refs != null) {
-            // SlingScalarConverter services must have a unique name for now
-            // (we might use a namespacing @directive in the schema to allow 
multiple ones with the same name)
-            if(refs.length > 1) {
-                throw new SlingGraphQLException(String.format("Got %d services 
for %s, expected just one", refs.length, filter));
-            }
-            converter = (SlingScalarConverter<Object, 
Object>)bundleContext.getService(refs[0]);
-        }
-
-        if(converter == null) {
-            throw new SlingGraphQLException("SlingScalarConverter with name '" 
+ name + "' not found");
-        }
-
-        return GraphQLScalarType.newScalar()
-            .name(name)
-            .description(converter.toString())
-            .coercing(new SlingCoercingWrapper(converter))
-            .build();
-    }
+    @Reference
+    private SlingScalarConvertersProvider slingScalarConvertersProvider;
 
-    public Iterable<GraphQLScalarType> 
getCustomScalars(Map<String,ScalarTypeDefinition> schemaScalars) {
-        // Using just the names for now, not sure why we'd need the 
ScalarTypeDefinitions
-        return schemaScalars.keySet().stream()
-            .map(this::getScalar)
-            .filter(it -> it != null)
-            .collect(Collectors.toList());
+    public List<GraphQLScalarType> getCustomScalars() {

Review comment:
       Injecting all at once, we can also filter by taking only items which are 
in `Map<String,ScalarTypeDefinition> schemaScalars`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to