wolfiton

wolfiton

Hi everyone,

How can i test my schema with wormwood when i have my schema in MyAppWeb/schema.ex?

Wormwood docs tells me that I need to load_gql MyCoolApplication.MyAbsintheSchema, "assets/js/queries/MyQuery.gql"

and this to my knowledge looks like the client part of graphql.

So can I test my back-end of my absinthe api with this?(confused)

Github with docs here GitHub - wormwood-elixir/wormwood: Wormwood is a tiny library to aid in testing GraphQL queries against an Absinthe schema. It allows you to test your query documents inside ExUnit test modules, and requires no HTTP requests to occur during testing. · GitHub

Also this article Wormwood - an Explicit Way to Test Absinthe GraphQL APIs | Black Duck Blog
Update: Found the examples link but no test wormwood/lib/examples at 0.1.0 · wormwood-elixir/wormwood · GitHub
Reported an issue regarding this problem here Problems understanding how to use the library for testing an absinthe schema · Issue #8 · wormwood-elixir/wormwood · GitHub

Found an example here for test GitHub - wormwood-elixir/wormwood at 0.1.0 · GitHub

Thanks.

Showing Posts 1 to 10

wolfiton

wolfiton OP

I think, I go it this library makes absinthe feel like working with graphql in nodejs.

The gql files wormwood/assets at 0.1.0 · wormwood-elixir/wormwood · GitHub
Absinthe implementation: wormwood/lib/examples at 0.1.0 · wormwood-elixir/wormwood · GitHub
Test examples: wormwood/test/examples at 0.1.0 · wormwood-elixir/wormwood · GitHub

wolfiton

wolfiton OP

Does anyone have any opinions regarding this testing framework?

Qqwy

Qqwy

TypeCheck Core Team

Hi @wolfiton! Since your question is quite specific, it can take a day (or a couple of days) before someone who uses Wormwood + Absynthe to get back to you, so hang tight :slight_smile: .

Darin

Darin

Hey @wolfiton,

I literally just integrated Wormwood into my application, so I am by no means an expert, but I can walk you through what it looks like for me.

First, I created the queries that I wanted to test. These are the .gql files that you saw in the assets folder in the Wormwood project. These are the queries that are going to be run against your GQL schema, the same as what will happen on the frontend. I put mine in a folder called test/support/queries, and then created different ones for each use case: one to feature current user data, one to fetch data based on a slug, one to fetch all the data associated with a model, etc.

Second, I created the tests themselves. This I put into a folder called test/myproject_web/schema. Here is an example of what the test looks like. My application is a book tracking application, hence the usage of book related info.

defmodule MyAppWeb.Test.BooksSchemaTest do
  use MyApp.DataCase, async: true
  use Wormwood.GQLCase

  load_gql(MyAppWeb.Schema.Schema, "test/support/queries/books.gql")

  describe "books.gql" do
    test "should return all 6 books" do
      result = query_gql()
      {:ok, query_data} = result
      assert length(get_in(query_data, [:data, "books"])) == 6
    end
  end
end

Some things to note.

  1. I have use MyApp.DataCase, async: true at the top, which is different from docs. Just due to how my database is setup, I need this to run my tests.
  2. The line load_gql(MyAppWeb.Schema.Schema, "test/support/queries/books.gql") basically says "my GQL schema is located in the module that is the first argument, and I want to run the query located in the file at the second argument).
  3. query_gql() will run the query, and return the result in an OK tuple. The rest is just the test logic. In my case, I am checking that after I run the query, it returns 6 different books, as that is the number of books I have included in my seed.exs.

As for my opinions of the framework, they aren’t too fleshed out, but I can give you some first thoughts. I do like it because it seems like an easy way to test the actual GraphQL queries. I was testing the functions that my queries resolve to before (and still am), which was pretty close, but this is nice because it is just one extra layer of abstraction. Also, I don’t need to try entering things into Graphiql, and instead can just look at my test queries and run them if I want to see how they’re going to behave, meaning they serve as a bit of documentation. Finally, more tests are always nice.

I hope that helps.

wolfiton

wolfiton OP

Awesome, thanks @Darin for sharing your thoughts and experience with this testing framework.

I also have a couple of questions if you don’t mind:

Have you tested any middleware or a subscription with this testing framework yet?

Does dataloader work with this testing framework?

Do you think it will be supported long term?

wolfiton

wolfiton OP

Just tried your method for a simple test and it works great. Thanks for sharing.

wolfiton

wolfiton OP

Has problems when you use something like this in the schema

@desc "Queryable fields for Blog Articles"
  query do
    field :blog_articles, list_of(:blog_article) do
      resolve(fn _, _, _ ->
        {:ok, Blog.list_articles()}
      end)
    end
  end

  @desc "define fileds that can be acessed for Blog queries"
  object :blog_article do
    field :id, :id
    field :title, :string
  end
end

The gql files will not recognize this format and it will not translate to BlogArticle and BlogArticles it will just give errors for test with invalid argument and return nil.

I feel that this is a bug.

Because if I use : :article and :articles it will translate to Article and Articles.

Darin

Darin

No problem.

Have you tested any middleware or a subscription with this testing framework yet?

Not yet. I do have some simple middleware I use for authentication that might be an easy one to test. I might try that over the weekend, and I could inform you of what my experiences are. I haven’t tried mocking the authentication stuff at all for testing, so I’m not really sure what I’ll run into.

Does dataloader work with this testing framework?

I have dataloader setup for the queries that I tested and it seemed to work just fine. I haven’t gone into the logs or anything to check that the queries themselves are done in bulk, but I don’t see why not.

Do you think it will be supported long term?

I can’t answer this one for sure. The last commit was in late October of last year, and it doesn’t seem to be insanely popular with only 41 stars so I doubt there will be much community contribution at this point. However, my mindset is that I need to test these GraphQL queries, and this seems like a good way to do it now. If in the future another library pops up that seems to be more maintained and popular it’ll probably be a lot easier for me to swap them out if I have already broken out my .gql files and specific GraphQL test cases. Therefore I think it’s probably more worth my time to just jump in and start writing some tests using Wormwood rather than let the analysis paralysis set in.

wolfiton

wolfiton OP

Thanks have you encounter my problem in #post7 with the naming problems?

wolfiton

wolfiton OP

Will you contribute to wormwood testing framework, because it seems that you find it useful and use it in your projects?

Because if you would, I would like to join in and try to help with what I can to make it very easy to use.

I also find it very useful just thinking that i will already have my graphql setup for the front-end from wormwood so i will not need to write it again for the client(just copy paste).

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
bradley
I really like the adapter patterns that ecto, nebulex, waffle, etc. use and would love find something similar for a key management servic...
New
unaware8150
Hello folks! So at work, we are seeing some situations where we have to define some “fixed” strings that are used across the codebase in...
New
Alvinkariuki
How Can I Optimise Compile Time Dependencies I have been building an elixir application for about 2 years now. Many modules and files ha...
New

Other Trending Topics Top

mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
budgie
I love Elixir. It’s one of 2 programming languages I’ve ever fallen in love with. But I don’t use it anymore. Serverless was the promis...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews