Skip to content

Commit

Permalink
Run cargo fmt in CI (#431)
Browse files Browse the repository at this point in the history
<!-- Thank you for submitting this PR! :) -->

## Description

When I run `cargo fmt` on my branches, it makes more diff than I want.
This PR fixes that by adding `just format` / `just fmt`, and adding it
to a CI job.

<!--
  Questions to consider answering:
  1. What user-facing changes are being made?
2. What are issues related to this PR? (Consider adding `(close
#<issue-no>)` to the PR title)
  3. What is the conceptual design behind this PR?
  4. How can this PR be tested/verified?
  5. Does the PR have limitations?
  6. Does the PR introduce breaking changes?
-->

## Changelog

- Add a changelog entry (in the "Changelog entry" section below) if the
changes in this PR have any user-facing impact. See [changelog
guide](https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide).
- If no changelog is required ignore/remove this section and add a
`no-changelog-required` label to the PR.

### Product
_(Select all products this will be available in)_
- [ ] community-edition
- [ ] cloud
<!-- product : end : DO NOT REMOVE -->

### Type
<!-- See changelog structure:
https://github.com/hasura/graphql-engine-mono/wiki/Changelog-Guide#structure-of-our-changelog
-->
_(Select only one. In case of multiple, choose the most appropriate)_
- [ ] highlight
- [ ] enhancement
- [ ] bugfix
- [ ] behaviour-change
- [ ] performance-enhancement
- [ ] security-fix
<!-- type : end : DO NOT REMOVE -->

### Changelog entry
<!--
  - Add a user understandable changelog entry
- Include all details needed to understand the change. Try including
links to docs or issues if relevant
  - For Highlights start with a H4 heading (#### <entry title>)
  - Get the changelog entry reviewed by your team
-->

_Replace with changelog entry_

<!-- changelog-entry : end : DO NOT REMOVE -->

<!-- changelog : end : DO NOT REMOVE -->

V3_GIT_ORIGIN_REV_ID: e31e352f27b9ad0129c3759fead051b1a8d86758
  • Loading branch information
i-am-tom authored and hasura-bot committed Apr 2, 2024
1 parent cc9cedc commit ec62ea4
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 80 deletions.
24 changes: 13 additions & 11 deletions v3/crates/custom-connector/src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,13 +433,15 @@ fn eval_order_by_element(
column,
function,
),
ndc_models::OrderByTarget::StarCountAggregate { path } => eval_order_by_star_count_aggregate(
collection_relationships,
variables,
state,
item,
path,
),
ndc_models::OrderByTarget::StarCountAggregate { path } => {
eval_order_by_star_count_aggregate(
collection_relationships,
variables,
state,
item,
path,
)
}
}
}

