Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5f1eb8a

Browse files
Add path resolution for fragment arguments (#4651)
Summary: Pull Requestresolved:#4651Reviewed By: tyao1Differential Revision: D54962574Pulled By: captbaritonefbshipit-source-id: 9b404f6259762142a4ded3011fb0d2db0e2c69ea
1 parente46bebe commit5f1eb8a

File tree

4 files changed

+154
-15
lines changed

4 files changed

+154
-15
lines changed

‎compiler/crates/relay-lsp/src/hover/with_resolution_path.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ fn get_hover_contents(
454454
schema,
455455
schema_name,
456456
schema_documentation,
457+
program,
457458
content_consumer_type,
458459
),
459460
HoverBehavior::ScalarOrLinkedField(field_name, selection_path) =>{
@@ -471,6 +472,7 @@ fn get_hover_contents(
471472
schema,
472473
schema_name,
473474
schema_documentation,
475+
program,
474476
content_consumer_type,
475477
),
476478
HoverBehavior::InlineFragment(inline_fragment_path) =>on_hover_inline_fragment(
@@ -552,6 +554,7 @@ fn on_hover_constant_value<'a>(
552554
schema:&SDLSchema,
553555
schema_name:StringKey,
554556
schema_documentation:&implSchemaDocumentation,
557+
program:&Program,
555558
content_consumer_type:ContentConsumerType,
556559
) ->Option<HoverContents>{
557560
match constant_value_parent.find_constant_value_root(){
@@ -567,6 +570,7 @@ fn on_hover_constant_value<'a>(
567570
schema,
568571
schema_name,
569572
schema_documentation,
573+
program,
570574
content_consumer_type,
571575
),
572576
}
@@ -577,6 +581,7 @@ fn on_hover_argument_path(
577581
schema:&SDLSchema,
578582
schema_name:StringKey,
579583
schema_documentation:&implSchemaDocumentation,
584+
program:&Program,
580585
content_consumer_type:ContentConsumerType,
581586
) ->Option<HoverContents>{
582587
letArgumentPath{
@@ -609,6 +614,14 @@ fn on_hover_argument_path(
609614
schema_documentation,
610615
content_consumer_type,
611616
),
617+
ArgumentRoot::FragmentSpread(fragment_spread_path) =>get_fragment_spread_hover_content(
618+
fragment_spread_path,
619+
schema,
620+
schema_name,
621+
schema_documentation,
622+
program,
623+
content_consumer_type,
624+
),
612625
}?;
613626

614627
letmut contents =vec![argument_info];
@@ -843,6 +856,26 @@ fn on_hover_fragment_spread<'a>(
843856
program:&Program,
844857
content_consumer_type:ContentConsumerType,
845858
) ->Option<HoverContents>{
859+
let hover_contents =get_fragment_spread_hover_content(
860+
fragment_spread_path,
861+
schema,
862+
schema_name,
863+
schema_documentation,
864+
program,
865+
content_consumer_type,
866+
)?;
867+
868+
Some(HoverContents::Array(hover_contents))
869+
}
870+
871+
fnget_fragment_spread_hover_content<'a>(
872+
fragment_spread_path:&'aFragmentSpreadPath<'a>,
873+
schema:&SDLSchema,
874+
schema_name:StringKey,
875+
schema_documentation:&implSchemaDocumentation,
876+
program:&Program,
877+
content_consumer_type:ContentConsumerType,
878+
) ->Option<Vec<MarkedString>>{
846879
// TODO eventually show information about whether the fragment spread is
847880
// infallible, fallible, interface-on-interface, etc.
848881

@@ -947,7 +980,7 @@ For example:
947980
hover_contents.push(MarkedString::String(type_description.to_string()));
948981
}
949982

950-
Some(HoverContents::Array(hover_contents))
983+
Some(hover_contents)
951984
}
952985

