How to use header in Ash graphql query?

I try to use AshGraphql to make my graphql endpoint. But I can’t find a way to make viewer query. Similar to viewer query in github graphql api, I try to return user type which related to token in header. But it seems like I can’t use header when i define graphql DSL. How can I make query which uses header values?

This is my user resource

defmodule Core.Account.User do
  use Ash.Resource,
    data_layer: AshPostgres.DataLayer,
    extensions: [AshAuthentication, AshGraphql.Resource]

  attributes do
    uuid_primary_key :id

    attribute :email, :ci_string, allow_nil?: false
    attribute :hashed_password, :string, allow_nil?: false, sensitive?: true

    timestamps allow_nil?: false
  end

  relationships do
    has_many :reviews, Core.Review.Review do
      api Core.Review
      destination_attribute :writer_id
    end
  end

  authentication do
    api Core.Account

    strategies do
      password :password do
        identity_field :email
        hashed_password_field :hashed_password
      end
    end

    tokens do
      enabled? true
      token_resource Core.Account.Token
      signing_secret fn _, _ ->
        Application.fetch_env(:core, :token_signing_secret)
      end
    end
  end

  actions do
    defaults [:read]

    create :sign_up do
      reject [:hashed_password]
      argument :password, :string, allow_nil?: false, sensitive?: true
      change {AshAuthentication.Strategy.Password.HashPasswordChange, strategy_name: :password}
    end
  end

  code_interface do
    define_for Core.Account

    define :sign_up, action: :sign_up, args: [:email, :password]
  end

  identities do
    identity :unique_email, [:email]
  end

  postgres do
    table "user"
    repo Core.Repo
  end
end

Thanks :slight_smile:

You can use the modify_resolution option to do this.

https://hexdocs.pm/ash_graphql/dsl-ashgraphql-resource.html#graphql-queries-get-modify_resolution

1 Like

Wow thanks. I lost my way in read_one but it’s in get lol