Git Product home page Git Product logo

Comments (3)

IvBre avatar IvBre commented on April 28, 2024

Seems like this is working, but I'm not sure if its ideal:
In the parent resolver return the DataFetcherResult instead of the actual result, together with localContext set with the data object you want to share down the tree line, in this example its the request argument.

@Query
fun foo(request: ProtoRequestParams): ProtoResult {
  return DataFetcherResult.newResult<ProtoResult>()
            .data(getData(request))
            .localContext(request)
            .build()
}

And then in the child field resolver:

@SchemaModification(addField = "specificProperty", onType = ProtoItem::class)
fun specificProperty(item: ProtoItem, dataFetchingEnvironment: DataFetchingEnvironment): CompletableFuture<List<ProtoSpecificProperty>>? {
  val argument = dataFetchingEnvironment.getLocalContext<ProtoRequestParams>()
  // use the argument to resolve this field
}

Note that this code examples are in Kotlin.

from rejoiner.

sheepdreamofandroids avatar sheepdreamofandroids commented on April 28, 2024

Hi

Maybe I'm misunderstanding but to me it feels wrong that the resolution of specificProperty would depend on anything other than the item that it is connected to.

Could it be that Input_proto_request_params contains some context info for your query that should be repeated as a parameter on specificProperty?

I'm trying to solve a similar problem myself a.t.m. I'm using a hierarchy of implicitly retrieved context, well known variables and explicit parameters to solve that but I'm not sure what is "the right way" here...

from rejoiner.

IvBre avatar IvBre commented on April 28, 2024

Hello,

Maybe I'm misunderstanding but to me it feels wrong that the resolution of specificProperty would depend on anything other than the item that it is connected to.

According to the GraphQL specs, this scenario should be possible. That a child inherits arguments from its parent.

Could it be that Input_proto_request_params contains some context info for your query that should be repeated as a parameter on specificProperty?

Exactly, specificProperty requires Input_proto_request_params as well as its parent.

I'm trying to solve a similar problem myself a.t.m. I'm using a hierarchy of implicitly retrieved context, well known variables and explicit parameters to solve that but I'm not sure what is "the right way" here...

I was also thinking to just add this requirement directly on the field, but then the client needs to duplicate this argument, which I would rather avoid. I've solved it by setting localContext, not sure if that's the right way to go though.

from rejoiner.

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.