[GitHub] [sling-org-apache-sling-graphql-core] etugarev commented on a change in pull request #1: Feature/sling 9550 all scalars

2020-06-30 Thread GitBox


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



##
File path: 
src/test/java/org/apache/sling/graphql/core/mocks/URLScalarConverter.java
##
@@ -41,4 +41,14 @@
 final String testPrefix = getClass().getSimpleName() + " says:";
 return testPrefix + (value == null ? null : value.toExternalForm());
 }
+
+@Override
+public String getName() {

Review comment:
   an idea, we can have name and description in `SlingScalarConverter`, 
here it's not yet implemented





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




[GitHub] [sling-org-apache-sling-graphql-core] etugarev commented on a change in pull request #1: Feature/sling 9550 all scalars

2020-06-30 Thread GitBox


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 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)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 
getCustomScalars(Map 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 getCustomScalars() {

Review comment:
   Injecting all at once, we can also filter by taking only items which are 
in `Map 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




[GitHub] [sling-org-apache-sling-graphql-core] etugarev commented on a change in pull request #1: Feature/sling 9550 all scalars

2020-06-30 Thread GitBox


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



##
File path: 
src/test/java/org/apache/sling/graphql/core/mocks/URLScalarConverter.java
##
@@ -41,4 +41,14 @@
 final String testPrefix = getClass().getSimpleName() + " says:";
 return testPrefix + (value == null ? null : value.toExternalForm());
 }
+
+@Override
+public String getName() {

Review comment:
   we have name and description in `SlingScalarConverter` here it's not yet 
implemented





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




[GitHub] [sling-org-apache-sling-graphql-core] etugarev commented on a change in pull request #1: Feature/sling 9550 all scalars

2020-06-29 Thread GitBox


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 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)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 
getCustomScalars(Map 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 getCustomScalars() {

Review comment:
   Injecting all at once





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