graphql-elixir / graphql

GraphQL Elixir
Other
858 stars 45 forks source link

Resolve fails when it cannot find a matching function #59

Closed aweiker closed 8 years ago

aweiker commented 8 years ago

When a function is specified in resolve and pattern matching is used, if the matching fails an ugly missing method exception is thrown instead of an helpful error message. Since user input can cause this to fail, a friendly validation error should be given instead.

For example:

This is the relevant schema definition:

%ObjectType{
        name: "Mutation",
        description: "Root object for performing data mutations",
        fields: %{
          set_rail_preferences: %{
            description: "Updates the rail preferences for a user.",
            args: Orchestration.Schema.User.RailPreferences.set_rail_preferences_args,
            type: Orchestration.Schema.User.RailPreferences.type,
            resolve: fn(_, args = %{id: id}, _) ->
              case Orchestration.Data.set_user_rail_preferences(id, args) do
                {:ok, user} -> user.preferences.rail
                :empty -> nil
              end
            end
          }
        }
      }

Here is the query document

mutation preferences{
  set_rail_preferences(seat: WINDOW) {
    seat
  }
}

error message:

** (FunctionClauseError) no function clause matching in anonymous fn/3 in Orchestration.Schema.schema/0
aweiker commented 8 years ago

Added a PR with a failing unit test to show the failure.