Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Mar 18, 2024
1 parent 62597a2 commit 77ab5dc
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 28 deletions.
2 changes: 2 additions & 0 deletions libs/common/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

Check warning on line 1 in libs/common/src/execute.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `std::sync::Arc`

warning: unused import: `std::sync::Arc` --> libs/common/src/execute.rs:1:5 | 1 | use std::sync::Arc; | ^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default

use crate::{
graphql::ParsedGraphQLRequest,
http::{ConductorHttpRequest, ConductorHttpResponse},
Expand Down
1 change: 1 addition & 0 deletions libs/config/conductor.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@
"type": "string"
},
"schema_awareness": {
"description": "TODO: docs",
"anyOf": [
{
"$ref": "#/definitions/SchemaAwarenessConfig"
Expand Down
12 changes: 0 additions & 12 deletions libs/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ fn endpoint_definition_example1() -> JsonSchemaExample<ConductorConfig> {
config: GraphQLSourceConfig {
endpoint: "https://my-source.com/graphql".to_string(),
schema_awareness: None,
validate_operations: false
},
}],
endpoints: vec![EndpointDefinition {
Expand All @@ -188,7 +187,6 @@ fn endpoint_definition_example2() -> JsonSchemaExample<ConductorConfig> {
config: GraphQLSourceConfig {
endpoint: "https://my-source.com/graphql".to_string(),
schema_awareness: None,
validate_operations: false
},
}],
endpoints: vec![EndpointDefinition {
Expand Down Expand Up @@ -467,15 +465,6 @@ pub struct GraphQLSourceConfig {
pub endpoint: String,
/// TODO: docs
pub schema_awareness: Option<SchemaAwarenessConfig>,
/// Runs GraphQL validation when `schema_awareness` is configured and loaded correctly.
///
/// If schema awareness is not configured or not loaded sucussfully, this option is ignored.
#[serde(default = "default_graphql_source_validate_operations")]
pub validate_operations: bool,
}

fn default_graphql_source_validate_operations() -> bool {
true
}

#[derive(Deserialize, Serialize, Debug, Clone, JsonSchema)]
Expand Down Expand Up @@ -571,7 +560,6 @@ fn graphql_source_definition_example() -> JsonSchemaExample<SourceDefinition> {
config: GraphQLSourceConfig {
endpoint: "https://my-source.com/graphql".to_string(),
schema_awareness: None,
validate_operations: false,
},
},
}
Expand Down
2 changes: 0 additions & 2 deletions libs/e2e_tests/suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ impl TestSuite {
GraphQLSourceConfig {
endpoint: mock_server.url("/graphql"),
schema_awareness: None,
validate_operations: false,
},
)
.await
Expand Down Expand Up @@ -67,7 +66,6 @@ impl TestSuite {
GraphQLSourceConfig {
endpoint: mock_server.url("/graphql"),
schema_awareness: None,
validate_operations: false,
},
)
.await
Expand Down
14 changes: 1 addition & 13 deletions libs/engine/src/source/graphql_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{future::Future, pin::Pin, sync::Arc};

use conductor_common::{
execute::RequestExecutionContext,
graphql::{validate_graphql_operation, GraphQLResponse, ParsedGraphQLSchema},
graphql::{GraphQLResponse, ParsedGraphQLSchema},
http::{ConductorHttpRequest, CONTENT_TYPE},
};
use conductor_config::GraphQLSourceConfig;
Expand Down Expand Up @@ -76,18 +76,6 @@ impl SourceRuntime for GraphQLSourceRuntime {
route_data: &'a ConductorGatewayRouteData,
request_context: &'a mut RequestExecutionContext,
) -> Pin<Box<(dyn Future<Output = Result<GraphQLResponse, SourceError>> + 'a)>> {
if self.config.validate_operations {
if let Some(schema) = self.schema() {
if let Some(operation) = &request_context.downstream_graphql_request {
let errors = validate_graphql_operation(schema.as_ref(), &operation.parsed_operation);

if !errors.is_empty() {
return Box::pin(async move { Ok(errors.into()) });
}
}
}
}

Box::pin(wasm_polyfills::call_async(async move {
let fetcher = &self.fetcher;
let endpoint = &self.config.endpoint;
Expand Down
10 changes: 9 additions & 1 deletion plugins/graphql_validation/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ impl CreatablePlugin for GraphQLValidationPlugin {
#[async_trait::async_trait(?Send)]
impl Plugin for GraphQLValidationPlugin {
async fn on_downstream_graphql_request(&self, _ctx: &mut RequestExecutionContext) {

if let Some(schema) = self.schema() {

Check failure on line 23 in plugins/graphql_validation/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

no method named `schema` found for reference `&plugin::GraphQLValidationPlugin` in the current scope

error[E0599]: no method named `schema` found for reference `&plugin::GraphQLValidationPlugin` in the current scope --> plugins/graphql_validation/src/plugin.rs:23:32 | 23 | if let Some(schema) = self.schema() { | ^^^^^^ method not found in `&GraphQLValidationPlugin`
if let Some(operation) = &request_context.downstream_graphql_request {

Check failure on line 24 in plugins/graphql_validation/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find value `request_context` in this scope

error[E0425]: cannot find value `request_context` in this scope --> plugins/graphql_validation/src/plugin.rs:24:33 | 24 | if let Some(operation) = &request_context.downstream_graphql_request { | ^^^^^^^^^^^^^^^ not found in this scope
let errors = validate_graphql_operation(schema.as_ref(), &operation.parsed_operation);

Check failure on line 25 in plugins/graphql_validation/src/plugin.rs

View workflow job for this annotation

GitHub Actions / clippy

cannot find function `validate_graphql_operation` in this scope

error[E0425]: cannot find function `validate_graphql_operation` in this scope --> plugins/graphql_validation/src/plugin.rs:25:22 | 25 | let errors = validate_graphql_operation(schema.as_ref(), &operation.parsed_operation); | ^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope | help: consider importing this function | 1 + use conductor_common::graphql::validate_graphql_operation; |

if !errors.is_empty() {
return Box::pin(async move { Ok(errors.into()) });
}
}
}
}
}

0 comments on commit 77ab5dc

Please sign in to comment.