Skip to content

Instantly share code, notes, and snippets.

@shantiii
Last active January 5, 2017 19:30
Show Gist options
  • Save shantiii/2263547b5165133beb70eec642e9f3ff to your computer and use it in GitHub Desktop.
Save shantiii/2263547b5165133beb70eec642e9f3ff to your computer and use it in GitHub Desktop.
absinthe diamond dependencies
defmodule CoreTypes do
object :user do
field :id, :id
field :name, :string
end
object :product do
field :id, :id
field :author, :user
end
end
defmodule SearchTypes do
import_types CoreTypes
object :search_result do
field :query, :string
field :results, list_of(:product)
end
end
defmodule FeatureTypes do
import_types CoreTypes
object :feature_flag do
field :creator, :user
field :name, :string
end
end
defmodule Schema do
import_types SearchTypes
import_types FeatureTypes
query do
...
end
end
@bruce
Copy link

bruce commented Jan 5, 2017

Try this:

defmodule CoreTypes do
  use Absinthe.Schema.Notation

  object :user do
    field :id, :id
    field :name, :string
  end
  
  object :product do
    field :id, :id
    field :author, :user
  end
end

defmodule SearchTypes do
  use Absinthe.Schema.Notation

  object :search_result do
    field :query, :string
    field :results, list_of(:product)
  end

end

defmodule FeatureTypes do
  use Absinthe.Schema.Notation

  object :feature_flag do
    field :creator, :user
    field :name, :string
  end

end

defmodule Schema do
  use Absinthe.Schema

  import_types CoreTypes
  import_types SearchTypes
  import_types FeatureTypes

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

end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment