Introspection error because I'm using a type for both input and output

Let’s say I have a basic type called an article

object :article do
    field(:id, :id)
    field(:author, :string)
    field(:body, :string)
  end

I can have a query like this:

query do
  field :articles, list_of(:article) do
     ...
  end
end

But if I did this

mutation do
  field :upload_articles, :boolean do
      arg(:input, non_null(:upload_article_input))
    end
end

input_object :upload_article_input do
  field(:articles, non_null(list_of(:article)))
end

I get this error

Introspection must provide input type for arguments, but received: [Article]!.

My hack around this was to create

input_object :input_article do
    field(:id, :id)
    field(:author, :string)
    field(:body, :string)
end

input_object :upload_article_input do
  field(:articles, non_null(list_of(:input_article)))
end

and use that in the input, but since it’s fundamentally the same as the object :article, is there a better way to do this?

This is not a hack, this is the correct way to do it, although by convention the type is usually called article_input instead of input_article. Although in simple examples the inputs and outputs are identical, this always changes as APIs get more complex, and you want to create space for those to evolve separately.

Thanks Ben. I’ll go with that. Also I only noticed this when I tried to parse it with a external JS lib get-graphql-schema. Is there anyway to write a test in my code that ensures the introspection isn’t broken?

What version of Absinthe are you on? Modern versions of Absinthe should error out at compile time with the schema that you wrote.

1.4.16

It runs and compiles fine. Is there a way I can write a test that would fail instead?

Hm, it definitely shouldn’t. Absinthe does its best to prevent the creation of illegal schemas at compile time. Can you try it on 1.5.1?