Skip to content

Commit 7564129

Browse files
committed
drop with schema
1 parent 79302bb commit 7564129

4 files changed

Lines changed: 177 additions & 163 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
hive-router-plan-executor: major
3+
hive-router: patch
4+
---
5+
6+
# Drop `with_schema` from the `on_graphql_validation` plugin hook
7+
8+
Remove `OnGraphQLValidationStartHookPayload::with_schema`. Method was broken by design, it replaced the schema only for validation while parsing, introspection, normalization, planning, and execution continued using the request's original schema state. This could make a field disappear during validation while remaining visible through introspection, and it could leave schema-derived caches and planning state inconsistent with the schema used to validate the operation.
9+
10+
Plugins that need a request-specific schema should now build and retain a stable `Arc<Document>` for each schema variant and select it in `on_http_request`:
11+
12+
```rust
13+
fn on_http_request<'req>(
14+
&'req self,
15+
payload: OnHttpRequestHookPayload<'req>,
16+
) -> OnHttpRequestHookResult<'req> {
17+
payload.set_schema_document(self.document_for_request(&payload).clone());
18+
payload.proceed()
19+
}
20+
```
21+
22+
The router resolves the selected supergraph document into an internally owned `SchemaState` and reuses it for later requests that provide the same `Arc<Document>`. The selected schema then applies consistently to the entire request pipeline, including validation, introspection, normalization, planning, and execution.
23+
24+
Documents should be created when the plugin initializes or when the supergraph reloads, not per request. Creating a new `Arc<Document>` for every request defeats the router's schema-state cache and forces the schema state and query planner to be rebuilt.

lib/executor/src/plugins/hooks/on_graphql_validation.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use graphql_tools::{
4-
static_graphql::{query::Document as QueryDocument, schema::Document as SchemaDocument},
4+
static_graphql::query::Document as QueryDocument,
55
validation::{rules::ValidationRule, utils::ValidationError, validate::ValidationPlan},
66
};
77
use hive_router_query_planner::consumer_schema::ConsumerSchema;
@@ -32,12 +32,8 @@ pub struct OnGraphQLValidationStartHookPayload<'exec> {
3232
/// [Learn more about the context data sharing in the docs](https://the-guild.dev/graphql/hive/docs/router/extensibility/plugin_system#context-data-sharing)
3333
pub context: &'exec PluginContext,
3434
pub request_context: RequestContextApi,
35-
/// The GraphQL Schema that the document will be validated against.
36-
/// This is not the same with the supergraph. This is the public schema exposed by the router to the clients, which is generated from the supergraph and can be modified by the plugins.
37-
/// The plugins can replace the input schema to be used for validation
38-
/// and the new schema will be used in the validation process instead of the original one.
39-
///
40-
/// [See an example to see when to override the schema](https://github.com/graphql-hive/router/blob/main/plugin_examples/feature_flags/src/plugin.rs)
35+
/// The GraphQL schema that the document will be validated against.
36+
/// This is the public schema exposed by the router, not the supergraph.
4137
pub schema: Arc<ConsumerSchema>,
4238
/// Parsed GraphQL document from the query string in the GraphQL parameters.
4339
/// It contains the Abstract Syntax Tree (AST) representation of the GraphQL query, mutation, or subscription
@@ -70,14 +66,6 @@ impl OnGraphQLValidationStartHookPayload<'_> {
7066
self.validation_plan = Arc::new(validation_plan.into());
7167
self
7268
}
73-
/// Override the GraphQL Schema that the document will be validated against.
74-
/// [See an example to see when to override the schema](https://github.com/graphql-hive/router/blob/main/plugin_examples/feature_flags/src/plugin.rs)
75-
pub fn with_schema<TSchema: Into<Arc<SchemaDocument>>>(mut self, schema: TSchema) -> Self {
76-
let schema: Arc<SchemaDocument> = schema.into();
77-
let new_consumer_schema = ConsumerSchema::from(schema);
78-
self.schema = new_consumer_schema.into();
79-
self
80-
}
8169
}
8270

8371
impl<'exec> StartHookPayload<OnGraphQLValidationEndHookPayload, Response>

0 commit comments

Comments
 (0)