Support for testing multiple graphql schemas
jgrau opened this issue · comments
Hi @pocke
I just found this gem and thinks it's very interesting. My application has two graphql schemas: one for our public api and one for our admin-only application. I tried
GraphQL::Coverage.enable(PublicSchema)
GraphQL::Coverage.enable(AdminSchema)
but that fails with
An error occurred in a `before(:suite)` hook.
Failure/Error: GraphQL::Coverage.enable(AdminSchema)
GraphQL::Coverage::Errors::SchemaMismatch:
Schema mismatch: expected PublicSchema, got AdminSchema
# ./spec/rails_helper.rb:149:in `block (2 levels) in <top (required)>'
Finished in 0.01807 seconds (files took 5.52 seconds to load)
0 examples, 0 failures, 1 error occurred outside of examples
(the line reference in the error above is GraphQL::Coverage.enable(AdminSchema)
Would it be possible to support testing multiple schemas? Can you see any workarounds?
Thanks for your report! It is an interesting use case.
I have a workaround idea. You can run test twice. For example:
- Write
GraphQL::Coverage.enable(PublicSchema)
intospec_helper.rb
. - Run
bundle exec rspec
- Remove
GraphQL::Coverage.enable(PublicSchema)
and writeGraphQL::Coverage.enable(AdminSchema)
intospec_helper.rb
. - RUn
bundle exec rspec
again
In this example, you can get the coverages for both schemas.
But it is clearly inefficient😓 I think this workaround is useful if you need just one-off execution, but it is not enough for continuous execution. I have no idea about continuous execution...
I think it is not a rare case. Therefore, supporting multiple schemas is acceptable.
But we need to refactor it to implement this feature because GraphQL::Coverage
singleton stores information.