sandorbedo

sandorbedo

Absinthe goes into infinite loop^H^H^H^Hrecursion

Hi,

Is this a bug in Absinthe I’ve just ran into? Here’s an SDL schema:

    interface A { bs: [B!]!  }
    interface B { a: A!  }
    
    type A1 implements A { bs: [B!]! }
    type A2 implements A { bs: [B!]! }  # the same as A1 for now
    
    type B1 implements B { a: A! }
    type B2 implements B { a: A! }  # this is the same as B1

This is a perfectly fine, valid SDL, and Absinthe is able to use it. So far so good.

We have two interfaces here called A and B. The types implementing interface A have to have a field called bs containing a list of values of any type implementing B. The types implementing interface B have to have a field called a containing a value of a type that implements A. We also have four types that implement these interfaces. A1 and A2 implement interface A, while B1 and B2 implement interface B.

At this point A1 and A2, just like B1 and B2 have the exact same SDL definitions. Let’s play around with the idea that A1 has to do something with B1 and also that A2 has to do something with B2:

Let’s say that the field a of A1 can be specified more accurately. Instead of just containing Bs in general, we know it always holds B1 values. The same goes for the relationship of A2 and B2, so let’s replace the identical definition with this more specific one:

    type A1 implements A { bs: [B1!]! }
    type A2 implements A { bs: [B2!]! }

This is also a valid SDL, and Absinthe deals with it. B1 and B2 both implement B, so the interface requirement is fulfilled. bs holds values of types implementing interface B.

Just like when we undo the above change, and replace the definition of B1 and B2 with this:

    type B1 implements B { a: A1! }
    type B2 implements B { a: A2! }

This is also valid, because A1 and A2 implement A, so the interface that B1 and B2 implement (that is interface B) is satisfied.

The problem comes up when both the above modifications are done, like this:

    interface A { bs: [B!]!  }
    interface B { a: A!  }

    type A1 implements A { bs: [B1!]! }
    type A2 implements A { bs: [B2!]! }

    type B1 implements B { a: A1! }
    type B2 implements B { a: A2! }

Absinthe cannot compile the schema module with an SDL like this. It just eats up the memory of the machine and then the OS kills the compilation process. (I bet this is due to mutually referencing types.)

This might seem like an artificial problem, but actually this was discovered in a real life application with more meaningful types and interfaces that these As and Bs. The only workaround I found is that we only replace interfaces with types from one direction, not both.

Is this an Absinthe problem or this is something impossible to resolve in general?

Is there any way we can keep the specific types (instead of the generic interfaces) in our schema?

Most Liked

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Hey @sandorbedo Absinthe should always either compile happily or return an error, never recurse infinitely. Please feel free to file an issue. It will help a lot if you can present a complete runnable module or script just to make reproducing this very easy.

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 35421 110
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement