You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by GitBox <gi...@apache.org> on 2020/10/06 09:47:12 UTC

[GitHub] [sling-org-apache-sling-graphql-core] kozmaadrian opened a new pull request #6: [early review] Adds support for using Unions.

kozmaadrian opened a new pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6


   PR created for early review.
   
   TODO
   - [ ] Implements tests for testing the new SlingTypeProvider
   - [ ] Verify SlingTypeResolverScriptWrapper
   - [ ] Update Readme, describe SlingTypeResolverScriptWrapper


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] kozmaadrian commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
kozmaadrian commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500833581



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/ScriptedTypeResolverProvider.java
##########
@@ -0,0 +1,91 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.Servlet;
+
+/**
+ * Resolves a SlingTypeResolver name to a SlingScript if available.
+ */
+@Component(service = ScriptedTypeResolverProvider.class)
+public class ScriptedTypeResolverProvider {

Review comment:
       Actually, I tried to follow the concept used for DataFetchers.
   
   @bdelacretaz please let me know if you prefer to remove it.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] kozmaadrian commented on pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
kozmaadrian commented on pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#issuecomment-704224062


   > Could you create a https://issues.apache.org/jira/projects/SLING ticket so we can assign this to a release etc? Just a brief description of your use case there is good enough.
   
   Thanks @bdelacretaz for your input. 
   
   I've created the following ticket https://issues.apache.org/jira/browse/SLING-9796


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] kozmaadrian commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
kozmaadrian commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500833581



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/ScriptedTypeResolverProvider.java
##########
@@ -0,0 +1,91 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.Servlet;
+
+/**
+ * Resolves a SlingTypeResolver name to a SlingScript if available.
+ */
+@Component(service = ScriptedTypeResolverProvider.class)
+public class ScriptedTypeResolverProvider {

Review comment:
       Actually, I tried to follow the concept used for DataFetchers.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] kozmaadrian commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
kozmaadrian commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500453501



##########
File path: src/main/java/org/apache/sling/graphql/api/SlingTypeResolverEnvironment.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.api;
+
+import org.apache.sling.api.resource.Resource;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Provides contextual information to the {#link SlingDataFetcher}
+ */
+@SuppressWarnings("TypeParameterUnusedInFormals")
+
+@ProviderType
+public interface SlingTypeResolverEnvironment {
+
+    /**
+     * @return the current Sling resource
+     */
+    @Nullable
+    Resource getCurrentResource();
+
+    /**
+     * @return the options, if set by the schema directive
+     */
+    @Nullable
+    String getResolverOptions();
+
+    /**
+     * @return the source, if set by the schema directive
+     */
+    @Nullable
+    String getResolverSource();
+
+    /**
+     * @return the GraphQL result item
+     */
+    @Nullable
+    Object getObject();
+
+    /**
+     * @param <T> the type name
+     * @return the GraphQL Object Type
+     */
+    @Nullable <T> T getObjectType(String name);

Review comment:
       Changed to 
   
   ```
       @Nullable
       T getObjectType(@NotNull String name);
   ```




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] raducotescu commented on pull request #6: SLING-9796 - Add support for using Unions

Posted by GitBox <gi...@apache.org>.
raducotescu commented on pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#issuecomment-706197961


   I've applied a slightly modified patch in https://github.com/apache/sling-org-apache-sling-graphql-core/pull/8, since my change from https://github.com/apache/sling-org-apache-sling-graphql-core/pull/7 made this PR unmergeable. Let's continue the discussion there.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] kozmaadrian commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
kozmaadrian commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500453330



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/SlingTypeResolverSelector.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import java.io.IOException;
+
+/**
+ * Selects a SlingTypeProvider used to get the corresponding object type,
+ * based on a name specified by a GraphQL schema directive.
+ */
+@Component(service = SlingTypeResolverSelector.class)
+public class SlingTypeResolverSelector {
+
+    /**
+     * Fetchers which have a name starting with this prefix must be
+     * under the {#link RESERVED_PACKAGE_PREFIX} package.
+     */
+    public static final String RESERVED_NAME_PREFIX = "sling/";
+
+    /**
+     * Package name prefix for fetchers which have names starting
+     * with the {#link RESERVED_NAME_PREFIX}.
+     */
+    public static final String RESERVED_PACKAGE_PREFIX = "org.apache.sling.";
+
+    private BundleContext bundleContext;
+
+    @Reference
+    private ScriptedDataFetcherProvider scriptedDataFetcherProvider;

Review comment:
       Replaced with `ScriptedTypeResolverProvider`, extending `getSlingTypeResolver` to call the scripted provider as fallback.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] raducotescu closed pull request #6: SLING-9796 - Add support for using Unions

