Skip to content

Commit 3aee982

Browse files
gabotechsgabotechs
authored andcommitted
fix: do not transpile non-generic private objects
1 parent 9864dc7 commit 3aee982

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

graphqxl_transpiler/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ mod transpile_generic_block_def;
88
mod transpile_spec;
99
mod utils;
1010

11-
pub use transpile_spec::transpile_spec;
11+
pub use transpile_spec::{transpile_spec, TranspileSpecOptions};

graphqxl_transpiler/src/transpile_spec.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ use graphqxl_parser::{DefType, Spec};
55
use std::collections::HashMap;
66
use std::error::Error;
77

8-
pub fn transpile_spec(spec: &Spec) -> Result<Spec, Box<dyn Error>> {
8+
#[derive(Clone, Default, Debug, PartialEq, Eq)]
9+
pub struct TranspileSpecOptions {
10+
pub private_prefix: String,
11+
}
12+
13+
pub fn transpile_spec(spec: &Spec, options: &TranspileSpecOptions) -> Result<Spec, Box<dyn Error>> {
914
let mut target = Spec::default();
1015
let mut transpiled_store = HashMap::new();
1116

@@ -26,6 +31,9 @@ pub fn transpile_spec(spec: &Spec) -> Result<Spec, Box<dyn Error>> {
2631

2732
match def {
2833
DefType::Type(name) => {
34+
if name.id.starts_with(&options.private_prefix) {
35+
continue;
36+
}
2937
let transpiled = transpile_block_def_by_id(name, &types_block_def_store)?;
3038
if transpiled.generic.is_none() {
3139
target.types.insert(name.id.clone(), transpiled);
@@ -45,6 +53,9 @@ pub fn transpile_spec(spec: &Spec) -> Result<Spec, Box<dyn Error>> {
4553
target.order.push(DefType::Type(name.clone()));
4654
}
4755
DefType::Input(name) => {
56+
if name.id.starts_with(&options.private_prefix) {
57+
continue;
58+
}
4859
let transpiled = transpile_block_def_by_id(name, &inputs_block_def_store)?;
4960
if transpiled.generic.is_none() {
5061
target.inputs.insert(name.id.clone(), transpiled);

src/main.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use apollo_compiler::ApolloCompiler;
88
use clap::Parser;
99
use graphqxl_parser::parse_spec;
1010
use graphqxl_synthesizer::{synth_spec, SynthConfig};
11-
use graphqxl_transpiler::transpile_spec;
11+
use graphqxl_transpiler::{transpile_spec, TranspileSpecOptions};
1212
use std::fs;
1313

1414
#[derive(Parser, Debug)]
@@ -47,7 +47,12 @@ fn graphqxl_to_graphql(args: &Args) -> Result<(String, String)> {
4747
let spec_result = parse_spec(&args.input);
4848
let spec = ok_or_anyhow_err(spec_result, "Could not parse GraphQXL spec")?;
4949

50-
let transpile_result = transpile_spec(&spec);
50+
let transpile_result = transpile_spec(
51+
&spec,
52+
&TranspileSpecOptions {
53+
private_prefix: args.private_prefix.clone(),
54+
},
55+
);
5156
let transpiled = ok_or_anyhow_err(transpile_result, "Could not transpile graphqxl spec")?;
5257

5358
let (result, source_map) = synth_spec(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type _Type {
2+
"${{ custom.foo }}"
3+
foo: Int
4+
}
5+
6+
${foo: "custom"}
7+
type Type = _Type
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type Type {
2+
"custom"
3+
foo: Int
4+
}
5+
6+

0 commit comments

Comments
 (0)