Giter VIP home page Giter VIP logo

Comments (11)

ashu-walmart avatar ashu-walmart commented on June 30, 2024 4

Will this PR help? #83.

from graphql-java-servlet.

freedomljc avatar freedomljc commented on June 30, 2024 1

@vojtechhabarta 's diff could help the GraphQLServlet to have per-request instrumentation.
Besides that, we need to add the dataloader into instrumentation.
To enable dataloader per request, GraphQLContext could be the best place to instantiate the dataloaders inside.

Ideas:

  1. Add DataLoaderRegistry into the GraphQLContext.

public class GraphQLContext {
....
protected Optional dataloaderRegistry;
public GraphQLContext(Optional request, Optional response, Optional dataloderRegistry) {
this.request = request;
this.response = response;
this.dataloaderRegistry = dataloaderRegistry;
}
....
}

  1. Create a new class ContextA to inherit the GraphQLContext:

public class ContextA extends GraphQLContext{
public ContextA() {
...
Dataloader<Object, Object> dataloaderA = new Dataloader<>();
DataLoaderRegistry registry = new DataLoaderRegistry();
this.registry.put("A", dataloaderA)
}

public CompleteFuture<A> loadAValue(Object key) {
	return this.registry.get("A").get(Key);
}

}

  1. Create a new class InstrumentationProviderA to inherit the InstrumentationProvider (based on @vojtechhabarta 's diff), then be able to connect the dataloader with the object .
    public class InstrumentationProviderA implements InstrumentationProvider {
    public Instrumentation getInstrumentation(GraphQLContext context) {
    DataLoaderDispatcherInstrumentation dispatcherInstrumentation = new DataLoaderDispatcherInstrumentation(context.dataloaderRegistry);
    return dispatcherInstrumentation;
    }
    }

from graphql-java-servlet.

apottere avatar apottere commented on June 30, 2024

Would it make sense to always add the DataLoaderDispatcherInstrumentation when the context has a DataLoaderRegistry? i.e. should it pass the context to the InstrumentationProvider or should it get the instrumentation provided by the InstrumentationProvider and then add the DataLoaderDispatcherInstrumentation to it automatically?

from graphql-java-servlet.

vojtechhabarta avatar vojtechhabarta commented on June 30, 2024

Always adding DataLoaderDispatcherInstrumentation when the context has a DataLoaderRegistry would probably make sense, I think. But I don't know what exactly you mean. Something similar to what I tried in mentioned commit? In 60f1093 I added GraphQLContext parameter to InstrumentationProvider.getInstrumentation() method.

Or are you thinking about supporting DataLoaderDispatcherInstrumentation automatically and adding DataLoaderRegistry field to GraphQLContext?

from graphql-java-servlet.

vojtechhabarta avatar vojtechhabarta commented on June 30, 2024

I would like to solve this problem somehow.

I have 2 use cases:

  • Objects that can be cached regardless the user accessing the data for some amount of time. For this use case current support for DataLoaders is sufficient, moreover this can also be solved using arbitrary cache.
  • Object that can be cached only per user request. Here I cannot use normal cache. Since the structure is relatively complex and one object can appear on different levels of result it would be really beneficial to have per-request cache.

Any idea, solution, hack...?

from graphql-java-servlet.

vincentDAO avatar vincentDAO commented on June 30, 2024

@vojtechhabarta, @freedomljc I LOVE your ideas to implement "instrumentation per request" .

Our project is using @deprecated BatchedExecutionStrategy we want to change to use DataLoader but stuck at configure DataLoader per request.

Have you guys tried to implement it?

from graphql-java-servlet.

vojtechhabarta avatar vojtechhabarta commented on June 30, 2024

I haven't implemented it. I thought somebody who understands better than me how GraphQL in Java works should do it 😏

from graphql-java-servlet.

vincentDAO avatar vincentDAO commented on June 30, 2024

@ashu-walmart, hopefully your PR is reviewed and merged soon.

from graphql-java-servlet.

kdlan avatar kdlan commented on June 30, 2024

I make a pull request graphql-java/graphql-java#1171 for this

with Supplier<DataLoaderRegistry>, DataLoaderDispatcherInstrumentation can get a request-scoped DataLoaderRegistry and FieldLevelTrackingApproach

from graphql-java-servlet.

oliemansm avatar oliemansm commented on June 30, 2024

@ashu-walmart et al. Anything still needed for this in this project? PR #83 has been merged. So like to know if there's still some functionality missing we need to implement. Also, if you're able to write a small readme explaining this feature for future reference would be much appreciated.

from graphql-java-servlet.

ashu-walmart avatar ashu-walmart commented on June 30, 2024

@oliemansm, This works for me now and am using the feature in my project. I will write a readme describing the feature. Thanks!

from graphql-java-servlet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.