953986
fnon_hover_directive(

‎compiler/crates/resolution-path/src/argument_root.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ impl<'a> ArgumentParent<'a> {
1313
Self::Directive(directive_path) =>ArgumentRoot::Directive(directive_path),
1414
Self::ScalarField(scalar_field_path) =>ArgumentRoot::ScalarField(scalar_field_path),
1515
Self::LinkedField(linked_field_path) =>ArgumentRoot::LinkedField(linked_field_path),
16+
Self::FragmentSpread(fragment_spread_path) =>{
17+
ArgumentRoot::FragmentSpread(fragment_spread_path)
18+
}
1619
Self::ConstantObject(ConstantObjectPath{inner: _, parent}) => parent
1720
.parent
1821
.find_enclosing_argument_path()
@@ -33,6 +36,7 @@ pub enum ArgumentRoot<'a> {
3336
LinkedField(&'aLinkedFieldPath<'a>),
3437
ScalarField(&'aScalarFieldPath<'a>),
3538
Directive(&'aDirectivePath<'a>),
39+
FragmentSpread(&'aFragmentSpreadPath<'a>),
3640
}
3741

3842
#[cfg(test)]

‎compiler/crates/resolution-path/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,14 @@ impl<'a> ResolvePosition<'a> for FragmentSpread {
587587
.name
588588
.resolve(IdentParent::FragmentSpreadName(self.path(parent)), position);
589589
}
590+
ifletSome(arguments) =&self.arguments{
591+
for argumentin&arguments.items{
592+
if argument.contains(position){
593+
return argument
594+
.resolve(ArgumentParent::FragmentSpread(self.path(parent)), position);
595+
}
596+
}
597+
}
590598
for directiveinself.directives.iter(){
591599
if directive.contains(position){
592600
return directive
@@ -797,6 +805,7 @@ pub enum ArgumentParent<'a> {
797805
ScalarField(ScalarFieldPath<'a>),
798806
ConstantObject(ConstantObjectPath<'a>),
799807
Directive(DirectivePath<'a>),
808+
FragmentSpread(FragmentSpreadPath<'a>),
800809
}
801810

802811
impl<'a>ResolvePosition<'a>forArgument{

‎compiler/crates/resolution-path/src/test.rs

Lines changed: 107 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,27 @@ pub(super) fn test_resolution(source: &str, sub_str: &str, cb: impl Fn(&Resoluti
3838
}
3939

4040
#[test]
41-
fnoperation_definition_type_condition(){
41+
fnoperation_definition_operation(){
42+
let source =r#"
43+
query Foo {
44+
me {
45+
id
46+
}
47+
}
48+
"#;
49+
test_resolution(source,"query", |resolved|{
50+
assert_matches!(
51+
resolved,
52+
ResolutionPath::Operation(OperationPath{
53+
inner:(_,OperationKind::Query),
54+
parent: _,
55+
})
56+
);
57+
})
58+
}
59+
60+
#[test]
61+
fnoperation_definition_name(){
4262
let source =r#"
4363
query Foo {
4464
me {
@@ -58,25 +78,71 @@ fn operation_definition_type_condition() {
5878
}
5979

6080
#[test]
61-
fnoperation_definition_operation(){
81+
fnoperation_definition_variable_definition_name(){
6282
let source =r#"
63-
query Foo {
83+
query Foo($bar: ID!) {
6484
me {
6585
id
6686
}
6787
}
6888
"#;
69-
test_resolution(source,"query", |resolved|{
89+
test_resolution(source,"bar", |resolved|{
7090
assert_matches!(
7191
resolved,
72-
ResolutionPath::Operation(OperationPath{
73-
inner:(_,OperationKind::Query),
74-
parent: _,
92+
ResolutionPath::VariableIdentifier(VariableIdentifierPath{
93+
inner: _,
94+
parent:VariableIdentifierParent::VariableDefinition(VariableDefinitionPath{
95+
inner: _,
96+
parent:VariableDefinitionListPath{
97+
inner: _,
98+
parent:VariableDefinitionListParent::OperationDefinition(_),
99+
},
100+
}),
75101
})
76102
);
77103
})
78104
}
79105

106+
#[test]
107+
fnoperation_definition_variable_definition_type(){
108+
let source =r#"
109+
query Foo($bar: ID!) {
110+
me {
111+
id
112+
}
113+
}
114+
"#;
115+
test_resolution(source,"ID!", |resolved|{
116+
assert_matches!(
117+
resolved,
118+
ResolutionPath::Ident(IdentPath{
119+
inner: _,
120+
parent:IdentParent::NamedTypeAnnotation(NamedTypeAnnotationPath{
121+
inner: _,
122+
parent:TypeAnnotationPath{
123+
inner: _,
124+
parent:TypeAnnotationParent::NonNullTypeAnnotation(_),
125+
}
126+
}),
127+
})
128+
)
129+
})
130+
}
131+
132+
#[test]
133+
fnoperation_definition_variable_definition_default_value(){
134+
let source =r#"
135+
query Foo($localId: ID! = "1") {
136+
me {
137+
id
138+
}
139+
}
140+
"#;
141+
test_resolution(source,r#""1""#, |resolved|{
142+
assert_matches!(resolved,ResolutionPath::ConstantString(_));
143+
})
144+
}
145+
80146
#[test]
81147
fnlinked_field_name(){
82148
let source =r#"
@@ -248,6 +314,27 @@ fn fragment_spread_name() {
248314
})
249315
}
250316

317+
#[test]
318+
fnfragment_spread_argument_name(){
319+
let source =r#"
320+
fragment Foo on Node {
321+
...someFragment(someArg: 5)
322+
}
323+
"#;
324+
test_resolution(source,"someArg", |resolved|{
325+
assert_matches!(
326+
resolved,
327+
ResolutionPath::Ident(IdentPath{
328+
inner: _,
329+
parent:IdentParent::ArgumentName(ArgumentPath{
330+
inner: _,
331+
parent:ArgumentParent::FragmentSpread(_),
332+
}),
333+
})
334+
);
335+
})
336+
}
337+
251338
#[test]
252339
fndirective_name(){
253340
let source =r#"
@@ -321,7 +408,7 @@ fn list_literal() {
321408
}
322409

323410
#[test]
324-
fnfragment_argument_name(){
411+
fnfragment_argument_definition_name(){
325412
let source =r#"
326413
fragment Foo($localId: ID!) on User {
327414
id
@@ -345,7 +432,7 @@ fn fragment_argument_name() {
345432
}
346433

347434
#[test]
348-
fnfragment_argument_type(){
435+
fnfragment_argument_definition_type(){
349436
let source =r#"
350437
fragment Foo($localId: ID!) on User {
351438
id
@@ -369,7 +456,7 @@ fn fragment_argument_type() {
369456
}
370457

371458
#[test]
372-
fnfragment_argument_default_value(){
459+
fnfragment_argument_definition_default_value(){
373460
let source =r#"
374461
fragment Foo($localId: ID! = "1") on User {
375462
id
@@ -380,13 +467,19 @@ fn fragment_argument_default_value() {
380467
})
381468
}
382469
#[test]
383-
fnfragment_argument_directive(){
470+
fnfragment_argument_definition_directive(){
384471
let source =r#"
385-
fragment Foo($localId: ID! = "1") on User {
472+
fragment Foo($localId: ID! = "1" @bar) on User {
386473
id
387474
}
388475
"#;
389-
test_resolution(source,r#""1""#, |resolved|{
390-
assert_matches!(resolved,ResolutionPath::ConstantString(_));
476+
test_resolution(source,"bar", |resolved|{
477+
assert_matches!(
478+
resolved,
479+
ResolutionPath::Ident(IdentPath{
480+
inner: _,
481+
parent:IdentParent::DirectiveName(_)
482+
})
483+
);
391484
})
392485
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp