Skip to content

Multiple graphql servlets in OSGi context #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dhermanson opened this issue Nov 22, 2019 · 5 comments · Fixed by #237
Closed

Multiple graphql servlets in OSGi context #218

dhermanson opened this issue Nov 22, 2019 · 5 comments · Fixed by #237

Comments

@dhermanson
Copy link

Hello,

Thank you for this fantastic library. I am using this library in an OSGi runtime, specifically Apache Karaf. I have a use case for which I want to run more than one instance of a graphql servlet. Having a single graphql servlet doesn't fit my needs. So I'm running into a problem where it doesn't make sense for OsgiGraphQLHttpServlet to register itself as an OSGi component.

Now, I'm somewhat new to OSGi. I started using it about 8 months ago. Perhaps there is some way for me to disable that specific component that I'm not aware of. What I've done is fork this repository and essentially remove the @Component annotation on OsgiGraphQLHttpServlet. Actually, I think I might've deleted OsgiGraphQLHttpServlet entirely.

I get that it is very useful for someone to pull in this library and have a working graphql servlet in an OSGi context. But, unless there's an OSGi trick which would allow me to disable the OsgiGraphQLHttpServlet that I'm not aware of yet (please inform me if that's the case), my current approach is to fork this library and remove that file, so I can have multiple graphql servlets.

Now, I understand that the existence of the OsgiGraphQLHttpServlet doesn't prohibit me from creating additional graphql servlets. But I don't really like having it registered as a servlet if it doesn't make sense for my purposes.

Would it be possible to remove the @Component from the OsgiGraphQLHttpServlet, so that it wouldn't be registered by default? I'm just thinking that anyone who is running in an OSGi context would know what they need to do to wire it up properly.

If my needs don't fit with the goals of the project, I understand. I will happily maintain my fork. I just thought I'd express my use case, because I imagine others may be experiencing it as well.

Thanks

@oliemansm
Copy link
Member

I don't have any experience with OSGi myself. Ideally it would be configurable where the default behavior remains as-is, but through some kind of configuration it could be disabled. Is that possible somehow?

What if we we would move that class into a separate module that people would have to add as a dependency explicitly? I'm open to PRs for this, as long as there's accompanying documentation for other users what changes they need to make to get the same behavior they have now.

@benfortuna
Copy link
Contributor

Hi. I've just added a PR (#237) that provides the ability to configure multiple graphql servlets in OSGi.

Note that the impact to existing functionality is that there is no longer a default servlet deployed on startup, but this can be rectified by added an appropriate configuration as part of the boot config.

@oliemansm oliemansm linked a pull request Mar 20, 2020 that will close this issue
@oliemansm
Copy link
Member

@benfortuna @dhermanson
Because of this issue the servlet is no longer deployed automatically on startup as you've both mentioned. How can this be configured as part of the boot config that you mention here? I'm trying to get it to work in the example but I can't figure out how to make it work.

@benfortuna
Copy link
Contributor

benfortuna commented Jan 14, 2021

@oliemansm apologies for delayed response. I'm not too familiar with Karaf (I'm using Apache Sling) but I'll have a look at the example and see if I can provide a configuration to start the default servlet.

ps. If you have the Felix console available you can create a new configuration in configMgr:

image

And then use httpservice to verify the servlet is registered:

image

@benfortuna
Copy link
Contributor

In Apache Sling to create a default graphql servlet on startup I create a factory configuration like this:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants