Skip to content

Commit

Permalink
Report schema location for invalid types (#3924)
Browse files Browse the repository at this point in the history
Summary:
With Client Edges, if you specify an `edge_to` with an invalid type name we were previously reporting an error at a generated location.

<img width="1124" alt="Screen Shot 2022-05-25 at 8 39 24 AM" src="https://user-images.githubusercontent.com/162735/170302170-2bf3004d-e118-4c2b-a863-fd2d899a6555.png">

This also ensures we provide a correct error location when you type a field type in a client schema extension.

Pull Request resolved: #3924

Test Plan:
Create a Relay Resolver with `edge_to Foo` and see an error message that points to the correct location:

<img width="1126" alt="Screen Shot 2022-05-25 at 8 28 44 AM" src="https://user-images.githubusercontent.com/162735/170302024-342524e0-8a64-4afb-a2a9-ea676f2eee11.png">

Reviewed By: voideanvalue

Differential Revision: D36667389

Pulled By: captbaritone

fbshipit-source-id: 700414188c75f3043c889cf3fa7dce6841168da7
  • Loading branch information
captbaritone authored and facebook-github-bot committed May 26, 2022
1 parent b73f35e commit 384315d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
19 changes: 10 additions & 9 deletions compiler/crates/schema/src/in_memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1348,7 +1348,7 @@ impl InMemorySchema {
.iter()
.map(|field_def| {
let arguments = self.build_arguments(&field_def.arguments)?;
let type_ = self.build_type_reference(&field_def.type_)?;
let type_ = self.build_type_reference(&field_def.type_, field_location_key)?;
let directives = self.build_directive_values(&field_def.directives);
let description = field_def.description.as_ref().map(|desc| desc.value);
Ok(self.build_field(Field {
Expand Down Expand Up @@ -1390,7 +1390,7 @@ impl InMemorySchema {
}
let arguments = self.build_arguments(&field_def.arguments)?;
let directives = self.build_directive_values(&field_def.directives);
let type_ = self.build_type_reference(&field_def.type_)?;
let type_ = self.build_type_reference(&field_def.type_, source_location_key)?;
let description = field_def.description.as_ref().map(|desc| desc.value);
field_ids.push(self.build_field(Field {
name: WithLocation::new(field_location, field_name),
Expand Down Expand Up @@ -1465,22 +1465,23 @@ impl InMemorySchema {
fn build_type_reference(
&mut self,
ast_type: &TypeAnnotation,
source_location: SourceLocationKey,
) -> DiagnosticsResult<TypeReference> {
Ok(match ast_type {
TypeAnnotation::Named(named_type) => TypeReference::Named(
*self.type_map.get(&named_type.name.value).ok_or_else(|| {
vec![Diagnostic::error(
SchemaError::UndefinedType(named_type.name.value),
Location::generated(),
Location::new(source_location, named_type.name.span),
)]
})?,
),
TypeAnnotation::NonNull(of_type) => {
TypeReference::NonNull(Box::new(self.build_type_reference(&of_type.type_)?))
}
TypeAnnotation::List(of_type) => {
TypeReference::List(Box::new(self.build_type_reference(&of_type.type_)?))
}
TypeAnnotation::NonNull(of_type) => TypeReference::NonNull(Box::new(
self.build_type_reference(&of_type.type_, source_location)?,
)),
TypeAnnotation::List(of_type) => TypeReference::List(Box::new(
self.build_type_reference(&of_type.type_, source_location)?,
)),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ type User {
==================================== ERROR ====================================
✖︎ Reference to undefined type 'Email'.

<generated>:1:1
1 │ # expected-to-throw
│ ^
2 │
<generated>:4:12
3 │ type User {
4 │ emails: [Email!]!
│ ^^^^^
5 │ }

0 comments on commit 384315d

Please sign in to comment.