I have a Phoenix application that is using Absinthe. When I issue a query against my schema for a particular field, Absinthe returns an error:
Cannot query field “fullyQualifiedDomainName” on type “VirtualServer”. Did you mean “fullyQualifiedDomainName”?
Notably the two strings above match.
I’ve boiled the code in question down to a sample:
defmodule My.Sample.Schema do
use Absinthe.Schema
object :virtual_server do
field :hostname, :string
field :fullyQualifiedDomainName, :string
end
query do
@desc "All the things"
field :virtual_servers, list_of(:virtual_server) do
resolve fn(_, _) -> {:ok, [%{"hostname" => "happy", "fullyQualifiedDomainName" => "fqdn"}] } end
end
end
end
IO.inspect ("""
query {
virtualServers {
hostname
}
}
""" |> Absinthe.run(My.Sample.Schema))
IO.inspect ("""
query {
virtualServers {
fullyQualifiedDomainName
}
}
""" |> Absinthe.run(My.Sample.Schema))
When I run that sample, in the context of my application it prints out:
{:ok, %{data: %{"virtualServers" => [%{"hostname" => nil}]}}}
{
:ok,
%{
errors: [
%{
locations: [%{column: 0, line: 3}],
message: "Cannot query field \"fullyQualifiedDomainName\" on type \"VirtualServer\". Did you mean \"fullyQualifiedDomainName\"?"
}
]
}
}
For the first query, it is happy to see the field named hostname
and does it’s best to grab the data (I don’t know why it’s coming back nil
in this sample as it returns real data in the main app, please let that go for the moment).
What bother’s me is the result of the second query. Why does it realize that hostname
is valid in the first query, but rejects fullyQualifiedDomainName
in the second query?
The two are declared in the schema right next to one another!
The position of fullyQualifiedDomainName
in the schema definition doesn’t seem to matter at all. In the larger application these two fields are accompanied by many other fields. I’ve tried moving fullyQualifiedDomainName
to the front of the list, the end, somewhere in the middle… for whatever reason this one field is never recognized.
Can anyone suggest what might be wrong with that field name, or the schema definition that I have here, which would prevent Absinthe from recognizing it?