Absinthe TDD Best Practices

Hi Peeps,

I’m looking for best practices, tutorials or any recommendations on how to TDD with Absinthe; there doesn’t seem to be much on terms of testing Absinthe GraphQL APIs even the “Craft GraphQL APIs in Elixir with Absinthe” book seems a little sparse on the subject only showing an example testing against the endpoint.

I’m particularly curious about tests against the schemas and resolvers themselves rather than the actual running endpoint.

Hey @amacgregor. Fundamentally the bulk of your application’s API, and consequently the bulk of your testing, should focus on context functions.

Testing resolvers directly is about as feasible as testing controller callbacks directly: Not impossible, but not exactly ergonomic. They are built to be called within the context of Absinthe executing, and so they may depend on values related to Absinthe execution which you then need to recreate. If they suspend then you have to manually un-suspend them and that’s not going to be ergonomic at all.


Hey @benwilson512 , so I should focus the bulk of the testing on the Context and then maybe leave some integration test for testing the actual GraphQL API implementation?

I guess that makes sense, and thanks for the explanation about resolvers; it’s one of those situations where if what I’m trying to do is too hard, then there is probably a better way to do it.

So now let me go back and see if context finally click and feel comfortable for me :smiley: to use.

1 Like