forked from facebook/relay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.rs
42 lines (39 loc) · 1.39 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
use common::FileKey;
use fixture_tests::Fixture;
use graphql_ir::{build, ExecutableDefinition, Program};
use graphql_syntax::parse;
use graphql_text_printer::print_full_operation;
use test_schema::TEST_SCHEMA;
pub fn transform_fixture(fixture: &Fixture) -> Result<String, String> {
let file_key = FileKey::new(fixture.file_name);
let ast = parse(fixture.content, file_key).unwrap();
let ir = build(&TEST_SCHEMA, &ast.definitions).unwrap();
let program = Program::from_definitions(&TEST_SCHEMA, ir);
build(&TEST_SCHEMA, &ast.definitions)
.map(|definitions| {
definitions
.into_iter()
.filter_map(|definition| {
if let ExecutableDefinition::Operation(operation) = definition {
Some(print_full_operation(&program, &operation))
} else {
None
}
})
.collect::<Vec<String>>()
.join("\n\n\n\n")
})
.map_err(|errors| {
errors
.into_iter()
.map(|error| format!("{:?}", error))
.collect::<Vec<_>>()
.join("\n\n")
})
}