Reusing Imported GraphQL Type Definitions in Absinthe

Hey @tres. import_types should generally only be used from the root level Schema. The Schema is ultimately a single namespace, and no checking of types is done until the schema itself is built. In other words just do:

defmodule DerpWeb.Schema do
  use Absinthe.Schema

  import_types DerpWeb.Schema.UserTypes
  import_types DerpWeb.Schema.OfficeTypes
  import_types DerpWeb.Schema.CreatedThingTypes
  ...
end
defmodule DerpWeb.Schema.CreatedThingTypes do
  use Absinthe.Schema.Notation
  ...
  object :created_thing do
    @desc "The user associated with the created thing"
    field :user, :user, resolve: assoc(:user)
    @desc "The office associated with the created thing"
    field :office, :office, resolve: assoc(:office)
    ...
  end
end

And it’ll all just work.

5 Likes