Skip to content

Commit 125fab8

Browse files
committed
support comments in args
1 parent 0281b74 commit 125fab8

File tree

4 files changed

+51
-4
lines changed

4 files changed

+51
-4
lines changed

graphqxl_synthesizer/src/synth_arguments.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
use crate::synth_description::DescriptionSynth;
12
use crate::synth_directive::DirectiveSynth;
23
use crate::synth_identifier::IdentifierSynth;
34
use crate::synth_value_data::ValueDataSynth;
45
use crate::synth_value_type::ValueTypeSynth;
56
use crate::synths::{
6-
ChainSynth, MultilineListSynth, OneLineListSynth, StringSynth, Synth, SynthContext,
7+
ChainSynth, MultilineListSynth, OneLineListSynth, PairSynth, StringSynth, Synth, SynthContext,
78
};
89
use graphqxl_parser::{Argument, ArgumentDefaultValue};
910

1011
pub(crate) struct ArgumentsSynth(pub(crate) Vec<Argument>);
1112

1213
impl Synth for ArgumentsSynth {
1314
fn synth(&self, context: &mut SynthContext) -> bool {
14-
let inner_synths = self
15+
let mut at_least_one_description = false;
16+
let inner_synths: Vec<Box<dyn Synth>> = self
1517
.0
1618
.iter()
1719
.map(|argument| {
@@ -31,11 +33,21 @@ impl Synth for ArgumentsSynth {
3133
v.push(Box::new(StringSynth::from(" ")));
3234
v.push(Box::new(DirectiveSynth(directive.clone())));
3335
}
34-
ChainSynth(v)
36+
37+
if !argument.description.is_empty() {
38+
at_least_one_description = true;
39+
Box::new(PairSynth {
40+
first: DescriptionSynth::text(&argument.description),
41+
last: ChainSynth(v),
42+
line_jump_sep: true,
43+
})
44+
} else {
45+
Box::new(ChainSynth(v)) as Box<dyn Synth>
46+
}
3547
})
3648
.collect();
3749

38-
if self.0.len() > context.config.max_one_line_args {
50+
if self.0.len() > context.config.max_one_line_args || at_least_one_description {
3951
MultilineListSynth::no_suffix(("(", inner_synths, ")")).synth(context);
4052
} else {
4153
OneLineListSynth::comma(("(", inner_synths, ")")).synth(context);

graphqxl_synthesizer/src/synths/synth_context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ pub(crate) trait Synth {
9494
}
9595
}
9696

97+
impl Synth for Box<dyn Synth> {
98+
fn synth(&self, context: &mut SynthContext) -> bool {
99+
self.as_ref().synth(context)
100+
}
101+
}
102+
97103
#[cfg(test)]
98104
mod tests {
99105
use super::*;

src/test/comments-in-args.graphqxl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
type Query {
2+
"Comment on foo"
3+
foo(
4+
"Comment on bar"
5+
bar: String
6+
baz: Int
7+
"""
8+
multiline comment
9+
10+
bar_baz
11+
"""
12+
bar_baz: Boolean
13+
): [String!]!
14+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
type Query {
2+
"Comment on foo"
3+
foo(
4+
"Comment on bar"
5+
bar: String
6+
baz: Int
7+
"""
8+
multiline comment
9+
10+
bar_baz
11+
"""
12+
bar_baz: Boolean
13+
): [String!]!
14+
}
15+

0 commit comments

Comments
 (0)