Expand Down Expand Up @@ -999,17 +1001,17 @@ pub(crate) fn eval_nested_field(
state,
&full_row,
)?;
Ok(ndc_models::RowFieldValue(serde_json::to_value(row).map_err(
|_| {
Ok(ndc_models::RowFieldValue(
serde_json::to_value(row).map_err(|_| {
(
StatusCode::INTERNAL_SERVER_ERROR,
Json(ndc_models::ErrorResponse {
message: "Cannot encode rowset".into(),
details: serde_json::Value::Null,
}),
)
},
)?))
})?,
))
}
ndc_models::NestedField::Array(ndc_models::NestedArray { fields }) => {
let array: Vec<serde_json::Value> = serde_json::from_value(value).map_err(|_| {
Expand Down
2 changes: 1 addition & 1 deletion v3/crates/engine/src/execute/explain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ async fn get_execution_steps<'s>(

/// Get the join steps for a given join location. This should be used to get the join steps for a remote relationship.
/// It also supports nested remote relationships.
///
///
/// TODO: Currently the steps are sequential, we should make them parallel once the executor supports it.
#[async_recursion]
async fn get_join_steps(
Expand Down
142 changes: 75 additions & 67 deletions v3/crates/engine/src/execute/ndc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,28 @@ pub async fn execute_ndc_query<'n, 's>(
) -> Result<Vec<ndc_models::RowSet>, error::Error> {
let tracer = tracing_util::global_tracer();
tracer
.in_span_async("Execute query using data connector", SpanVisibility::User, || {
Box::pin(async {
set_attribute_on_active_span(
AttributeVisibility::Default,
"operation",
execution_span_attribute,
);
set_attribute_on_active_span(
AttributeVisibility::Default,
"field",
field_span_attribute,
);
let connector_response =
fetch_from_data_connector(http_client, query, data_connector, project_id)
.await?;
Ok(connector_response.0)
})
})
.in_span_async(
"Execute query using data connector",
SpanVisibility::User,
|| {
Box::pin(async {
set_attribute_on_active_span(
AttributeVisibility::Default,
"operation",
execution_span_attribute,
);
set_attribute_on_active_span(
AttributeVisibility::Default,
"field",
field_span_attribute,
);
let connector_response =
fetch_from_data_connector(http_client, query, data_connector, project_id)
.await?;
Ok(connector_response.0)
})
},
)
.await
}

Expand Down Expand Up @@ -109,56 +113,60 @@ pub(crate) async fn execute_ndc_mutation<'n, 's, 'ir>(
) -> Result<json::Value, error::Error> {
let tracer = tracing_util::global_tracer();
tracer
.in_span_async("Execute mutation using data connector", SpanVisibility::User, || {
Box::pin(async {
set_attribute_on_active_span(
AttributeVisibility::Default,
"operation",
execution_span_attribute,
);
set_attribute_on_active_span(
AttributeVisibility::Default,
"field",
field_span_attribute,
);
let connector_response = fetch_from_data_connector_mutation(
http_client,
query,
data_connector,
project_id,
)
.await?;
// Post process the response to add the `__typename` fields
tracer.in_span("process_response", SpanVisibility::Internal, || {
// NOTE: NDC returns a `Vec<RowSet>` (to account for
// variables). We don't use variables in NDC queries yet,
// hence we always pick the first `RowSet`.
let mutation_results = connector_response
.operation_results
.into_iter()
.next()
.ok_or(error::InternalDeveloperError::BadGDCResponse {
summary: "missing rowset".into(),
})?;
match process_response_as {
ProcessResponseAs::CommandResponse {
command_name: _,
type_container,
} => process_command_mutation_response(
mutation_results,
selection_set,
type_container,
),
_ => Err(error::Error::from(
error::InternalEngineError::InternalGeneric {
description: "mutations without commands are not supported yet"
.into(),
},
)),
}
.in_span_async(
"Execute mutation using data connector",
SpanVisibility::User,
|| {
Box::pin(async {
set_attribute_on_active_span(
AttributeVisibility::Default,
"operation",
execution_span_attribute,
);
set_attribute_on_active_span(
AttributeVisibility::Default,
"field",
field_span_attribute,
);
let connector_response = fetch_from_data_connector_mutation(
http_client,
query,
data_connector,
project_id,
)
.await?;
// Post process the response to add the `__typename` fields
tracer.in_span("process_response", SpanVisibility::Internal, || {
// NOTE: NDC returns a `Vec<RowSet>` (to account for
// variables). We don't use variables in NDC queries yet,
// hence we always pick the first `RowSet`.
let mutation_results = connector_response
.operation_results
.into_iter()
.next()
.ok_or(error::InternalDeveloperError::BadGDCResponse {
summary: "missing rowset".into(),
})?;
match process_response_as {
ProcessResponseAs::CommandResponse {
command_name: _,
type_container,
} => process_command_mutation_response(
mutation_results,
selection_set,
type_container,
),
_ => Err(error::Error::from(
error::InternalEngineError::InternalGeneric {
description: "mutations without commands are not supported yet"
.into(),
},
)),
}
})
})
})
})
},
)
.await
}

Expand Down
5 changes: 4 additions & 1 deletion v3/crates/engine/src/metadata/resolved/data_connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ pub struct DataConnectorLink {
}

impl std::hash::Hash for DataConnectorLink {
fn hash<H>(&self, h: &mut H) where H: std::hash::Hasher {
fn hash<H>(&self, h: &mut H)
where
H: std::hash::Hasher,
{
self.name.hash(h)
}
}
Expand Down
4 changes: 4 additions & 0 deletions v3/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ ci-lint:
fix:
just docker_with_source_only sh -c "cargo clippy --no-deps --fix --allow-no-vcs -- {{ CLIPPY_FIX_ARGS }}; cargo fmt"

format:
cargo fmt --check
alias fmt := format

fix-local:
cargo clippy --no-deps --fix --allow-no-vcs -- {{ CLIPPY_FIX_ARGS }}; cargo fmt

Expand Down

0 comments on commit ec62ea4

Please sign in to comment.