Skip to content

Commit

Permalink
Use directive location where it makes sense
Browse files Browse the repository at this point in the history
Reviewed By: captbaritone

Differential Revision: D64558729

fbshipit-source-id: 22d1e4e7bfaf28a3c2787fff5912a16d65b3807d
  • Loading branch information
gordyf authored and facebook-github-bot committed Oct 23, 2024
1 parent b0c92e8 commit ebf028b
Show file tree
Hide file tree
Showing 56 changed files with 91 additions and 86 deletions.
4 changes: 2 additions & 2 deletions compiler/crates/graphql-ir/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,9 +1351,9 @@ impl<'schema, 'signatures, 'options> Builder<'schema, 'signatures, 'options> {
ValidationMessage::RepeatedNonRepeatableDirective {
name: directive.name.item,
},
repeated_directive.name.location,
repeated_directive.location,
)
.annotate("previously used here", directive.name.location),
.annotate("previously used here", directive.location),
]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/crates/graphql-ir/src/ir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl InlineFragment {
))),
None => Err(vec![Diagnostic::error(
ValidationMessage::FragmentAliasDirectiveMissingAs,
directive.name.location,
directive.location,
)]),
}
}
Expand Down Expand Up @@ -722,7 +722,7 @@ fn alias_arg_as(alias_directive: &Directive) -> DiagnosticsResult<Option<WithLoc
}
_ => Err(vec![Diagnostic::error(
ValidationMessage::FragmentAliasDirectiveDynamicNameArg,
alias_directive.name.location,
alias_directive.location,
)]),
},
None => Ok(None),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ fragment duplicateDirectiveOnField on User {
duplicate-directive.invalid.graphql:10:37
9 │ fragment duplicateDirectiveOnField on User {
10 │ name @customDirective(level: 1) @customDirective(level: 2)
│ ^^^^^^^^^^^^^^^^
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
11 │ }

ℹ︎ previously used here

duplicate-directive.invalid.graphql:10:10
9 │ fragment duplicateDirectiveOnField on User {
10 │ name @customDirective(level: 1) @customDirective(level: 2)
│ ^^^^^^^^^^^^^^^^
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^
11 │ }


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ impl ApplyFragmentArgumentsTransform<'_, '_, '_> {
"Invalid usage of @no_inline on fragment '{}': this feature is gated and currently set to: {}",
fragment.name.item, self.no_inline_feature
),
directive.name.location,
directive.location,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<'s> Transformer for AssignableFragmentSpread<'s> {
ValidationMessage::AssignableFragmentSpreadNoOtherDirectives {
disallowed_directive_name: directive.name.item.0,
},
directive.name.location,
directive.location,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl<'a> Validator for AssignableDirective<'a> {
ValidationMessage::AssignableDisallowOtherDirectives {
disallowed_directive_name: directive.name.item.0,
},
directive.name.location,
directive.location,
))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ impl<'a> Validator for UpdatableDirective<'a> {
disallowed_directive_name: directive.name.item.0,
outer_type_plural: self.executable_definition_info.unwrap().type_plural,
},
directive.name.location,
directive.location,
)])
} else {
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions compiler/crates/relay-transforms/src/client_edges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ impl<'program, 'pc> ClientEdgesTransform<'program, 'pc> {
ValidationMessage::ClientEdgeUnsupportedDirective {
directive_name: directive.name.item,
},
directive.name.location,
directive.location,
));
}
}
Expand All @@ -350,7 +350,7 @@ impl<'program, 'pc> ClientEdgesTransform<'program, 'pc> {
if let Some(directive) = waterfall_directive {
self.errors.push(Diagnostic::error_with_data(
ValidationMessageWithData::RelayResolversUnexpectedWaterfall,
directive.name.location,
directive.location,
));
}

Expand Down Expand Up @@ -542,7 +542,7 @@ impl<'program, 'pc> ClientEdgesTransform<'program, 'pc> {
if let Some(directive) = waterfall_directive {
self.errors.push(Diagnostic::error_with_data(
ValidationMessageWithData::RelayResolversUnexpectedWaterfall,
directive.name.location,
directive.location,
));
}
return self.default_transform_linked_field(field);
Expand Down Expand Up @@ -684,7 +684,7 @@ impl Transformer for ClientEdgesTransform<'_, '_> {
{
self.errors.push(Diagnostic::error_with_data(
ValidationMessageWithData::RelayResolversUnexpectedWaterfall,
directive.name.location,
directive.location,
));
}
self.default_transform_scalar_field(field)
Expand Down
14 changes: 7 additions & 7 deletions compiler/crates/relay-transforms/src/declarative_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Transformer for DeclarativeConnectionMutationTransform<'_> {
field_name: field.alias_or_name(self.schema),
current_type: self.schema.get_type_string(&field_definition.type_),
},
delete_directive.name.location,
delete_directive.location,
));
Transformed::Keep
} else {
Expand Down Expand Up @@ -198,7 +198,7 @@ impl Transformer for DeclarativeConnectionMutationTransform<'_> {
node_directive_name: node_directive.name.item,
field_name: field.alias_or_name(self.schema),
},
edge_directive.name.location,
edge_directive.location,
));
transformed_field
}
Expand All @@ -211,7 +211,7 @@ impl Transformer for DeclarativeConnectionMutationTransform<'_> {
ValidationMessage::ConnectionsArgumentRequired {
directive_name: edge_directive.name.item,
},
edge_directive.name.location,
edge_directive.location,
));
transformed_field
}
Expand Down Expand Up @@ -262,7 +262,7 @@ impl Transformer for DeclarativeConnectionMutationTransform<'_> {
directive_name: edge_directive.name.item,
field_name: field.alias_or_name(self.schema),
},
edge_directive.name.location,
edge_directive.location,
));
Transformed::Keep
}
Expand All @@ -277,7 +277,7 @@ impl Transformer for DeclarativeConnectionMutationTransform<'_> {
ValidationMessage::ConnectionsArgumentRequired {
directive_name: node_directive.name.item,
},
node_directive.name.location,
node_directive.location,
));
transformed_field
}
Expand Down Expand Up @@ -359,7 +359,7 @@ impl Transformer for DeclarativeConnectionMutationTransform<'_> {
.schema
.get_type_string(&field_definition.type_),
},
node_directive.name.location,
node_directive.location,
));
Transformed::Keep
}
Expand All @@ -370,7 +370,7 @@ impl Transformer for DeclarativeConnectionMutationTransform<'_> {
directive_name: node_directive.name.item,
field_name: field.alias_or_name(self.schema),
},
node_directive.name.location,
node_directive.location,
));
Transformed::Keep
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/crates/relay-transforms/src/defer_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl DeferStreamTransform<'_> {
},
prev.name.location,
)
.annotate("related location", directive.name.location),
.annotate("related location", directive.location),
);
}
None => {
Expand Down Expand Up @@ -318,7 +318,7 @@ impl<'s> Transformer for DeferStreamTransform<'s> {
}
self.errors.push(Diagnostic::error(
ValidationMessage::InvalidDeferOnInlineFragment,
directive.name.location,
directive.location,
));
}

