Absinthe & Testing

Any tips for testing an Absinthe API?

I have a feeling it could be very nice, with the typing information GraphQL gives us and a dash of randomisation - quickcheck style…

Perhaps that’s already the done thing though?

1 Like

Currently I just call the absinthe api from my tests and check what is returned… ^.^;

It might be fairly easily doable to setup a propcheck style tests for it though.

1 Like

I wrote Kronky, which has some helpers for testing Absinthe, among other things. There are example test cases in the docs. In short it looks like

    query = """
      { user(id: "1")
        {
          firstName
          lastName
          age
        }
      }
      """
      {:ok, %{data: data}} = evaluate_graphql(query)

      user_fields = %{first_name: :string, last_name: string, age: integer}
      expected = %User{first_name: "Lilo", last_name: "Pelekai", age: 6}
      %{"user" => result} = data
      assert_equivalent_graphql(expected, result, user_fields)

If you subscribe to Elixir Sips, they also have an Absinthe Episode with some tests.

3 Likes

Yeah this is an idea I’ve been really excited about for a while, but I just haven’t had the time to invest in the tooling needed to make this actually happen. You’re always welcome to be the first!

5 Likes