Elixir 1.7.4, Absinthe compilation error: The root query type must be implemented and be a of type Object

I am receiving below error at mix compile. I tried to downgrade but received error on Mac. Help please…

$ brew switch elixir 1.6.6
Error: elixir does not have a version "1.6.6" in the Cellar.
elixir installed versions: 1.7.4

I am at Elixir 1.7.4 and deps are

      {:absinthe, "~> 1.4.0"},
      {:absinthe_plug, "~> 1.4.0"},
      {:absinthe_ecto, "~> 0.1.3"},

The root query type must be implemented and be a of type Object

  #Example
  defmodule MyApp.Schema do
    use Absinthe.Schema

    query do
      #Fields go here
    end
  end

From the graqhql schema specifiation

A GraphQL schema includes types, indicating where query and mutation
operations start. This provides the initial entry points into the type system.
The query type must always be provided, and is an Object base type. The
mutation type is optional; if it is null, that means the system does not
support mutations. If it is provided, it must be an object base type.

Reference: https://facebook.github.io/graphql/#sec-Initial-types

lib/absinthe/schema.ex:271: Absinthe.Schema.__after_compile__/2
(stdlib) lists.erl:1263: :lists.foldl/3
(stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
(elixir) lib/kernel/parallel_compiler.ex:206: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

Please take a look at this post:

Thank you for quick response. I am new to Elixir world and not used to the terminology yet.

Do you mean Elixir V1.7.0-rc.0 release fixed Absinthe compilation bug? My Elixir is 1.7.4 and believe higher version than V1.7.0-rc.0.

Confused now, appreciate more info.

@Hanums Looks like that absinthe is not yet ready for Elixir > 1.6.6. Try installing 1.6.6 version of Elixir and let us know if that solves your problem.

If I remember that topic well absinthe used some Elixir private API which have been changed. Also absinthe probably had planned big rework, but I’m not following it and I’m not sure if it’s done now.

If you want to give a try with 1.7.4 then you would need to try special git branch for new version of Elixir. Please see Git options ( :git ) documentation page which describes how to use such options properly.

I have been using Absinthe 1.4 with Elixir > 1.7

Here is my dependencies (Do not use 1.4.0, prefer 1.4)

      {:ecto, "~> 3.0", override: true},
      #
      {:absinthe, "~> 1.4"},
      {:absinthe_plug, "~> 1.4"},
      {:absinthe_ecto, "~> 0.1.3"},
      {:absinthe_relay, "~> 1.4"},
      {:absinthe_phoenix, "~> 1.4"},

I am overriding ecto because absinthe_relay requires ecto 2, but that is not required if You don’t use relay.

At least You need one query inside the query block. For example, You can try this…

  query do
    field :hello, :string do
      resolve fn _, _ -> {:ok, "world!"} end
    end
  end

In graphiql, You can query

{
  hello
}

And this would be the result.

{
  "data": {
    "hello": "world!"
  }
}

Do not forget to specify the json encoder in your router…

  scope "/" do
    pipe_through :api

    # Note: downloaded from CDN!
    forward "/graphiql",
      Absinthe.Plug.GraphiQL,
      schema: GraphqlWeb.Schema,
      json_codec: Jason
  end
1 Like

Absinthe absolutely supports Elixir 1.7. However, you need one of the latest versions. @Hanums you should mix deps.update absinthe.

4 Likes

My bad - this question just reminded me this old issue and I just checked if 1.7-issue branch is still there and it is. I had just took a look at branches details and found:

1.7-issue Updated 6 months ago by benwilson512

2 Likes

Thank you Benwilson512 and code compiled successfully, but Error Absinthe.Schema.Error still persists. Now I am in the process of testing GraphQL and will post updates.

If you do mix deps|grep absinthe what version do you show?

warning: found quoted keyword “test” but the quotes are not required. Note that keywords are always atoms, even when quoted, and quotes should only be used to introduce keywords with foreign characters in them
mix.exs:76

  • absinthe 1.4.13 (Hex package) (mix)
    locked at 1.4.13 (absinthe) 81eb2ff4
  • absinthe_plug 1.4.5 (Hex package) (mix)
    locked at 1.4.5 (absinthe_plug) f63d52a7
  • absinthe_ecto 0.1.3 (Hex package) (mix)
    locked at 0.1.3 (absinthe_ecto) 420b6812

an you rm -rf _build ?

1 Like

I am very new to Elixir and Phoenix world and I am so sorry did not get the question.

Please guide how can I check in my environment and I am happy to provide information.

What Ben recommended to you is not Elixir-specific. It’s a Linux command.

Delete your _build and deps directories (at the root of your project) and then execute this:

mix do deps.get, compile
2 Likes

Oh, got it. I will try it later as I am not confident on my Elixir and Phoenix skills yet. App was developed and I am enhance it, hesitant to modify large piece of of the app at this time.

Thank you much for the help, awesome forum!

After upgrading Erlang to 21.2.4 and Elixir to 1.7.4 (from 1.6.6), I got compilation errors. Versions before:

* absinthe 1.3.2 (Hex package) (mix)
  locked at 1.3.2 (absinthe) 1d16ee5c
* absinthe_plug 1.3.1 (Hex package) (mix)
  locked at 1.3.1 (absinthe_plug) e97c9faa
* absinthe_ecto 0.1.2 (https://github.com/absinthe-graphql/absinthe_ecto.git) (mix)

Versions after (mix.exs):

      {:absinthe, "~> 1.4"},
      {:absinthe_plug, "~> 1.4"},
      {:absinthe_ecto, "~> 0.1.3"},

…and in mix.lock:

* absinthe 1.4.13 (Hex package) (mix)
  locked at 1.4.13 (absinthe) 81eb2ff4
* absinthe_plug 1.4.6 (Hex package) (mix)
  locked at 1.4.6 (absinthe_plug) ac5d2d3d
* absinthe_ecto 0.1.3 (Hex package) (mix)
  locked at 0.1.3 (absinthe_ecto) 420b6812

…I can confirm the project compiles and works under Elixir 1.7.4.

Please show the errors.

My bad. This is with Elixir 1.7.4.

Versions:

$ grep absinthe mix.lock 
  "absinthe": {:hex, :absinthe, "1.3.2", "1d16ee5ceeb8b90e37f936b924caacc099b9da667e9c7e6a4d729f41197123d4", [:mix], [], "hexpm"},
  "absinthe_ecto": {:git, "https://github.com/absinthe-graphql/absinthe_ecto.git", "6c199e4e06568446e2de2e5731b74e2e388c94a1", []},
  "absinthe_plug": {:hex, :absinthe_plug, "1.3.1", "e97c9faa6a2e29be181205d994c3ca2e2c5c5dec38aea69fcd324407f6c163c6", [:mix], [{:absinthe, "~> 1.3.0", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.2 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"},

I removed the path and module name. Compilation error:

== Compilation error in file lib/.../schema.ex ==
** (Absinthe.Schema.Error) Invalid schema:
Elixir.<...>.Schema:0: The root query type must be implemented and be a of type Object
  
  
  #Example
  defmodule MyApp.Schema do
    use Absinthe.Schema
  
    query do
      #Fields go here
    end
  end
  
  --------------------------------------
  From the graqhql schema specifiation
  
  A GraphQL schema includes types, indicating where query and mutation
  operations start. This provides the initial entry points into the type system.
  The query type must always be provided, and is an Object base type. The
  mutation type is optional; if it is null, that means the system does not
  support mutations. If it is provided, it must be an object base type.
  
  Reference: https://facebook.github.io/graphql/#sec-Initial-types


    lib/absinthe/schema.ex:230: Absinthe.Schema.__after_compile__/2
    (stdlib) lists.erl:1263: :lists.foldl/3
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6
    (elixir) lib/kernel/parallel_compiler.ex:206: anonymous fn/4 in Kernel.ParallelCompiler.spawn_workers/6

Can you show your schema at all? Does an rm -rf _build help?

I’ll poke you in private.

No, full recompilation with cleaning up the directories beforehand doesn’t help. That’s why I took a while – tried it several times.

Oh you’re actually on Absinthe 1.3.2? That simply won’t work on 1.7.4. Elixir changed some details about how module attributes worked that absinthe was accidentally relying on. You need to upgrade to 1.4.13.

2 Likes