Absinthe returns strange error

I’m struggling with a GraphQL query. This is the query I send in:

{"query":"{\n  allServiceProviders {\n    name\n    adhocEnabled\n    adhocCost\n    subEnabled\n    subCost\n  }\n}","variables":null,"operationName":null}

And this is the answer I get:

Cannot query field \"adhocEnabled\" on type \"ServiceProvider\". Did you mean \"adhocEnabled\"?

I did mean adhocEanbled, why doesn’t absinthe find it? I’m using absinthe 1.4 if it matters.

There’s been a pretty reasonable analogy between raising a graphql error and raising an exception. Functions can raise an exception OR return successfully, but not both. If you want to return error information as well as result information the general convention is to have a specific object type that composes both.

I don’t understand your answer. My function does not return any errors (as far as I know). It’s the absinthe library that returns the error that it doesn’t find the ```
adhocEnabled

field. In the same message it suggest to use the ```
adhocEnabled

field (which obviously exist).

Can you show the field definition?

object :serviceProvider do
    field :name, non_null(:string)
    field :adhocEnabled, non_null(:boolean)
    field :adhocCost, non_null(:float)
    field :subEnabled, non_null(:boolean)
    field :subCost, non_null(:float)
  end

Apparently if I use camelCase field names, absinthe uses snake_case column names in the database and somehow, somewhere it fails to convert between the names. So probably one of the adhocEnabled strings in the error message is in fact adhoc_enabled, it’s only absinthe that “helpfully” converts the names. If I use snake_case field names, everything seems to work.

Right, Absinthe expects elixir standard snake case field names for all identifiers.

2 Likes

absinthe expects the field identifiers to be in snake case. If you change that it will work.

2 Likes