graphql-elixir / graphql

GraphQL Elixir
Other
858 stars 45 forks source link

Upgrading to phoenix 1.2 causes error in node_interface #98

Closed note89 closed 8 years ago

note89 commented 8 years ago
== Compilation error on file web/router.ex ==
** (ArgumentError) cannot escape #Function<1.97113962/1 in App.PublicSchema.node_interface/0>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, pids and remote functions in the format &Mod.fun/arity
    (elixir) src/elixir_quote.erl:119: :elixir_quote.argument_error/1
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:382: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:259: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:382: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:259: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:382: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:259: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:382: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:259: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:382: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:259: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:382: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:141: :elixir_quote.escape/2
    (elixir) lib/macro.ex:312: Macro.escape/2
  scope "/graphql" do
    pipe_through :api
    forward "/", GraphQL.Plug, schema: {App.PublicSchema, :schema}
  end
  def node_interface do
    Node.define_interface(fn(obj) ->
      case obj do
        %{start_unix_timestamp: _ } ->
          App.Event.Type
        %{comments: _, full_text: _} ->
          App.Article.Type
        %{members: _} ->
            App.Group.Type
        %{email: _, name: _} ->
          App.User.Type
        %{replys: _} ->
          App.Comments.Type
      end
    end)
  end

elixir 1.2.3

joshprice commented 8 years ago

From what I can tell the problem seems to be passing the anonymous fn into define_interface (ie fn(obj) ->...). Try using the {mod, fun, args} or &Mod.fun/arity style instead.

note89 commented 8 years ago

Seems like i have to rewrite a lot of my functions to that style but now i got this .

** (exit) an exception was raised:
    ** (UndefinedFunctionError) function App.Event.Bounds.Root.type/1 is undefined or private
        (app) App.Event.Bounds.Root.type({App.Event.Bounds.Root, :get})
        (graphql) anonymous fn/2 in GraphQL.Schema.reduce_types/2
        (stdlib) lists.erl:1262: :lists.foldl/3
        (graphql) lib/graphql/type/schema.ex:75: GraphQL.Schema.reduce_types/2
        (graphql) lib/graphql/type/schema.ex:49: GraphQL.Schema.do_reduce_types/2
        (graphql) lib/graphql/type/schema.ex:30: GraphQL.Schema.new/1
        (graphql) lib/graphql/validation/validator.ex:58: GraphQL.Validation.Validator.validate_with_rules/3
        (graphql) lib/graphql.ex:104: GraphQL.execute_with_optional_validation/3
        (plug_graphql) lib/graphql/plug/endpoint.ex:85: GraphQL.Plug.Endpoint.execute/2
        (plug_graphql) lib/graphql/plug.ex:54: GraphQL.Plug.call/2
        (phoenix) lib/phoenix/router/route.ex:154: Phoenix.Router.Route.forward/4
        (app) lib/phoenix/router.ex:261: App.Router.dispatch/2
        (app) web/router.ex:1: App.Router.do_call/2
        (app) lib/app/endpoint.ex:1: App.Endpoint.phoenix_pipeline/1
        (app) lib/plug/debugger.ex:93: App.Endpoint."call (overridable 3)"/2
        (app) lib/app/endpoint.ex:1: App.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

and the file looks like this

defmodule App.Event.Bounds.Root do
  alias GraphQL.Relay.Connection
  alias RethinkDB.Query
  import RethinkDB.Lambda
  import App.Utils.Types

  @type_float %{type: %GraphQL.Type.Float{}}
  @type_integer %{type: %GraphQL.Type.Int{}}

  def get do
    %{
      name: "List of events",
      description: "Takes a query and gives backa events who's title match that",
      type: App.Event.Connection.get[:connection_type],
      args: Map.merge(Connection.args,
      %{
          swLat: float_non_null,
          swLng: float_non_null,
          neLat: float_non_null,
          neLng: float_non_null,
          start_unix_time: int_non_null,
          end_unix_time: int_non_null,
      }),
      resolve: { App.Event.Bounds.Root.Resolve, :get }
    }
  end
end
note89 commented 8 years ago

This repo reproduces the error . https://github.com/graphql-elixir/phoenix-hipster-stack

note89 commented 8 years ago

If i fix the first problem i get this

== Compilation error on file web/router.ex ==
** (ArgumentError) cannot escape #Function<0.123002726/3 in App.Type.Link.get/0>. The supported values are: lists, tuples, maps, atoms, numbers, bitstrings, pids and remote functions in the format &Mod.fun/arity
    (elixir) src/elixir_quote.erl:119: :elixir_quote.argument_error/1
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:397: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:259: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:397: :elixir_quote.do_splice/5
    (elixir) src/elixir_quote.erl:259: :elixir_quote.do_quote/3
    (elixir) src/elixir_quote.erl:246: :elixir_quote.do_quote/3

``` so it just continiues
note89 commented 8 years ago

In the end i had to update routes.ex but then got this runtime error

Request: POST /graphql
** (exit) an exception was raised:
    ** (BadMapError) expected a map, got: &App.PublicSchema.schema/0
        (stdlib) :maps.find(:query, &App.PublicSchema.schema/0)
        (elixir) lib/map.ex:145: Map.get/3
        (graphql) lib/graphql/execution/executor.ex:82: GraphQL.Execution.Executor.execute_operation/3
        (graphql) lib/graphql.ex:25: GraphQL.execute/5
        (plug_graphql) lib/graphql/plug/endpoint.ex:85: GraphQL.Plug.Endpoint.execute/2
        (plug_graphql) lib/graphql/plug.ex:54: GraphQL.Plug.call/2
        (phoenix) lib/phoenix/router/route.ex:154: Phoenix.Router.Route.forward/4
        (app) lib/phoenix/router.ex:261: App.Router.dispatch/2
note89 commented 8 years ago

Here is my attempt https://github.com/graphql-elixir/phoenix-hipster-stack/commit/69885f66490ef55e40af363ef1472f799988c54e