Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Feb 25, 2024
1 parent 611ae5f commit 7f01b2f
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 79 deletions.
105 changes: 60 additions & 45 deletions compiler/crates/graphql-ir/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,16 +454,18 @@ impl<'schema, 'signatures, 'options> Builder<'schema, 'signatures, 'options> {
let mut seen_variables = StringKeyMap::default();
for variable in definitions {
if let Some(other_variable_span) = seen_variables.get(&variable.name.name) {
return Err(vec![Diagnostic::error(
ValidationMessage::DuplicateVariable {
name: variable.name.name,
},
self.location.with_span(variable.span),
)
.annotate(
"conflicts with",
self.location.with_span(*other_variable_span),
)]);
return Err(vec![
Diagnostic::error(
ValidationMessage::DuplicateVariable {
name: variable.name.name,
},
self.location.with_span(variable.span),
)
.annotate(
"conflicts with",
self.location.with_span(*other_variable_span),
),
]);
}
seen_variables.insert(variable.name.name, variable.span);
}
Expand Down Expand Up @@ -1208,13 +1210,15 @@ impl<'schema, 'signatures, 'options> Builder<'schema, 'signatures, 'options> {
for (i, arg) in arguments.items.iter().enumerate() {
for other_arg in arguments.items.iter().skip(i + 1) {
if arg.name.value == other_arg.name.value {
return Err(vec![Diagnostic::error(
ValidationMessage::DuplicateArgument {
name: arg.name.value,
},
self.location.with_span(arg.span),
)
.annotate("conflicts with", self.location.with_span(other_arg.span))]);
return Err(vec![
Diagnostic::error(
ValidationMessage::DuplicateArgument {
name: arg.name.value,
},
self.location.with_span(arg.span),
)
.annotate("conflicts with", self.location.with_span(other_arg.span)),
]);
}
}
}
Expand Down Expand Up @@ -1305,13 +1309,15 @@ impl<'schema, 'signatures, 'options> Builder<'schema, 'signatures, 'options> {
.skip(index + 1)
.find(|other_directive| other_directive.name.item == directive.name.item)
{
return Err(vec![Diagnostic::error(
ValidationMessage::RepeatedNonRepeatableDirective {
name: directive.name.item,
},
repeated_directive.name.location,
)
.annotate("previously used here", directive.name.location)]);
return Err(vec![
Diagnostic::error(
ValidationMessage::RepeatedNonRepeatableDirective {
name: directive.name.item,
},
repeated_directive.name.location,
)
.annotate("previously used here", directive.name.location),
]);
}
}
}
Expand Down Expand Up @@ -1442,14 +1448,16 @@ impl<'schema, 'signatures, 'options> Builder<'schema, 'signatures, 'options> {
let next_type = self.schema.get_type_string(used_as_type);
let next_span = self.location.with_span(variable.span);
let prev_span = self.location.with_span(prev_usage.span);
return Err(vec![Diagnostic::error(
ValidationMessage::IncompatibleVariableUsage {
prev_type,
next_type,
},
next_span,
)
.annotate("is incompatible with", prev_span)]);
return Err(vec![
Diagnostic::error(
ValidationMessage::IncompatibleVariableUsage {
prev_type,
next_type,
},
next_span,
)
.annotate("is incompatible with", prev_span),
]);
}
// If the currently used type is a subtype of the previous usage, then it could
// be a narrower type. Update our inference to reflect the stronger requirements.
Expand Down Expand Up @@ -1574,11 +1582,16 @@ impl<'schema, 'signatures, 'options> Builder<'schema, 'signatures, 'options> {
required_fields.remove(&x.name.value);
let prev_span = seen_fields.insert(x.name.value, x.name.span);
if let Some(prev_span) = prev_span {
return Err(vec![Diagnostic::error(
ValidationMessage::DuplicateInputField(x.name.value),
self.location.with_span(prev_span),
)
.annotate("also defined here", self.location.with_span(x.name.span))]);
return Err(vec![
Diagnostic::error(
ValidationMessage::DuplicateInputField(x.name.value),
self.location.with_span(prev_span),
)
.annotate(
"also defined here",
self.location.with_span(x.name.span),
),
]);
};

let value_span = x.value.span();
Expand Down Expand Up @@ -1722,14 +1735,16 @@ impl<'schema, 'signatures, 'options> Builder<'schema, 'signatures, 'options> {
required_fields.remove(&obj_entry.name.value);
let prev_span = seen_fields.insert(obj_entry.name.value, obj_entry.name.span);
if let Some(prev_span) = prev_span {
return Err(vec![Diagnostic::error(
ValidationMessage::DuplicateInputField(obj_entry.name.value),
self.location.with_span(prev_span),
)
.annotate(
"also defined here",
self.location.with_span(obj_entry.name.span),
)]);
return Err(vec![
Diagnostic::error(
ValidationMessage::DuplicateInputField(obj_entry.name.value),
self.location.with_span(prev_span),
)
.annotate(
"also defined here",
self.location.with_span(obj_entry.name.span),
),
]);
};

let value_span = obj_entry.value.span();
Expand Down
64 changes: 35 additions & 29 deletions compiler/crates/relay-docblock/src/docblock_ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,17 +399,19 @@ fn parse_terse_relay_resolver_ir(

if let Some(fragment_type_condition) = fragment_type_condition {
if fragment_type_condition.item != type_name.value {
return Err(vec![Diagnostic::error(
IrParsingErrorMessages::MismatchRootFragmentTypeConditionTerseSyntax {
fragment_type_condition: fragment_type_condition.item,
type_name: type_name.value,
},
type_str.location.with_span(type_name.span),
)
.annotate(
"with fragment type condition",
fragment_type_condition.location,
)]);
return Err(vec![
Diagnostic::error(
IrParsingErrorMessages::MismatchRootFragmentTypeConditionTerseSyntax {
fragment_type_condition: fragment_type_condition.item,
type_name: type_name.value,
},
type_str.location.with_span(type_name.span),
)
.annotate(
"with fragment type condition",
fragment_type_condition.location,
),
]);
}
}

Expand Down Expand Up @@ -525,14 +527,16 @@ fn combine_edge_to_and_output_type(
(None, Some(output_type)) => {
parse_type_annotation(output_type.value).map(|val| Some(OutputType::Output(val)))
}
(Some(edge_to), Some(output_type)) => Err(vec![Diagnostic::error(
IrParsingErrorMessages::IncompatibleFields {
field_1: AllowedFieldName::EdgeToField,
field_2: AllowedFieldName::OutputTypeField,
},
edge_to.key_location,
)
.annotate("@outputType", output_type.key_location)]),
(Some(edge_to), Some(output_type)) => Err(vec![
Diagnostic::error(
IrParsingErrorMessages::IncompatibleFields {
field_1: AllowedFieldName::EdgeToField,
field_2: AllowedFieldName::OutputTypeField,
},
edge_to.key_location,
)
.annotate("@outputType", output_type.key_location),
]),
}
}

Expand Down Expand Up @@ -646,16 +650,18 @@ fn parse_fragment_definition(
{
for field_arg in &field_arguments.items {
if let Some(fragment_arg) = fragment_arguments.named(field_arg.name.value) {
return Err(vec![Diagnostic::error(
IrParsingErrorMessages::ConflictingArguments,
Location::new(source_location, field_arg.name.span),
)
.annotate(
"conflicts with this fragment argument",
fragment_definition
.location
.with_span(fragment_arg.name.span),
)]);
return Err(vec![
Diagnostic::error(
IrParsingErrorMessages::ConflictingArguments,
Location::new(source_location, field_arg.name.span),
)
.annotate(
"conflicts with this fragment argument",
fragment_definition
.location
.with_span(fragment_arg.name.span),
),
]);
}
}
}
Expand Down
9 changes: 4 additions & 5 deletions compiler/crates/schema/src/in_memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,11 +1628,10 @@ impl InMemorySchema {
let field_name = field_def.name.value;
let field_location = Location::new(source_location_key, field_def.name.span);
if let Some(prev_location) = existing_fields.insert(field_name, field_location) {
return Err(vec![Diagnostic::error(
SchemaError::DuplicateField(field_name),
field_location,
)
.annotate("previously defined here", prev_location)]);
return Err(vec![
Diagnostic::error(SchemaError::DuplicateField(field_name), field_location)
.annotate("previously defined here", prev_location),
]);
}
let arguments = self.build_arguments(&field_def.arguments)?;
let directives = self.build_directive_values(&field_def.directives);
Expand Down

0 comments on commit 7f01b2f

Please sign in to comment.