absinthe-graphql / absinthe_relay

Absinthe support for the Relay framework
MIT License
182 stars 88 forks source link

Attempting to declare a connection field on an interface results in an error #40

Open dpehrson opened 7 years ago

dpehrson commented 7 years ago

Use case

Multiple node objects in my schema can be commented on, they should share a comments field which is relay connection of comment nodes and a declared interface to allow for polymorphic querying.

Expected results

I should be able to declare an interface with a field that is a relay connection for querying as such:

interface :commentable do
  connection field :comments, node_type: :comment
end

Actual results

Errors 😭

== Compilation error on file web/graph/schema.ex ==
** (FunctionClauseError) no function clause matching in Access.fetch/2
    (elixir) lib/access.ex:147: Access.fetch({:field, [line: 41], [:comments, [node_type: :comment]]}, :node_type)
    (elixir) lib/access.ex:179: Access.get/3
    (absinthe_relay) lib/absinthe/relay/connection/notation.ex:41: Absinthe.Relay.Connection.Notation.naming_from_attrs!/1
    (absinthe_relay) expanding macro: Absinthe.Relay.Connection.Notation.connection/1
    web/graph/schema.ex:41: App.Graph.Schema (module)
    (absinthe) expanding macro: Absinthe.Schema.Notation.interface/2
    web/graph/schema.ex:40: App.Graph.Schema (module)
    (elixir) lib/kernel/parallel_compiler.ex:117: anonymous fn/4 in Kernel.ParallelCompiler.spawn_compilers/1
AlexanderEkdahl commented 7 years ago

Any updates on this? I'm seeing a different error.

dpehrson commented 7 years ago

I originally reported this so long ago that I imagine a lot has changed about the library since then.

This only came up for me during a proof-of-concept testing phase and I never ended up actually having to use it so I never bothered trying to fix it like with other issues.

@benwilson512 and @bruce are super responsive to issues if you can help narrow down the error case. Check out #83 for an example of what I've done in the past.

benwilson512 commented 7 years ago

This is somewhere between a bug fix and a feature request. We mostly just need to make the connection macro know about interfaces.

AlexanderEkdahl commented 7 years ago

I may take a stab at this. Until then you can do:

interface :commentable do
  field :comments, :comment_connection
end