Expand Down Expand Up @@ -353,7 +353,7 @@ impl<'s> Transformer for DeferStreamTransform<'s> {
ValidationMessage::InvalidStreamOnScalarField {
field_name: scalar_field.alias_or_name(&self.program.schema),
},
directive.name.location,
directive.location,
));
}
self.default_transform_scalar_field(scalar_field)
Expand Down Expand Up @@ -410,7 +410,7 @@ fn get_literal_string_argument(
arg_name: arg.name.item,
directive_name: directive.name.item,
},
directive.name.location,
directive.location,
))
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl Transformer for GenerateLiveQueryMetadata {
LiveQueryTransformValidationMessage::MissingConfig {
query_name: operation.name.item,
},
live_query_directive.name.location,
live_query_directive.location,
));
return Transformed::Keep;
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/crates/relay-transforms/src/inline_data_fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ impl<'s> InlineDataFragmentsTransform<'s> {
ValidationMessage::InlineDataFragmentDirectivesNotSupported {
directive_name: not_allowed_directive.name.item,
},
not_allowed_directive.name.location,
not_allowed_directive.location,
)
.annotate(
"spread is marked as `@inline` here",
inline_directive.name.location,
inline_directive.location,
),
);
}
Expand Down
13 changes: 5 additions & 8 deletions compiler/crates/relay-transforms/src/match_/match_transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl<'program, 'flag> MatchTransform<'program, 'flag> {
ValidationMessage::InvalidModuleWithAdditionalDirectives {
spread_name: spread.fragment.item,
},
invalid_directive.name.location,
invalid_directive.location,
));
}

Expand All @@ -386,12 +386,9 @@ impl<'program, 'flag> MatchTransform<'program, 'flag> {
if let Some(inline_data_directive) = fragment.directives.named(*INLINE_DIRECTIVE_NAME) {
return Err(Diagnostic::error(
ValidationMessage::InvalidModuleWithInline,
module_directive.name.location,
module_directive.location,
)
.annotate(
"@inline directive location",
inline_data_directive.name.location,
));
.annotate("@inline directive location", inline_data_directive.location));
}

