Repository: apollographql/apollo-rs
Pull request #515 (2023-04-04 23:12:05)

chore(encoder): add missing clone impl to encoder types
Noticed that `Clone` was derived on some but not all encoder types when I tried to `.clone()` an `encoder::ObjectDefinition` instance. 

Not sure if there's a good reason, but ahead and opened this PR if it just happened to be an omission.


Patch:
diff --git a/crates/apollo-compiler/src/validation/directive.rs b/crates/apollo-compiler/src/validation/directive.rs
index 8969bca..bc68756 100644
--- a/crates/apollo-compiler/src/validation/directive.rs
+++ b/crates/apollo-compiler/src/validation/directive.rs
@@ -171,19 +171,19 @@ pub fn validate_directives(
 
             if !is_repeatable {
                 // original loc must be Some
-                let loc = original.loc.expect("undefined original directive location");
+                let original_loc = original.loc.expect("undefined original directive location");
                 diagnostics.push(
                     ApolloDiagnostic::new(
                         db,
                         loc.into(),
                         DiagnosticData::UniqueDirective {
                             name: name.to_string(),
-                            original_call: loc.into(),
+                            original_call: original_loc.into(),
                             conflicting_call: loc.into(),
                         },
                     )
                     .label(Label::new(
-                        loc,
+                        original_loc,
                         format!("directive {name} first called here"),
                     ))
                     .label(Label::new(
diff --git a/crates/apollo-encoder/src/directive_def.rs b/crates/apollo-encoder/src/directive_def.rs
index a29168b..b134297 100644
--- a/crates/apollo-encoder/src/directive_def.rs
+++ b/crates/apollo-encoder/src/directive_def.rs
@@ -30,7 +30,7 @@ use crate::{ArgumentsDefinition, InputValueDefinition, StringValue};
 /// "#
 /// );
 /// ```
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct DirectiveDefinition {
     // Name must return a String.
     name: String,
diff --git a/crates/apollo-encoder/src/document.rs b/crates/apollo-encoder/src/document.rs
index 6ee830c..378f164 100644
--- a/crates/apollo-encoder/src/document.rs
+++ b/crates/apollo-encoder/src/document.rs
@@ -73,7 +73,7 @@ use crate::{
 ///     "#}
 /// );
 /// ```
-#[derive(Debug, Default)]
+#[derive(Debug, Clone, Default)]
 pub struct Document {
     operation_definitions: Vec<OperationDefinition>,
     fragment_definitions: Vec<FragmentDefinition>,
diff --git a/crates/apollo-encoder/src/fragment.rs b/crates/apollo-encoder/src/fragment.rs
index 88593e8..a5a3487 100644
--- a/crates/apollo-encoder/src/fragment.rs
+++ b/crates/apollo-encoder/src/fragment.rs
@@ -34,7 +34,7 @@ use crate::{Directive, SelectionSet};
 ///     "#}
 /// );
 /// ```
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct FragmentDefinition {
     name: String,
     type_condition: TypeCondition,
diff --git a/crates/apollo-encoder/src/object_def.rs b/crates/apollo-encoder/src/object_def.rs
index 4e2c8b6..7ff9d3f 100644
--- a/crates/apollo-encoder/src/object_def.rs
+++ b/crates/apollo-encoder/src/object_def.rs
@@ -51,7 +51,7 @@ use crate::{Directive, FieldDefinition, StringValue};
 ///     "#}
 /// );
 /// ```
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct ObjectDefinition {
     // Name must return a String.
     name: String,
diff --git a/crates/apollo-encoder/src/operation.rs b/crates/apollo-encoder/src/operation.rs
index 2e675c4..fb0fad9 100644
--- a/crates/apollo-encoder/src/operation.rs
+++ b/crates/apollo-encoder/src/operation.rs
@@ -51,7 +51,7 @@ use crate::{Directive, SelectionSet, VariableDefinition};
 ///     "#}
 /// );
 /// ```
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct OperationDefinition {
     operation_type: OperationType,
     name: Option<String>,
@@ -139,7 +139,7 @@ impl fmt::Display for OperationDefinition {
 ///     query | mutation | subscription
 ///
 /// Detailed documentation can be found in [GraphQL spec](https://spec.graphql.org/October2021/#OperationType).
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub enum OperationType {
     /// Represents a query operation
     Query,
diff --git a/crates/apollo-encoder/src/variable.rs b/crates/apollo-encoder/src/variable.rs
index d51fee6..19bc30f 100644
--- a/crates/apollo-encoder/src/variable.rs
+++ b/crates/apollo-encoder/src/variable.rs
@@ -29,7 +29,7 @@ use crate::{Directive, Type_, Value};
 ///     String::from(r#"$my_var: MyType = { first: 25, second: "test" }"#)
 /// );
 /// ```
-#[derive(Debug)]
+#[derive(Debug, Clone)]
 pub struct VariableDefinition {
     variable: String,
     ty: Type_,


Test patch:
diff --git a/crates/apollo-compiler/test_data/diagnostics/0079_directive_is_unique.txt b/crates/apollo-compiler/test_data/diagnostics/0079_directive_is_unique.txt
index 1b7c3e3..f408379 100644
--- a/crates/apollo-compiler/test_data/diagnostics/0079_directive_is_unique.txt
+++ b/crates/apollo-compiler/test_data/diagnostics/0079_directive_is_unique.txt
@@ -8,7 +8,7 @@
             file_id: FileId {
                 id: 76,
             },
-            offset: 164,
+            offset: 172,
             length: 7,
         },
         labels: [
@@ -27,7 +27,7 @@
                     file_id: FileId {
                         id: 76,
                     },
-                    offset: 164,
+                    offset: 172,
                     length: 7,
                 },
                 text: "directive unique called again here",
@@ -47,7 +47,7 @@
                 file_id: FileId {
                     id: 76,
                 },
-                offset: 164,
+                offset: 172,
                 length: 7,
             },
         },
diff --git a/crates/apollo-compiler/test_data/diagnostics/0080_directive_is_unique_with_extensions.txt b/crates/apollo-compiler/test_data/diagnostics/0080_directive_is_unique_with_extensions.txt
index 52545c5..a109078 100644
--- a/crates/apollo-compiler/test_data/diagnostics/0080_directive_is_unique_with_extensions.txt
+++ b/crates/apollo-compiler/test_data/diagnostics/0080_directive_is_unique_with_extensions.txt
@@ -64,7 +64,7 @@
             file_id: FileId {
                 id: 77,
             },
-            offset: 178,
+            offset: 214,
             length: 14,
         },
         labels: [
@@ -83,7 +83,7 @@
                     file_id: FileId {
                         id: 77,
                     },
-                    offset: 178,
+                    offset: 214,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -103,7 +103,7 @@
                 file_id: FileId {
                     id: 77,
                 },
-                offset: 178,
+                offset: 214,
                 length: 14,
             },
         },
@@ -117,7 +117,7 @@
             file_id: FileId {
                 id: 77,
             },
-            offset: 110,
+            offset: 79,
             length: 14,
         },
         labels: [
@@ -136,7 +136,7 @@
                     file_id: FileId {
                         id: 77,
                     },
-                    offset: 110,
+                    offset: 79,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -156,7 +156,7 @@
                 file_id: FileId {
                     id: 77,
                 },
-                offset: 110,
+                offset: 79,
                 length: 14,
             },
         },
@@ -170,7 +170,7 @@
             file_id: FileId {
                 id: 77,
             },
-            offset: 110,
+            offset: 148,
             length: 14,
         },
         labels: [
@@ -189,7 +189,7 @@
                     file_id: FileId {
                         id: 77,
                     },
-                    offset: 110,
+                    offset: 148,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -209,7 +209,7 @@
                 file_id: FileId {
                     id: 77,
                 },
-                offset: 110,
+                offset: 148,
                 length: 14,
             },
         },
diff --git a/crates/apollo-compiler/test_data/diagnostics/0081_directive_is_unique_type_system.txt b/crates/apollo-compiler/test_data/diagnostics/0081_directive_is_unique_type_system.txt
index 4fa7295..50f1e64 100644
--- a/crates/apollo-compiler/test_data/diagnostics/0081_directive_is_unique_type_system.txt
+++ b/crates/apollo-compiler/test_data/diagnostics/0081_directive_is_unique_type_system.txt
@@ -8,7 +8,7 @@
             file_id: FileId {
                 id: 78,
             },
-            offset: 97,
+            offset: 112,
             length: 14,
         },
         labels: [
@@ -27,7 +27,7 @@
                     file_id: FileId {
                         id: 78,
                     },
-                    offset: 97,
+                    offset: 112,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -47,7 +47,7 @@
                 file_id: FileId {
                     id: 78,
                 },
-                offset: 97,
+                offset: 112,
                 length: 14,
             },
         },
@@ -61,7 +61,7 @@
             file_id: FileId {
                 id: 78,
             },
-            offset: 162,
+            offset: 177,
             length: 14,
         },
         labels: [
@@ -80,7 +80,7 @@
                     file_id: FileId {
                         id: 78,
                     },
-                    offset: 162,
+                    offset: 177,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -100,7 +100,7 @@
                 file_id: FileId {
                     id: 78,
                 },
-                offset: 162,
+                offset: 177,
                 length: 14,
             },
         },
@@ -114,7 +114,7 @@
             file_id: FileId {
                 id: 78,
             },
-            offset: 336,
+            offset: 351,
             length: 14,
         },
         labels: [
@@ -133,7 +133,7 @@
                     file_id: FileId {
                         id: 78,
                     },
-                    offset: 336,
+                    offset: 351,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -153,7 +153,7 @@
                 file_id: FileId {
                     id: 78,
                 },
-                offset: 336,
+                offset: 351,
                 length: 14,
             },
         },
@@ -167,7 +167,7 @@
             file_id: FileId {
                 id: 78,
             },
-            offset: 290,
+            offset: 305,
             length: 14,
         },
         labels: [
@@ -186,7 +186,7 @@
                     file_id: FileId {
                         id: 78,
                     },
-                    offset: 290,
+                    offset: 305,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -206,7 +206,7 @@
                 file_id: FileId {
                     id: 78,
                 },
-                offset: 290,
+                offset: 305,
                 length: 14,
             },
         },
@@ -220,7 +220,7 @@
             file_id: FileId {
                 id: 78,
             },
-            offset: 382,
+            offset: 397,
             length: 14,
         },
         labels: [
@@ -239,7 +239,7 @@
                     file_id: FileId {
                         id: 78,
                     },
-                    offset: 382,
+                    offset: 397,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -259,7 +259,7 @@
                 file_id: FileId {
                     id: 78,
                 },
-                offset: 382,
+                offset: 397,
                 length: 14,
             },
         },
@@ -273,7 +273,7 @@
             file_id: FileId {
                 id: 78,
             },
-            offset: 236,
+            offset: 251,
             length: 14,
         },
         labels: [
@@ -292,7 +292,7 @@
                     file_id: FileId {
                         id: 78,
                     },
-                    offset: 236,
+                    offset: 251,
                     length: 14,
                 },
                 text: "directive nonRepeatable called again here",
@@ -312,7 +312,7 @@
                 file_id: FileId {
                     id: 78,
                 },
-                offset: 236,
+                offset: 251,
                 length: 14,
             },
         },