-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add opt in flag to adopt orphan extensions
- Loading branch information
1 parent
dd263f1
commit ec52553
Showing
4 changed files
with
204 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use apollo_compiler::Schema; | ||
|
||
#[test] | ||
fn test_orphan_extensions() { | ||
let input = r#" | ||
extend schema @dir | ||
extend type Obj @dir | ||
directive @dir on SCHEMA | OBJECT | ||
"#; | ||
|
||
// By default, orphan extensions are errors: | ||
let schema = Schema::parse(input, "schema.graphql"); | ||
assert!(!schema.schema_definition_directives().has("dir")); | ||
assert!(!schema.types.contains_key("Obj")); | ||
let err = schema.validate().unwrap_err().to_string_no_color(); | ||
assert!( | ||
err.contains("schema extension without a schema definition"), | ||
"{err}" | ||
); | ||
assert!( | ||
err.contains("type extension for undefined type `Obj`"), | ||
"{err}" | ||
); | ||
|
||
// Opt in to non-standard behavior of adopting them instead: | ||
let schema2 = Schema::builder() | ||
.adopt_orphan_extensions() | ||
.parse(input, "schema.graphql") | ||
.build(); | ||
assert!(schema2.schema_definition_directives().has("dir")); | ||
assert!(schema2.types["Obj"].directives().has("dir")); | ||
schema2.validate().unwrap(); | ||
} | ||
|
||
#[test] | ||
fn test_orphan_extensions_kind_mismatch() { | ||
let input = r#" | ||
extend type T @dir | ||
extend interface T @dir | ||
directive @dir repeatable on SCHEMA | OBJECT | ||
"#; | ||
|
||
let schema = Schema::builder() | ||
.adopt_orphan_extensions() | ||
.parse(input, "schema.graphql") | ||
.build(); | ||
let type_def = &schema.types["T"]; | ||
assert!(type_def.is_object()); | ||
assert_eq!(type_def.directives().get_all("dir").count(), 1); | ||
let err = schema.validate().unwrap_err().to_string_no_color(); | ||
assert!( | ||
err.contains("adding an interface type extension, but `T` is an object type"), | ||
"{err}" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod executable; | ||
mod extensions; | ||
mod merge_schemas; | ||
/// Formerly in src/lib.rs | ||
mod misc; | ||
|