10000 Remove path from @catch codegen · facebook/relay@460508a · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 460508a

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Remove path from @catch codegen
Reviewed By: tyao1 Differential Revision: D65459455 fbshipit-source-id: 53b6d8d57e289301286ba579983f9ec0f5bf98a1
1 parent a88c013 commit 460508a

File tree

41 files changed

+67
-162
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+67
-162
lines changed

compiler/crates/relay-codegen/src/build_ast.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,6 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> {
10461046
kind: Primitive::String(CODEGEN_CONSTANTS.catch_field),
10471047
field: primitive,
10481048
to: Primitive::String(catch_metadata.to.into()),
1049-
path: Primitive::String(catch_metadata.path),
10501049
}))
10511050
}
10521051

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ fragment MyFragment on Node {
2626
"name": "name",
2727
"storageKey": null
2828
},
29-
"to": "RESULT",
30-
"path": "name"
29+
"to": "RESULT"
3130
}
3231
],
3332
"type": "Node",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_aliased_inline_fragment.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ fragment MyFragment on Node {
3939
"kind": "AliasedInlineFragmentSpread",
4040
"name": "User"
4141
},
42-
"to": "RESULT",
43-
"path": "User"
42+
"to": "RESULT"
4443
}
4544
],
4645
"type": "Node",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_aliased_inline_fragment_no_condition.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ fragment MyFragment on Node {
3939
"kind": "AliasedInlineFragmentSpread",
4040
"name": "myAlias"
4141
},
42-
"to": "RESULT",
43-
"path": "myAlias"
42+
"to": "RESULT"
4443
}
4544
],
4645
"type": "Node",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_linked_child_has_to_result.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ fragment MyFragment on User {
2828
"name": "street",
2929
"storageKey": null
3030
},
31-
"to": "RESULT",
32-
"path": "address.street"
31+
"to": "RESULT"
3332
}
3433
],
3534
"storageKey": null

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_linked_to_result.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ fragment MyFragment on User {
3131
],
3232
"storageKey": null
3333
},
34-
"to": "RESULT",
35-
"path": "address"
34+
"to": "RESULT"
3635
}
3736
],
3837
"type": "User",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_nested_catch.expected

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ fragment MyFragment on User {
3030
"name": "street",
3131
"storageKey": null
3232
},
33-
"to": "RESULT",
34-
"path": "address.street"
33+
"to": "RESULT"
3534
}
3635
],
3736
"storageKey": null
3837
},
39-
"to": "RESULT",
40-
"path": "address"
38+
"to": "RESULT"
4139
}
4240
],
4341
"type": "User",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_nested_linked_different_to.expected

+2-4
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,12 @@ fragment MyFragmentFirst on User {
3030
"name": "lastName",
3131
"storageKey": null
3232
},
33-
"to": "RESULT",
34-
"path": "parents.lastName"
33+
"to": "RESULT"
3534
}
3635
],
3736
"storageKey": null
3837
},
39-
"to": "NULL",
40-
"path": "parents"
38+
"to": "NULL"
4139
}
4240
],
4341
"type": "User",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_nested_linked_with_other_fields.expected

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,12 @@ fragment MyFragmentFirst on User {
3838
"name": "lastName",
3939
"storageKey": null
4040
},
41-
"to": "RESULT",
42-
"path": "parents.lastName"
41+
"to": "RESULT"
4342
}
4443
],
4544
"storageKey": null
4645
},
47-
"to": "NULL",
48-
"path": "parents"
46+
"to": "NULL"
4947
}
5048
],
5149
"type": "User",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_no_args.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ fragment MyFragment on Node {
2626
"name": "name",
2727
"storageKey": null
2828
},
29-
"to": "RESULT",
30-
"path": "name"
29+
"to": "RESULT"
3130
}
3231
],
3332
"type": "Node",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_null_arg.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ fragment MyFragment on Node {
2626
"name": "name",
2727
"storageKey": null
2828
},
29-
"to": "NULL",
30-
"path": "name"
29+
"to": "NULL"
3130
}
3231
],
3332
"type": "Node",

compiler/crates/relay-codegen/tests/catch_directive_codegen/fixtures/catch_directive_on_query.expected

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ query Foo {
3535
"name": "name",
3636
"storageKey": null
3737
},
38-
"to": "RESULT",
39-
"path": "me.name"
38+
"to": "RESULT"
4039
}
4140
],
4241
"storageKey": null

compiler/crates/relay-transforms/src/catch_directive.rs

+19-70
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use std::sync::Arc;
99

10-
use ::intern::string_key::Intern;
1110
use ::intern::string_key::StringKey;
1211
use common::ArgumentName;
1312
use common::Diagnostic;
@@ -29,8 +28,6 @@ use intern::intern;
2928
use lazy_static::lazy_static;
3029
mod catchable_node;
3130
mod validation_message;
32-
use graphql_ir::Field;
33-
use intern::Lookup;
3431

