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)
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.
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #genstage
- #ai
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 12 Posts
wolfiton
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
Does anyone have any opinions regarding this testing framework?
Qqwy
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
.
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
.gqlfiles 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 calledtest/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.Some things to note.
use MyApp.DataCase, async: trueat the top, which is different from docs. Just due to how my database is setup, I need this to run my tests.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).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 myseed.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
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
Just tried your method for a simple test and it works great. Thanks for sharing.
wolfiton
Has problems when you use something like this in the schema
The
gql fileswill not recognize this format and it will not translate toBlogArticleandBlogArticlesit will just give errors for test withinvalid argumentandreturn nil.I feel that this is a bug.
Because if I use :
:article and :articlesit will translate toArticleandArticles.Darin
No problem.
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.
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.
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
.gqlfiles 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
Thanks have you encounter my problem in #post7 with the naming problems?
wolfiton
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).