Skip to content

Make graphql-java have a multi module project structure #336

Closed

Description

@bbakerman

By having multiple modules, the project will be able to offer JDK8 specific modules and also split the main API for the execution api

The directory split would be something like

graphql-java
api
execution
java8

Activity

  1. bbakerman commented on Feb 28, 2017

    @bbakerman
    MemberAuthor

    I had a go at this and the dependencies are execution are a bit skew if at the moment

    I split into

    graphql-java-api
    graphql-java-execution

    For example graphql.execution.ExecutionStrategy is used by graphql.GraphQL both as an interface and it will slip in implementation classes such as SimpleExecutionStrategy.

    We can split out "execution" say without re-arranging these code deps.

    This got me thinking - what are we trying to achieve with multi module?

    Is it jdk6 / jdk8 split - that is code that runs on the base jdk6 base and some new code that is jdk8?

    If thats the case we can simplify by having one main "api" dep and a separate "jdk8" only sub module

  2. dminkovsky commented on Feb 28, 2017

    @dminkovsky
    Contributor

    This got me thinking - what are we trying to achieve with multi module?

    Is it jdk6 / jdk8 split - that is code that runs on the base jdk6 base and some new code that is jdk8?

    Yes, for me it's the JDK6/8 split.

    Also, I know some people are using just the language features (i.e. @hepin1989 at Taobao) and have written their own execution code.

    If I had time to do this split right now, I would separate out the (i) language and then (ii) parts of the execution framework that would be common to all execution strategies (coercing enum, coercing scalars, things like that).

  3. dminkovsky commented on Feb 28, 2017

    @dminkovsky
    Contributor

    Because if you look at all the execution strategies, they all copy paste that coercing code and complete value code one way or another.

  4. He-Pin commented on Feb 28, 2017

    @He-Pin

    I think we could split it to these modules:

    • QueryParser
    • SchemaIDLParser
    • SchemaAST and Builders
    • Introspection
    • ExcutionStrategySPI and default implememt
    • AsyncExcutionStrategy for java 8

    With this kind of structure,I think this will greatly help the commnity.

  5. aschrijver commented on Mar 2, 2017

    @aschrijver
    Contributor

    I think the Relay code should also merit a separate module (or even a separate project) There are more client implementations such as Apollo Client.

  6. andimarek commented on Mar 10, 2017

    @andimarek
    Member

    We are discussing the general Java 8 topic here: #338

  7. andimarek commented on Apr 10, 2017

    @andimarek
    Member

    The initial motivator for breaking up is now obsolete: We switched to Java 8.

    @dminkovsky Do you think it should still be done?
    The most obvious candidate is probably the relay package imho: this should really live in its own module. ( @aschrijver )

  8. dminkovsky commented on Apr 10, 2017

    @dminkovsky
    Contributor
  9. dminkovsky commented on Apr 17, 2017

    @dminkovsky
    Contributor

    And then you have PRs like #360 that actually improve the Relay support. So perhaps I'm just not a visionary :).

  10. dminkovsky commented on Apr 18, 2017

    @dminkovsky
    Contributor
  11. added 2 commits that reference this issue on May 2, 2017
  12. bbakerman commented on May 24, 2017

    @bbakerman
    MemberAuthor

    Closing this for now as its mostly been addressed.

    I appreciate that there are some other reasons for an extra module such as breaking out relay support but in general I dont think its worth it right now and good issue hygeine says close issues you are not doing

  13. smyrick commented on Jan 3, 2020

    @smyrick
    Contributor

    @bbakerman Would this issue be relevant still? In graphql-kotlin we have discussed being able to have more of the execution implemented in a kotlin way so that we can take full advantage of things like coroutines and Flow. However graphql-java has lots of features that we wouldn't want to reimplement like the parser and ast.

    Would this be something that would be considered so that graphql-java could be the core GraphQL JVM library to use? Then we could reuse some of the modules in client side libraries as well.

  14. andimarek commented on Jan 3, 2020

    @andimarek
    Member

    @smyrick can you explain it a bit more why multiple modules/project would help you? which client side are you referring to? Which dependency makes it problematic for you to just use the parts you are interested in and ignore the rest? (GraphQL Java has intentionally no "real" dependency)

    We still have the idea of splitting graphql java up one day, but it is not a concrete plan at the moment. It would be great to understand better how it would benefit you.

    Thanks

  15. smyrick commented on Jan 6, 2020

    @smyrick
    Contributor

    +cc @dariuszkuc

    In our library, we would like to have a pure Kotlin execution strategy of the schema. This way we can take full advantage of coroutines. Once we build a schema, we are basically limited right now of not going any deeper than calling graphql-java GraphQL.executeAsync(). Building a schema object does not need to be in a Kotlin implementation, but executing reuses a lot of the same code is not sharable today. We wouldn't want to do an entire rewrite of the library in Kotlin just for the added benefit in execution, so if graphql-java was more modular we could reuse your schema/query parser, schema objects, and printers but implement our own execution.

    Then beyond our library for the server side, I am sure that other libraries, client and server side, (See apollo-android-compiler) would love to also share things like a common lexer and parser.

  16. smyrick commented on Jan 31, 2020

    @smyrick
    Contributor

    @andimarek Looking at the existing folder structure and packages there are a couple areas where you could publish standalone libraries and these could be re-used and built upon by others using the JVM in the GraphQL community

    • execution

      • This module is already pretty well self contained and is only consumed up by the root level. It does consume other parts like schema and language but those can also be other modules.
    • schema

      • This is going to be a fairly large module and consumed by many but the point of separation here is that defining all the schema objects and their structure and rules for the GraphQL spec is separate from the execution module or the analysis module. The schema printer could even be its own module or just bundled here
    • analysis

      • Already on it's own, just consuming others so easily separated
    • relay

      • Already on it's own, just consuming others so easily separated
    • parser, language, util, introspection and others

      • I view these as part of the core library as they are used by all other modules. As a first attempt to split the library this would probably just be called graphql-java-core and contain everything that doesn't fit in the above categories

    Then end result could be that the modules are published as a separate library but then you still can have a module called graphql-java that just depends on all the others to provide a single dependency for those that want a simplified version. Separating into different modules would make separation a little easier for maintainers and allow for sub-version updates if you wanted too.

    Would the maintainers still be interested in pursuing this idea?

  17. bbakerman commented on Feb 3, 2020

    @bbakerman
    MemberAuthor

    I have previously had a go at splitting the graphql-java execution when we did the nextgen execution strategy and again when we did the Nadel entry point.

    I will agree that as is its difficult to invent new execution strategies that are significantly different to the ones provided.

    They key coupling points are the GraphQL class to ExecutionStrategy and also a three way coupling between GraphQL, ExecutionStrategy and Instrumentation.

    The GraphQL class by design is a major coupling point. Its the input, the doc parsing, the execution, the validation rules and so on all as one entry point. I think
    this coupling is good however I think we need to take those common aspects of it and put them into new subclasses so they can be more easily re-used

    This was the code that I copied twice during nextgen/nadel new entry points. I think this proves how it needs to be made into more re-useable components.

    The other major coupling is that Instrumentation is ExecutionStrategy dependent and completely coupled to that implmentation. By its very nature the Instrumentation
    has callback methods that suit the ExecutionStrategy and hence they cannot easily be re-used between new ExecutionStrategy implemenations. Again
    we can confirm this via the nextgen/nadel exercises.

    I think we should make a breaking change and make ExecutionStrategy and Instrumentation interfaces with very light shapes. This way the GraphQL
    class can hold them and later code can "up cast" them to known shapes as they need to.

    The challenge with Instrumentation is parsing (eg onParse) and validation (onValidation) and then and common entry point of onExecution. Perhaps there can be the
    same instrumentExecutionInput / instrumentExecutionResult style methods left in place.

    I dont think we need to make graphql-java a multi module code base to achieve this. I will grant that multi modulee allows you to better confirm
    depedencies directions but its not essential. Its a lot easier to work on a single moduke code base for sure.

    cc: @andimarek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions