Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/apollo-compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm

## Features

- **Update `ignore_builtin_redefinitions` option to allow SDL to contain built-in meta type definitions - [dariuszkuc], [pull/994]**
- **Adds `ignore_builtin_redefinitions` option to `SchemaBuilder` to allow SDL to contain built-in
scalar definitions - [dariuszkuc], [pull/990]**

Expand Down
16 changes: 8 additions & 8 deletions crates/apollo-compiler/src/schema/from_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ impl SchemaBuilder {
}
Entry::Occupied(entry) => {
let previous = entry.get();
if self.ignore_builtin_redefinitions && previous.is_built_in() {
continue;
}

if $is_scalar && previous.is_built_in() {
if self.ignore_builtin_redefinitions {
continue;
} else {
self.errors.push(
$def.location(),
BuildError::BuiltInScalarTypeRedefinition,
)
}
self.errors.push(
$def.location(),
BuildError::BuiltInScalarTypeRedefinition,
)
} else {
self.errors.push(
$def.name.location(),
Expand Down
47 changes: 46 additions & 1 deletion crates/apollo-compiler/tests/validation/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,7 @@ mod variable_default_values {
}

#[test]
fn handles_built_in_type_redefinition() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This types.rs file was for ValuesOfCorrectType Rule tests, so I moved these builtin_type_redefinition tests into their own file.

fn handles_built_in_scalar_redefinition() {
let schema = r#"
scalar String

Expand Down Expand Up @@ -2049,3 +2049,48 @@ type Query {
.build()
.expect("schema parsed successfully");
}

#[test]
fn handles_built_in_type_redefinition() {
let schema = r#"
type __Directive {
name: String!
description: String!
isRepeatable: String!
args: __InputValue
locations: String!
}

type Query {
foo: String
}
"#;

let errors = Schema::parse_and_validate(schema, "schema.graphql")
.expect_err("invalid schema")
.errors;
let expected = expect![[r#"
Error: the type `__Directive` is defined multiple times in the schema
╭─[ built_in.graphql:87:6 ]
87 │ type __Directive {
│ ─────┬─────
│ ╰─────── previous definition of `__Directive` here
├─[ schema.graphql:2:6 ]
2 │ type __Directive {
│ ─────┬─────
│ ╰─────── `__Directive` redefined here
│ Help: remove or rename one of the definitions, or use `extend`
────╯
"#]];
expected.assert_eq(&errors.to_string());

let builder = SchemaBuilder::new().ignore_builtin_redefinitions();
let _ = builder
.parse(schema, "schema.graphql")
.build()
.expect("schema parsed successfully");
}