Skip to content

Have a factory for more dynamic runtime wiring  #419

Closed

Description

@bbakerman

The IDL can have directives and comments which could be used to inform what data fetcher etc.. to use

Imagine

type Foo {
      fieldX : String @dataFetcher(dataFetcher : "theDFToUse")
}

The current runtime only allows static name -> resolver

Activity

  1. added this to the 3.0.0 milestone on May 14, 2017
  2. andimarek commented on May 14, 2017

    @andimarek
    Member

    @bbakerman is there a graphql-js or spec reference?

  3. bbakerman commented on May 15, 2017

    @bbakerman
    MemberAuthor

    No its not spec - other than directives are in the spec to allow customisation by an engine.

    The use of a "data fetcher factory" therefore allows you to look at the environment (from IDL from or from whatever takes your fancy) and allows you to switch in new DataFetchers rather than pure static wiring.

    I have the use case in mind of using IDL directives to allow Schema specifiers to "specify" what they want perhaps by class name fieldX : String @dataFetcher(dataFetcher : "com.company.SecurityEnforcingDataFecter")

  4. ieugen commented on May 15, 2017

    @ieugen

    I second this. This will make using Dependency injection frameworks a lot more easily. You could let the framework build the components and then wire them into graphql.

    Think about CDI/ Spring / Guice building the data fetchers and then the runtime injecting them by name/type in the proper place.

    This can also allow AOP by means of adding directives that force some behaviors in a declarative way.

    I believe this is quite an useful feature. Code generating libraries like graphql-apigee can benefit as well.

  5. dh94 commented on May 15, 2017

    @dh94
    Contributor

    I'm not sure this is a good thing,
    i think it's nice to have the api decoupled from the implementation completely,
    and with adding this directive you tightly couple them together.

  6. added a commit that references this issue on May 18, 2017
  7. added a commit that references this issue on May 18, 2017
  8. andimarek commented on May 19, 2017

    @andimarek
    Member

    @dh94 this features doesn't enforce any tight coupling between the schema and the implementation. Yes, you can use it to to build something like @bbakerman suggested: adding meta informations (via directives) for DataFetchers and TypeResolvers. But you could also use it to select the DataFetcher based on some naming of the types for example.

    In general it is just a way to connect schema and Implementation when the schema is created. It gives you more flexibility, if you need it or prefer it.

  9. andimarek commented on May 19, 2017

    @andimarek
    Member

    merged

  10. vtahlani commented on Jun 13, 2017

    @vtahlani

    Do you have example for using dataFetcher directive. Below is my IDL schema

    schema {
        query: QueryType
    }
    
    type QueryType {
        getUser: User@dataFetcher(dataFetcher : "new com.test.data.User()")
    }
    
    interface User {
    	userId: ID
    	, UserName: String
    	, Friends: [User]
    	
    }
    

    Schema get loaded successfully but looks like dataFetch not working.

    Can we write custom function as part of dataResolver, the way we can do it with graphql-js? Can we call javaScript functions?

  11. ieugen commented on Jun 13, 2017

    @ieugen
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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions