0

I was doing the Absinthe tutorial for Elixir using the howtographql.com website. At some point (https://www.howtographql.com/graphql-elixir/2-queries/), when running the last step of running the graphql server, I get an error.

Command executed:

$ iex -S mix phx.server

Output:

Erlang/OTP 22 [erts-10.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe] [dtrace]

warning: found quoted keyword "test" but the quotes are not required. Note that keywords are always atoms, even when quoted. Similar to atoms, keywords made exclusively of Unicode letters, numbers, underscore, and @ do not require quotes
  mix.exs:57

Compiling 4 files (.ex)

== Compilation error in file lib/community_web/schema.ex ==
** (CompileError) lib/community_web/schema.ex:17: undefined function field/3
    (elixir) lib/kernel/parallel_compiler.ex:229: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/7

This is how my lib/community_web/schema.ex looks like:

  1 defmodule CommunityWeb.Schema do
  2   use Absinthe.Schema
  3 
  4   alias CommunityWeb.NewsResolver
  5 
  6   object :link do
  7     field :id, non_null(:id)
  8     field :url, non_null(:string)
  9     field :description, non_null(:string)
 10   end
 11 
 12   query do
 13     field :all_links, non_null(list_of(non_null(:link)))
 14   end
 15 end
 16 
 17 field :all_links, non_null(list_of(non_null(:link))) do
 18   resolve &NewsResolver.all_links/3
 19 end

This is how my lib/community_web/resolvers/news_resolver.ex looks like:

  1 defmodule CommunityWeb.NewsResolver do
  2   alias Community.News
  3 
  4   def all_links(_root, _args, _info) do
  5     links = News.list_links()
  6     {:ok, links}
  7   end
  8 end

I was expecting that the server will get executed, as the tutorial states, but only the error message is shown.

Thanks!

Brett Beatty
  • 5,690
  • 1
  • 23
  • 37
fer
  • 1
  • 2

1 Answers1

0

Lines 17-19 in your lib/community_web/schema.ex don't belong. field/3 can only be used in an absinthe object, and you have it outside your module. My guess is you meant to put the do block on the field on line 13.

I would try replacing line 13 with lines 17-19 and see if that helps.

Brett Beatty
  • 5,690
  • 1
  • 23
  • 37
  • I thought it looked odd that piece of code over there too, but sadly moving lines 17-19 to line 13 causes an error about the schema, that shows a [generic error message about the schema](https://pastebin.com/amwMH6vV). – fer Sep 25 '19 at 12:18
  • When you moved those lines it looked like the [example from your tutorial](https://github.com/howtographql/graphql-elixir/blob/master/lib/community/web/schema.ex)? – Brett Beatty Sep 25 '19 at 16:54