3532
use self::catchable_node::CatchMetadata;
3633
use self::catchable_node::CatchableNode;
@@ -75,7 +72,6 @@ impl From<CatchTo> for StringKey {
7572
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
7673
pub struct CatchMetadataDirective {
7774
pub to: CatchTo,
78-
pub path: StringKey,
7975
}
8076
associated_data_impl!(CatchMetadataDirective);
8177

@@ -105,15 +101,13 @@ struct CatchDirective<'s> {
105101
#[allow(dead_code)]
106102
program: &'s Program,
107103
errors: Vec<Diagnostic>,
108-
path: Vec<&'s str>,
109104
}
110105

111106
impl<'program> CatchDirective<'program> {
112107
fn new(program: &'program Program) -> Self {
113108
Self {
114109
program,
115110
errors: Default::default(),
116-
path: vec![],
117111
}
118112
}
119113

@@ -158,7 +152,7 @@ impl<'s> Transformer for CatchDirective<'s> {
158152
None => self.default_transform_operation(operation),
159153
Some(catch_metadata) => {
160154
let next_directives =
161-
add_metadata_directive(&operation.directives, intern!(""), catch_metadata.to);
155+
add_metadata_directive(&operation.directives, catch_metadata.to);
162156

163157
let selections = self.transform_selections(&operation.selections);
164158

@@ -180,7 +174,7 @@ impl<'s> Transformer for CatchDirective<'s> {
180174
None => self.default_transform_fragment(fragment),
181175
Some(catch_metadata) => {
182176
let next_directives =
183-
add_metadata_directive(&fragment.directives, intern!(""), catch_metadata.to);
177+
add_metadata_directive(&fragment.directives, catch_metadata.to);
184178

185179
let selections = self.transform_selections(&fragment.selections);
186180

@@ -194,36 +188,23 @@ impl<'s> Transformer for CatchDirective<'s> {
194188
}
195189

196190
fn transform_scalar_field(&mut self, field: &ScalarField) -> Transformed<Selection> {
197-
let name = field.alias_or_name(&self.program.schema).lookup();
198-
self.path.push(name);
199-
let path_name: StringKey = self.path.join(".").intern();
200-
self.path.pop();
201-
202191
match self.get_catch_metadata(field) {
203192
None => Transformed::Keep,
204193
Some(catch_metadata) => {
205194
Transformed::Replace(Selection::ScalarField(Arc::new(ScalarField {
206-
directives: add_metadata_directive(
207-
&field.directives,
208-
path_name,
209-
catch_metadata.to,
210-
),
195+
directives: add_metadata_directive(&field.directives, catch_metadata.to),
211196
..field.clone()
212197
})))
213198
}
214199
}
215200
}
216201

217202
fn transform_linked_field(&mut self, field: &LinkedField) -> Transformed<Selection> {
218-
let name = field.alias_or_name(&self.program.schema).lookup();
219-
self.path.push(name);
220-
221203
let maybe_catch_metadata = self.get_catch_metadata(field);
222204

223205
match maybe_catch_metadata {
224206
None => {
225207
let selections = self.transform_selections(&field.selections);
226-
self.path.pop();
227208
if selections.should_keep() {
228209
Transformed::Keep
229210
} else {
@@ -234,14 +215,10 @@ impl<'s> Transformer for CatchDirective<'s> {
234215
}
235216
}
236217
Some(catch_metadata) => {
237-
let path_name = self.path.join(".").intern();
238-
let next_directives =
239-
add_metadata_directive(&field.directives, path_name, catch_metadata.to);
218+
let next_directives = add_metadata_directive(&field.directives, catch_metadata.to);
240219

241220
let selections = self.transform_selections(&field.selections);
242221

243-
self.path.pop();
244-
245222
Transformed::Replace(Selection::LinkedField(Arc::new(LinkedField {
246223
directives: next_directives,
247224
selections: selections.replace_or_else(|| field.selections.clone()),
@@ -257,44 +234,21 @@ impl<'s> Transformer for CatchDirective<'s> {
257234
let maybe_catch_metadata = self.get_catch_metadata(fragment);
258235

259236
match alias {
260-
Some(alias) => {
261-
self.path.push(alias.alias.item.lookup());
262-
match maybe_catch_metadata {
263-
None => {
264-
let selections = self.transform_selections(&fragment.selections);
265-
self.path.pop();
266-
if selections.should_keep() {
267-
Transformed::Keep
268-
} else {
269-
Transformed::Replace(Selection::InlineFragment(Arc::new(
270-
InlineFragment {
271-
selections: selections
272-
.replace_or_else(|| fragment.selections.clone()),
273-
..fragment.clone()
274-
},
275-
)))
276-
}
277-
}
278-
Some(catch_metadata) => {
279-
let path_name = self.path.join(".").intern();
280-
let next_directives = add_metadata_directive(
281-
&fragment.directives,
282-
path_name,
283-
catch_metadata.to,
284-
);
285-
286-
let selections = self.transform_selections(&fragment.selections);
287-
288-
self.path.pop();
289-
290-
Transformed::Replace(Selection::InlineFragment(Arc::new(InlineFragment {
291-
directives: next_directives,
292-
selections: selections.replace_or_else(|| fragment.selections.clone()),
293-
..fragment.clone()
294-
})))
295-
}
237+
Some(_alias) => match maybe_catch_metadata {
238+
None => self.default_transform_inline_fragment(fragment),
239+
Some(catch_metadata) => {
240+
let next_directives =
241+
add_metadata_directive(&fragment.directives, catch_metadata.to);
242+
243+
let selections = self.transform_selections(&fragment.selections);
244+
245+
Transformed::Replace(Selection::InlineFragment(Arc::new(InlineFragment {
246+
directives: next_directives,
247+
selections: selections.replace_or_else(|| fragment.selections.clone()),
248+
..fragment.clone()
249+
})))
296250
}
297-
}
251+
},
298252
None => {
299253
if maybe_catch_metadata.is_some() {
300254
self.errors.push(Diagnostic::error(
@@ -308,17 +262,12 @@ impl<'s> Transformer for CatchDirective<'s> {
308262
}
309263
}
310264

311-
fn add_metadata_directive(
312-
directives: &[Directive],
313-
path_name: StringKey,
314-
to: Option<CatchTo>,
315-
) -> Vec<Directive> {
265+
fn add_metadata_directive(directives: &[Directive], to: Option<CatchTo>) -> Vec<Directive> {
316266
let mut next_directives: Vec<Directive> = Vec::with_capacity(directives.len() + 1);
317267
next_directives.extend(directives.iter().cloned());
318268
next_directives.push(
319269
CatchMetadataDirective {
320270
to: catch_to_with_fallback(to),
321-
path: path_name,
322271
}
323272
.into(),
324273
);

compiler/crates/relay-transforms/tests/catch_directive/fixtures/catch-to-default-usage-inline-fragment-with-alias.expected

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ fragment FragFoo on User {
2222
@__CatchMetadataDirective
2323
# CatchMetadataDirective {
2424
# to: Result,
25-
# path: "User",
2625
# }
2726
{
2827
name

compiler/crates/relay-transforms/tests/catch_directive/fixtures/catch-to-default-usage-query.expected

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ query FragFoo @catch {
88
query FragFoo @catch @__CatchMetadataDirective
99
# CatchMetadataDirective {
1010
# to: Result,
11-
# path: "",
1211
# }
1312
{
1413
me {

compiler/crates/relay-transforms/tests/catch_directive/fixtures/catch-usage-fragment.expected

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ fragment FragFoo on User @catch(to: RESULT) {
66
fragment FragFoo on User @catch(to: RESULT) @__CatchMetadataDirective
77
# CatchMetadataDirective {
88
# to: Result,
9-
# path: "",
109
# }
1110
{
1211
name

compiler/crates/relay-transforms/tests/catch_directive/fixtures/catch-usage-inline-fragment-with-alias.expected

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ fragment FragFoo on User {
2222
@__CatchMetadataDirective
2323
# CatchMetadataDirective {
2424
# to: Result,
25-
# path: "User",
2625
# }
2726
{
2827
name

compiler/crates/r 10000 elay-transforms/tests/catch_directive/fixtures/catch-usage-linked-with-linked-sibling.expected

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ fragment MyFragmentSecond on User {
2121
address @catch(to: RESULT) @__CatchMetadataDirective
2222
# CatchMetadataDirective {
2323
# to: Result,
24-
# path: "address",
2524
# }
2625
{
2726
street

compiler/crates/relay-transforms/tests/catch_directive/fixtures/catch-usage-linked.expected

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ fragment MyFragment on User {
99
address @catch(to: RESULT) @__CatchMetadataDirective
1010
# CatchMetadataDirective {
1111
# to: Result,
12-
# path: "address",
1312
# }
1413
{
1514
street

compiler/crates/relay-transforms/tests/catch_directive/fixtures/catch-usage-nested-catches.expected

-2
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ fragment MyFragmentFirst on User {
99
parents @catch @__CatchMetadataDirective
1010
# CatchMetadataDirective {
1111
# to: Result,
12-
# path: "parents",
1312
# }
1413
{
1514
lastName @catch @__CatchMetadataDirective
1615
# CatchMetadataDirective {
1716
# to: Result,
18-
# path: "parents.lastName",
1917
# }
2018

2119
}

compiler/crates/relay-transforms/tests/catch_directive/fixtures/catch-usage-on-query.expected

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ query Foo {
1212
name @catch @__CatchMetadataDirective
1313
# CatchMetadataDirective {
1414
# to: Result,
15-
# path: "me.name",
1615
# }
1716

1817
}

0 commit comments

Comments
 (0)
0