Ask questionsReturn response fields based on the context

Need to return response based on the context.

This is my schema.ex

object(:user) do
    field :name, :string
    field :dob, :string
    field :test_1, dataloader(Repo)
    field :test_2, dataloader(Repo)
    field :test_3, dataloader(Repo)
    field :test_4, dataloader(Repo)
    field :test_5, dataloader(Repo)

def plugins do
    [Absinthe.Middleware.Dataloader | Absinthe.Plugin.defaults()]

  def context(ctx) do
    loader =
      |> Dataloader.add_source(Repo,
    Map.put(ctx, :loader, loader)

If the get_user API was hit by logged in user(By context, I was validating that). I will to return all the fields. The dataloader will do loading the associations job for me.

    name: "some name", 
    dob: "some dob", 
    test_1:  "some_test_1", 
    test_2: "some_test_2",
    test_3: "some_test_3",
    test_4: "some_test_4",
    test_5: "some_test_5"

If the same get_user API was hit by not logged user(Without token). I only want to return the “name” field from the backend!
    name: "some name", 
    dob: nil, 
    test_1:  nil, 
    test_2: nil,
    test_3: nil,
    test_4: nil,
    test_5: nil

How can i achieve this with dataloader?. Dataloader try to load all the association every time(If that particular field was passed from the frontend).


Answer questions iteron-yasir

@benwilson512 I've already asked same question in elixirforum But, I didn't get any solution. That's why I asked here. Can you help me with this


Related questions

No questions were found.
Github User Rank List