Closed robsontenorio closed 4 years ago
The approach described in the docs actually works, but we might clarify that changing after initialization does not work.
We could make it so the test schema is recompiled on every call to $this->graphQL()
, but I am worried that might be costly in terms of performance.
@spawnia can you give some directions to achieve that?
I am considering to create my own trait. Once i am working on Lighthouse Dashboard package i need exactly this behavior on my testing case. Because i need detect changes on schema on sucessive requests.
How about splitting your test methods so they are focused and do one thing? Dynamically changing a schema in the lifecycle of a request has not come up as a real world use case, so I am hesitant to support it.
In my testing scenarios the source of true is always a schema.graphl
, so the internal state of dashboard (database) is filled with this info. I am following acceptance approach on tests.
But, I am not proposing this addition into Lighthouse core, because it is expensive. If you can point me how to “refresh” the schema on every single request I can put this logic in my own trait for only testing proposes.
What I have tried, but no lucky:
Solved by adding this to my TestCase.php
protected function rebuildTestSchema() {
$this->app->extend(SchemaSourceProvider::class, fn () => new TestSchemaProvider($this->schema));
}
Now i can switch schemas on single test method.
$this->schema = '...initial...'
$this->graphQL(...)
$this->schema = '...changed...'
// new helper
$this->rebuildTestSchema();
// now this detects schema changes
$this->graphQL(....)
Describe the bug
https://lighthouse-php.com/4.16/testing/extensions.htm
Cant override schema as described on docs, when using sucessive graphql requests.
Expected behavior/Solution
It should override schema.
Steps to reproduce
See PR https://github.com/nuwave/lighthouse/pull/1568
Lighthouse Version
v5.alpha4