Posted by GitBox <gi...@apache.org>.
raducotescu closed pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] bdelacretaz commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
bdelacretaz commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500833543



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/SlingTypeResolverSelector.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import java.io.IOException;
+
+/**
+ * Selects a SlingTypeProvider used to get the corresponding object type,
+ * based on a name specified by a GraphQL schema directive.
+ */
+@Component(service = SlingTypeResolverSelector.class)
+public class SlingTypeResolverSelector {
+
+    /**
+     * Fetchers which have a name starting with this prefix must be
+     * under the {#link RESERVED_PACKAGE_PREFIX} package.
+     */
+    public static final String RESERVED_NAME_PREFIX = "sling/";
+
+    /**
+     * Package name prefix for fetchers which have names starting
+     * with the {#link RESERVED_NAME_PREFIX}.
+     */
+    public static final String RESERVED_PACKAGE_PREFIX = "org.apache.sling.";
+
+    private BundleContext bundleContext;
+
+    @Reference
+    private ScriptedDataFetcherProvider scriptedDataFetcherProvider;
+
+    @Activate
+    public void activate(BundleContext ctx) {
+        bundleContext = ctx;
+    }
+
+    /**
+     * Return a SlingTypeResolver from the available OSGi services, if there's one
+     * registered with the supplied name.
+     */
+    @SuppressWarnings("unchecked")
+    private SlingTypeResolver<Object> getOsgiServiceFetcher(@NotNull String name) throws IOException {
+        SlingTypeResolver<Object> result = null;
+        final String filter = String.format("(%s=%s)", SlingTypeResolver.NAME_SERVICE_PROPERTY, name);
+        ServiceReference<?>[] refs = null;
+        try {
+            refs = bundleContext.getServiceReferences(SlingTypeResolver.class.getName(), filter);
+        } catch (InvalidSyntaxException ise) {
+            throw new IOException("Invalid OSGi filter syntax", ise);
+        }
+        if (refs != null) {
+            // SlingFetcher services must have a unique name
+            if (refs.length > 1) {
+                throw new IOException(String.format("Got %d services for %s, expected just one", refs.length, filter));
+            }
+            result = (SlingTypeResolver<Object>) bundleContext.getService(refs[0]);

Review comment:
       I suppose we can factor out the logic which is similar for this and for the SlingDataFetcher? And clean it up in a single place then.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] bdelacretaz commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
bdelacretaz commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500832606



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/ScriptedTypeResolverProvider.java
##########
@@ -0,0 +1,91 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.Servlet;
+
+/**
+ * Resolves a SlingTypeResolver name to a SlingScript if available.
+ */
+@Component(service = ScriptedTypeResolverProvider.class)
+public class ScriptedTypeResolverProvider {

Review comment:
       Do we really need a scripted type provider? I understand it exists here by analogy with the scripted SlingDataFetcher but I'm not sure about the use cases for it.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] raducotescu commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
raducotescu commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500949572



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/SlingTypeResolverSelector.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import java.io.IOException;
+
+/**
+ * Selects a SlingTypeProvider used to get the corresponding object type,
+ * based on a name specified by a GraphQL schema directive.
+ */
+@Component(service = SlingTypeResolverSelector.class)
+public class SlingTypeResolverSelector {
+
+    /**
+     * Fetchers which have a name starting with this prefix must be
+     * under the {#link RESERVED_PACKAGE_PREFIX} package.
+     */
+    public static final String RESERVED_NAME_PREFIX = "sling/";
+
+    /**
+     * Package name prefix for fetchers which have names starting
+     * with the {#link RESERVED_NAME_PREFIX}.
+     */
+    public static final String RESERVED_PACKAGE_PREFIX = "org.apache.sling.";
+
+    private BundleContext bundleContext;
+
+    @Reference
+    private ScriptedDataFetcherProvider scriptedDataFetcherProvider;
+
+    @Activate
+    public void activate(BundleContext ctx) {
+        bundleContext = ctx;
+    }
+
+    /**
+     * Return a SlingTypeResolver from the available OSGi services, if there's one
+     * registered with the supplied name.
+     */
+    @SuppressWarnings("unchecked")
+    private SlingTypeResolver<Object> getOsgiServiceFetcher(@NotNull String name) throws IOException {
+        SlingTypeResolver<Object> result = null;
+        final String filter = String.format("(%s=%s)", SlingTypeResolver.NAME_SERVICE_PROPERTY, name);
+        ServiceReference<?>[] refs = null;
+        try {
+            refs = bundleContext.getServiceReferences(SlingTypeResolver.class.getName(), filter);
+        } catch (InvalidSyntaxException ise) {
+            throw new IOException("Invalid OSGi filter syntax", ise);
+        }
+        if (refs != null) {
+            // SlingFetcher services must have a unique name
+            if (refs.length > 1) {
+                throw new IOException(String.format("Got %d services for %s, expected just one", refs.length, filter));
+            }
+            result = (SlingTypeResolver<Object>) bundleContext.getService(refs[0]);

Review comment:
       Yes - I opened https://issues.apache.org/jira/browse/SLING-9800 which besides the improvement regarding query execution should also optimised the interaction with the service registry.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] raducotescu commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
raducotescu commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500949572



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/SlingTypeResolverSelector.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import java.io.IOException;
+
+/**
+ * Selects a SlingTypeProvider used to get the corresponding object type,
+ * based on a name specified by a GraphQL schema directive.
+ */
+@Component(service = SlingTypeResolverSelector.class)
+public class SlingTypeResolverSelector {
+
+    /**
+     * Fetchers which have a name starting with this prefix must be
+     * under the {#link RESERVED_PACKAGE_PREFIX} package.
+     */
+    public static final String RESERVED_NAME_PREFIX = "sling/";
+
+    /**
+     * Package name prefix for fetchers which have names starting
+     * with the {#link RESERVED_NAME_PREFIX}.
+     */
+    public static final String RESERVED_PACKAGE_PREFIX = "org.apache.sling.";
+
+    private BundleContext bundleContext;
+
+    @Reference
+    private ScriptedDataFetcherProvider scriptedDataFetcherProvider;
+
+    @Activate
+    public void activate(BundleContext ctx) {
+        bundleContext = ctx;
+    }
+
+    /**
+     * Return a SlingTypeResolver from the available OSGi services, if there's one
+     * registered with the supplied name.
+     */
+    @SuppressWarnings("unchecked")
+    private SlingTypeResolver<Object> getOsgiServiceFetcher(@NotNull String name) throws IOException {
+        SlingTypeResolver<Object> result = null;
+        final String filter = String.format("(%s=%s)", SlingTypeResolver.NAME_SERVICE_PROPERTY, name);
+        ServiceReference<?>[] refs = null;
+        try {
+            refs = bundleContext.getServiceReferences(SlingTypeResolver.class.getName(), filter);
+        } catch (InvalidSyntaxException ise) {
+            throw new IOException("Invalid OSGi filter syntax", ise);
+        }
+        if (refs != null) {
+            // SlingFetcher services must have a unique name
+            if (refs.length > 1) {
+                throw new IOException(String.format("Got %d services for %s, expected just one", refs.length, filter));
+            }
+            result = (SlingTypeResolver<Object>) bundleContext.getService(refs[0]);

Review comment:
       Yes - I opened https://issues.apache.org/jira/browse/SLING-9800 which, besides the improvement regarding query execution, should also optimise the interaction with the service registry.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] raducotescu commented on a change in pull request #6: SLING-9796 - Add support for using Unions

Posted by GitBox <gi...@apache.org>.
raducotescu commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r502351919



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/ScriptedTypeResolverProvider.java
##########
@@ -0,0 +1,91 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.Servlet;
+
+/**
+ * Resolves a SlingTypeResolver name to a SlingScript if available.
+ */
+@Component(service = ScriptedTypeResolverProvider.class)
+public class ScriptedTypeResolverProvider {

Review comment:
       I talked offline with @bdelacretaz and we don't think that a `ScriptedTypeResolverProvider` makes sense for the following reasons:
   * it's hard to test by developers, requiring ITs
   * it's kind of cumbersome to write one




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] raducotescu commented on a change in pull request #6: SLING-9796 - Add support for using Unions

Posted by GitBox <gi...@apache.org>.
raducotescu commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r502351919



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/ScriptedTypeResolverProvider.java
##########
@@ -0,0 +1,91 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.Servlet;
+
+/**
+ * Resolves a SlingTypeResolver name to a SlingScript if available.
+ */
+@Component(service = ScriptedTypeResolverProvider.class)
+public class ScriptedTypeResolverProvider {

Review comment:
       I talked offline with @bdelacretaz and we don't think that a `ScriptedTypeResolverProvider` makes sense for the following reasons:
   * it's hard to test by developers, requiring ITs
   * it's kind of cumbersome to write one




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] raducotescu commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
raducotescu commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500220524



##########
File path: src/main/java/org/apache/sling/graphql/api/SlingTypeResolverEnvironment.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.api;
+
+import org.apache.sling.api.resource.Resource;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Provides contextual information to the {#link SlingDataFetcher}
+ */
+@SuppressWarnings("TypeParameterUnusedInFormals")
+
+@ProviderType
+public interface SlingTypeResolverEnvironment {
+
+    /**
+     * @return the current Sling resource
+     */
+    @Nullable
+    Resource getCurrentResource();
+
+    /**
+     * @return the options, if set by the schema directive
+     */
+    @Nullable
+    String getResolverOptions();
+
+    /**
+     * @return the source, if set by the schema directive
+     */
+    @Nullable
+    String getResolverSource();
+
+    /**
+     * @return the GraphQL result item
+     */
+    @Nullable
+    Object getObject();
+
+    /**
+     * @param <T> the type name
+     * @return the GraphQL Object Type
+     */
+    @Nullable <T> T getObjectType(String name);

Review comment:
       Can the `name` be null?

##########
File path: src/main/java/org/apache/sling/graphql/core/engine/ScriptedTypeResolverProvider.java
##########
@@ -0,0 +1,91 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.Servlet;
+
+/**
+ * Resolves a SlingTypeResolver name to a SlingScript if available.
+ */
+@Component(service = ScriptedTypeResolverProvider.class)
+public class ScriptedTypeResolverProvider {
+    public static final String SCRIPT_NAME = "resolver";
+    public static final String FAKE_RESOURCE_TYPE_PREFIX = "graphql/resolver/";
+
+    @Reference
+    private ServletResolver servletResolver;
+
+    private static class FakeResource extends AbstractResource {

Review comment:
       I know we have a similar class already - `org.apache.sling.graphql.core.engine.ScriptedDataFetcherProvider.FakeResource` - but couldn't we get rid of both and use a `org.apache.sling.api.resource.SyntheticResource` instead? (cc @bdelacretaz)

##########
File path: src/main/java/org/apache/sling/graphql/core/engine/SlingTypeResolverSelector.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import java.io.IOException;
+
+/**
+ * Selects a SlingTypeProvider used to get the corresponding object type,
+ * based on a name specified by a GraphQL schema directive.
+ */
+@Component(service = SlingTypeResolverSelector.class)
+public class SlingTypeResolverSelector {
+
+    /**
+     * Fetchers which have a name starting with this prefix must be
+     * under the {#link RESERVED_PACKAGE_PREFIX} package.
+     */
+    public static final String RESERVED_NAME_PREFIX = "sling/";
+
+    /**
+     * Package name prefix for fetchers which have names starting
+     * with the {#link RESERVED_NAME_PREFIX}.
+     */
+    public static final String RESERVED_PACKAGE_PREFIX = "org.apache.sling.";
+
+    private BundleContext bundleContext;
+
+    @Reference
+    private ScriptedDataFetcherProvider scriptedDataFetcherProvider;
+
+    @Activate
+    public void activate(BundleContext ctx) {
+        bundleContext = ctx;
+    }
+
+    /**
+     * Return a SlingTypeResolver from the available OSGi services, if there's one
+     * registered with the supplied name.
+     */
+    @SuppressWarnings("unchecked")
+    private SlingTypeResolver<Object> getOsgiServiceFetcher(@NotNull String name) throws IOException {
+        SlingTypeResolver<Object> result = null;
+        final String filter = String.format("(%s=%s)", SlingTypeResolver.NAME_SERVICE_PROPERTY, name);
+        ServiceReference<?>[] refs = null;
+        try {
+            refs = bundleContext.getServiceReferences(SlingTypeResolver.class.getName(), filter);
+        } catch (InvalidSyntaxException ise) {
+            throw new IOException("Invalid OSGi filter syntax", ise);
+        }
+        if (refs != null) {
+            // SlingFetcher services must have a unique name
+            if (refs.length > 1) {
+                throw new IOException(String.format("Got %d services for %s, expected just one", refs.length, filter));
+            }
+            result = (SlingTypeResolver<Object>) bundleContext.getService(refs[0]);

Review comment:
       While this follows an existing pattern in this bundle, it's not a clean approach. We increase the counter of held references for this service object and never allow them to be garbage collected (cc @bdelacretaz).

##########
File path: src/main/java/org/apache/sling/graphql/core/engine/SlingTypeResolverSelector.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import java.io.IOException;
+
+/**
+ * Selects a SlingTypeProvider used to get the corresponding object type,
+ * based on a name specified by a GraphQL schema directive.
+ */
+@Component(service = SlingTypeResolverSelector.class)
+public class SlingTypeResolverSelector {
+
+    /**
+     * Fetchers which have a name starting with this prefix must be
+     * under the {#link RESERVED_PACKAGE_PREFIX} package.
+     */
+    public static final String RESERVED_NAME_PREFIX = "sling/";
+
+    /**
+     * Package name prefix for fetchers which have names starting
+     * with the {#link RESERVED_NAME_PREFIX}.
+     */
+    public static final String RESERVED_PACKAGE_PREFIX = "org.apache.sling.";
+
+    private BundleContext bundleContext;
+
+    @Reference
+    private ScriptedDataFetcherProvider scriptedDataFetcherProvider;

Review comment:
       This reference doesn't seem to be used.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] bdelacretaz commented on pull request #6: [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
bdelacretaz commented on pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#issuecomment-704177255


   Could you create a https://issues.apache.org/jira/projects/SLING ticket so we can assign this to a release etc? Just a brief description of your use case there is good enough.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] bdelacretaz commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
bdelacretaz commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500831138



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/ScriptedTypeResolverProvider.java
##########
@@ -0,0 +1,91 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.api.resource.AbstractResource;
+import org.apache.sling.api.resource.Resource;
+import org.apache.sling.api.resource.ResourceMetadata;
+import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.scripting.SlingScript;
+import org.apache.sling.api.servlets.ServletResolver;
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import javax.servlet.Servlet;
+
+/**
+ * Resolves a SlingTypeResolver name to a SlingScript if available.
+ */
+@Component(service = ScriptedTypeResolverProvider.class)
+public class ScriptedTypeResolverProvider {
+    public static final String SCRIPT_NAME = "resolver";
+    public static final String FAKE_RESOURCE_TYPE_PREFIX = "graphql/resolver/";
+
+    @Reference
+    private ServletResolver servletResolver;
+
+    private static class FakeResource extends AbstractResource {

Review comment:
       SyntheticResource should work indeed, I agree




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [sling-org-apache-sling-graphql-core] kozmaadrian commented on a change in pull request #6: SLING-9796 [early review] Adds support for using Unions.

Posted by GitBox <gi...@apache.org>.
kozmaadrian commented on a change in pull request #6:
URL: https://github.com/apache/sling-org-apache-sling-graphql-core/pull/6#discussion_r500453330



##########
File path: src/main/java/org/apache/sling/graphql/core/engine/SlingTypeResolverSelector.java
##########
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.core.engine;
+
+import org.apache.sling.graphql.api.SlingTypeResolver;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+
+import java.io.IOException;
+
+/**
+ * Selects a SlingTypeProvider used to get the corresponding object type,
+ * based on a name specified by a GraphQL schema directive.
+ */
+@Component(service = SlingTypeResolverSelector.class)
+public class SlingTypeResolverSelector {
+
+    /**
+     * Fetchers which have a name starting with this prefix must be
+     * under the {#link RESERVED_PACKAGE_PREFIX} package.
+     */
+    public static final String RESERVED_NAME_PREFIX = "sling/";
+
+    /**
+     * Package name prefix for fetchers which have names starting
+     * with the {#link RESERVED_NAME_PREFIX}.
+     */
+    public static final String RESERVED_PACKAGE_PREFIX = "org.apache.sling.";
+
+    private BundleContext bundleContext;
+
+    @Reference
+    private ScriptedDataFetcherProvider scriptedDataFetcherProvider;

Review comment:
       Replaced with `ScriptedTypeResolverProvider, extending `getSlingTypeResolver` to call the scripted provider as fallback.

##########
File path: src/main/java/org/apache/sling/graphql/api/SlingTypeResolverEnvironment.java
##########
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.sling.graphql.api;
+
+import org.apache.sling.api.resource.Resource;
+import org.jetbrains.annotations.Nullable;
+import org.osgi.annotation.versioning.ProviderType;
+
+/**
+ * Provides contextual information to the {#link SlingDataFetcher}
+ */
+@SuppressWarnings("TypeParameterUnusedInFormals")
+
+@ProviderType
+public interface SlingTypeResolverEnvironment {
+
+    /**
+     * @return the current Sling resource
+     */
+    @Nullable
+    Resource getCurrentResource();
+
+    /**
+     * @return the options, if set by the schema directive
+     */
+    @Nullable
+    String getResolverOptions();
+
+    /**
+     * @return the source, if set by the schema directive
+     */
+    @Nullable
+    String getResolverSource();
+
+    /**
+     * @return the GraphQL result item
+     */
+    @Nullable
+    Object getObject();
+
+    /**
+     * @param <T> the type name
+     * @return the GraphQL Object Type
+     */
+    @Nullable <T> T getObjectType(String name);

Review comment:
       Removed `@Nullable`.




----------------------------------------------------------------
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:
users@infra.apache.org