title: Elixir, Absinthe How can I get user created after a date with absinthe?
body: <p>I am trying to get users that were created before/after certain date and I get this error. </p>
  
  <p>"message": "Argument \"filter\" has invalid value $filter.\nIn field \"insertedAfter\": Expected type \"NaiveDateTime\", found \"2018-05-13\".",</p>
  
  <p>The error makes sense since "2018-05-13" is not NativeDateTime... However, I thought NativeDateTime should parse the string "2018-05-13". I am trying to apply what I learned from a book but having hard time. I also created a custom date scalar but I basically encountered the same error.</p>
  
  <p>How can I accomplish being able to search user created after certain date with phoenix and absinthe?</p>
  
  <pre><code>query($filter: UserFilter){
    allUsers(filter: $filter){
      id
      firstName
      lastName
    }
  }
  
  values
  {
    "filter": {
      "insertedAfter": "2018-05-13"
    }
  }
  </code></pre>
  
  <p>Ecto schema, account > user.ex</p>
  
  <pre><code>schema "users" do
    field :avatar_img, :string
    field :email, :string, null: false
    field :fb_token, :string
    field :first_name, :string
    field :google_token, :string
    field :last_name, :string
    field :password, :string, null: false
    field :admin_user_id, :string
  
    timestamps()
   end
  </code></pre>
  
  <p>types.ex</p>
  
  <pre><code> use Absinthe.Schema.Notation
   use Absinthe.Ecto, repo: ElixirBlog.Repo
   import_types Absinthe.Type.Custom
  
   object :user do
    field :id, non_null(:id)
    field :first_name, non_null(:string)
    field :last_name, non_null(:string)
    field :email, non_null(:string)
    field :password, non_null(:string)
    field :avatar_img, :string
    field :admin_user_id, :string
    field :fb_token, :string
    field :google_token, :string
    field :inserted_at, :naive_datetime
    field :updated_at, :naive_datetime
  end
  </code></pre>
  
  <p>Absinthe schema
  schema.ex</p>
  
  <pre><code>use Absinthe.Schema
  import_types Elixir.Schema.Types
  
  input_object :user_filter do
    field :id, :integer
    field :first_name, :string
    field :last_name, :string
    field :email, :string
    field :inserted_before, :naive_datetime
    field :inserted_after, :naive_datetime
  end
  
  query do
    field :all_users, list_of(:user) do
     arg :filter, :user_filter
     arg :order, type: :sort_order, default_value: :asc
     resolve &amp;ElixirBlogWeb.UsersResolver.all_users/3
    end
  end
  </code></pre>
  
  <p>users_resolver.ex</p>
  
  <pre><code>alias Elixir.Account
  
  def all_users(_root, args, _info) do
   users = Account.list_users(args)
   {:ok, users}
  end
  </code></pre>
  
  <p>account.ex</p>
  
  <pre><code>def list_users(args) do
    args
    |&gt; Enum.reduce(User, fn
      {:order, order}, query -&gt;
      query |&gt; order_by({^order, :first_name})
      {:filter, filter}, query -&gt;
        query |&gt; filter_with(filter)
      end)
    |&gt; Repo.all
  end
  
  defp filter_with(query, filter) do
    Enum.reduce(filter, query, fn
      {:id, id}, query -&gt;
        from q in query, where: q.id == ^id
      {:first_name, first_name}, query -&gt;
        from q in query, where: ilike(q.first_name, ^"%#{first_name}%")
      {:last_name, last_name}, query -&gt;
        from q in query, where: ilike(q.last_name, ^"%#{last_name}%")
      {:email, email}, query -&gt;
        from q in query, where: ilike(q.email, ^"%#{email}%")
      {:inserted_before, date}, query -&gt;
        from q in query, where: q.inserted_at &lt;= ^date
      {:inserted_after, date},  query -&gt;
        from q in query, where: q.inserted_at &gt;= ^date
   end)
  end
  </code></pre>
  
  <p>mix.exs</p>
  
  <pre><code>  {:phoenix, "~&gt; 1.3.2"},
    {:phoenix_ecto, "~&gt; 3.2"},
    {:absinthe, "~&gt; 1.4"},
    {:absinthe_plug, "~&gt; 1.4"},
    {:absinthe_ecto, "~&gt; 0.1.3"},
  </code></pre>