Elixir GraphİQL api

I’m new to Graphql api potions, why am I not getting results when I type my code layout header body?

schema.ex:

defmodule CommunityWeb.Schema do

  use Absinthe.Schema

  alias CommunityWeb.NewsResolver

  object :link do

    field :id, non_null(:id)

    field :title, non_null(:string)

    field :body, non_null(:string)

  end

  query do

    @desc "Get all links"

    field :all_links, non_null(list_of(non_null(:link))) do

    resolve(&NewsResolver.all_links/3)

  end
end
end
**repo/seed.ex:**

alias Community.News.Link

alias Community.Repo

%Link{title: "titlee", body: "The Best Query Language"} |> Repo.insert!

%Link{title: "titleeee2", body: "Awesome GraphQL Client"} |> Repo.insert!

news.resolver.ex:

defmodule CommunityWeb.NewsResolver do

  alias Community.News

  def all_links(_root, _args, _info) do

    {:ok, News.list_links()}

  end

end

ERROR!

{
  "data": null,
  "errors": [
    {
      "locations": [
        {
          "column": 5,
          "line": 3
        }
      ],
      "message": "Cannot return null for non-nullable field",
      "path": [
        "allLinks",
        0,
        "body"
      ]
    }
  ]
}

According to the error, the first element of the list has body field which is null, but you specified in object :link that this field is non-nullable

1 Like