let module_directive_name_argument =
Expand Down Expand Up @@ -712,7 +709,7 @@ impl<'program, 'flag> MatchTransform<'program, 'flag> {
if key_arg.is_none() {
return Err(Diagnostic::error(
ValidationMessage::InvalidMatchWithNoSupportedArgument,
match_directive.name.location,
match_directive.location,
));
}
return Ok(if let TransformedValue::Keep = next_selections {
Expand Down Expand Up @@ -830,7 +827,7 @@ impl<'program, 'flag> MatchTransform<'program, 'flag> {
if seen_types.is_empty() {
return Err(Diagnostic::error(
ValidationMessage::InvalidMatchNoModuleSelection,
match_directive.name.location,
match_directive.location,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'program, 'pc> RefetchableFragment<'program, 'pc> {
ValidationMessage::InvalidRefetchableFragmentWithRelayPlural {
fragment_name: fragment.name.item,
},
directive.name.location,
directive.location,
)])
} else {
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions compiler/crates/relay-transforms/src/relay_actor_change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'program, 'feature> Transformer for ActorChangeTransform<'program, 'feature
.schema
.get_type_name(viewer_field.type_.inner()),
},
actor_change_directive.name.location,
actor_change_directive.location,
));
return Transformed::Keep;
} else {
Expand All @@ -151,7 +151,7 @@ impl<'program, 'feature> Transformer for ActorChangeTransform<'program, 'feature
field_name: schema_field.name.item,
type_name: self.program.schema.get_type_name(field_type),
},
actor_change_directive.name.location,
actor_change_directive.location,
));
return Transformed::Keep;
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/crates/relay-transforms/src/relay_resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl<'program> RelayResolverFieldTransform<'program> {
if let Some(directive) = non_required_directives.next() {
self.errors.push(Diagnostic::error(
ValidationMessage::RelayResolverUnexpectedDirective,
directive.name.location,
directive.location,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn get_action_argument(
let action_arg = maybe_action_arg.ok_or_else(|| {
Diagnostic::error(
RequiredDirectiveValidationMessage::ActionArgumentRequired,
required_directive.name.location,
required_directive.location,
)
})?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a> Transformer for GenerateTestOperationMetadata<'a> {
ValidationMessage::TestOperationOutsideTestDirectory {
test_path_regex: test_path_regex.to_string(),
},
test_operation_directive.name.location,
test_operation_directive.location,
));
return Transformed::Keep;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ impl<'a> Validator for DeprecatedFields<'a> {
if directive_definition.name.item == *FRAGMENT_DANGEROUSLY_UNALIAS_DIRECTIVE_NAME {
self.warnings.push(Diagnostic::hint_with_data(
ValidationMessageWithData::DeprecatedDangerouslyUnaliasedDirective,
directive.name.location,
directive.location,
vec![DiagnosticTag::DEPRECATED],
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'program> DisallowReadtimeFeaturesInMutations<'program> {
if *action == *THROW_ACTION {
return Err(vec![Diagnostic::error(
ValidationMessage::RequiredInMutation,
directive.name.location,
directive.location,
)]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<'a> DisallowRequiredOnNonNullField<'a> {
{
self.warnings.push(Diagnostic::hint(
ValidationMessageWithData::RequiredOnNonNull,
required_directive.unwrap().name.location,
required_directive.unwrap().location,
vec![DiagnosticTag::UNNECESSARY],
));
} else if self
Expand All @@ -99,7 +99,7 @@ impl<'a> DisallowRequiredOnNonNullField<'a> {
// @required on a semantically-non-null field is unnecessary
self.warnings.push(Diagnostic::hint(
ValidationMessageWithData::RequiredOnSemanticNonNull,
required_directive.unwrap().name.location,
required_directive.unwrap().location,
vec![DiagnosticTag::UNNECESSARY],
));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ impl<'s> ConnectionValidation<'s> {
connection_field_name: connection_schema_field.name.item,
key_arg_name: *KEY_ARG_NAME,
},
connection_directive.name.location,
connection_directive.location,
)]);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Validator for ValidateRequiredArguments<'_> {
&definition.arguments,
&directive.arguments,
directive.name.item.0,
directive.name.location,
directive.location,
self.root_name_with_location.unwrap(),
)
} else {
Expand Down
Loading

0 comments on commit ebf028b

Please sign in to comment.