yuki24 / artemis

Ruby GraphQL client on Rails that actually makes you more productive
MIT License
207 stars 14 forks source link

Validate input arguments against schema in tests #95

Open artyrcheek opened 1 month ago

artyrcheek commented 1 month ago

Is it possible to validate the variables / response in test according to the schema?

yuki24 commented 1 month ago

Thanks for your question, @artyrcheek. I wonder if this issue https://github.com/yuki24/artemis/issues/56#issuecomment-489755674 (or basically calling YourClient.preload! in test) is related to your question. It should load the entire schema and the query/mutation definitions in your app, and that might be something you want. Let me know if this is something else.

artyrcheek commented 1 month ago

Thankyou @yuki24, Just want to say, this library is exactly what I wanted in a GraphQL client. 👏🏻 I love the convention over configuration approach & I love never having to see camelCase in my ruby, testing has become so much easier 🤩 I use this library to query the Shopify API so I have it set up with the :multi_domain adapter.

What I'm asking for here specifically is the ability to validate my query arguments in my tests rather than the queries themself, I see that validating queries already works perfectly 👏🏻.

For example, here is Shopify's ProductInput type I would love if errors were raised in my tests if:

In my input arguments

Im thinking that if its possible to raise an error if query arguments are invalid according to the schema, It would make API upgrades super easy because i could see everywhere my input is invalid.

It would also be nice to validate that the response fixtures are valid against the schema, although I'm not as bothered about this.

I would love graphql_requests.first.valid_input? graphql_responses.first.valid_response? methods.

Maybe there is a way to do this with github-community-projects/graphql-client that I'm unaware of?