Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support comments in args #59

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 16 additions & 4 deletions graphqxl_synthesizer/src/synth_arguments.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::synth_description::DescriptionSynth;
use crate::synth_directive::DirectiveSynth;
use crate::synth_identifier::IdentifierSynth;
use crate::synth_value_data::ValueDataSynth;
use crate::synth_value_type::ValueTypeSynth;
use crate::synths::{
ChainSynth, MultilineListSynth, OneLineListSynth, StringSynth, Synth, SynthContext,
ChainSynth, MultilineListSynth, OneLineListSynth, PairSynth, StringSynth, Synth, SynthContext,
};
use graphqxl_parser::{Argument, ArgumentDefaultValue};

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

impl Synth for ArgumentsSynth {
fn synth(&self, context: &mut SynthContext) -> bool {
let inner_synths = self
let mut at_least_one_description = false;
let inner_synths: Vec<Box<dyn Synth>> = self
.0
.iter()
.map(|argument| {
Expand All @@ -31,11 +33,21 @@ impl Synth for ArgumentsSynth {
v.push(Box::new(StringSynth::from(" ")));
v.push(Box::new(DirectiveSynth(directive.clone())));
}
ChainSynth(v)

if !argument.description.is_empty() {
at_least_one_description = true;
Box::new(PairSynth {
first: DescriptionSynth::text(&argument.description),
last: ChainSynth(v),
line_jump_sep: true,
})
} else {
Box::new(ChainSynth(v)) as Box<dyn Synth>
}
})
.collect();

if self.0.len() > context.config.max_one_line_args {
if self.0.len() > context.config.max_one_line_args || at_least_one_description {
MultilineListSynth::no_suffix(("(", inner_synths, ")")).synth(context);
} else {
OneLineListSynth::comma(("(", inner_synths, ")")).synth(context);
Expand Down
6 changes: 6 additions & 0 deletions graphqxl_synthesizer/src/synths/synth_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ pub(crate) trait Synth {
}
}

impl Synth for Box<dyn Synth> {
fn synth(&self, context: &mut SynthContext) -> bool {
self.as_ref().synth(context)
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
14 changes: 14 additions & 0 deletions src/test/comments-in-args.graphqxl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type Query {
"Comment on foo"
foo(
"Comment on bar"
bar: String
baz: Int
"""
multiline comment

bar_baz
"""
bar_baz: Boolean
): [String!]!
}
15 changes: 15 additions & 0 deletions src/test/comments-in-args.graphqxl.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type Query {
"Comment on foo"
foo(
"Comment on bar"
bar: String
baz: Int
"""
multiline comment

bar_baz
"""
bar_baz: Boolean
): [String!]!
}

Loading