-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Modifying @relay_test_operation to write metadata for client fields #4047
Closed
stewartavery
wants to merge
2
commits into
facebook:main
from
stewartavery:stewartaavery/relay_test_operation_client_fields
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ query ProdQuery @relay_test_operation { | |
id | ||
} | ||
} | ||
# %extensions% |
37 changes: 37 additions & 0 deletions
37
...es/relay-transforms/tests/relay_test_operation/fixtures/test_client_fields_query.expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
==================================== INPUT ==================================== | ||
query ClientFieldsQuery @relay_test_operation { | ||
node(id: "test-id") { | ||
id | ||
... on User { | ||
name | ||
client_info { | ||
name | ||
description | ||
} | ||
} | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
extend type User { | ||
client_info: ClientInfo | ||
} | ||
|
||
type ClientInfo { | ||
name: String | ||
description: String | ||
} | ||
==================================== OUTPUT =================================== | ||
query ClientFieldsQuery @__metadata(relayTestingSelectionTypeInfo: {node: {enumValues: null, nullable: true, plural: false, type: "Node"}, node.id: {enumValues: null, nullable: false, plural: false, type: "ID"}, node.name: {enumValues: null, nullable: true, plural: false, type: "String"}, node.client_info: {enumValues: null, nullable: true, plural: false, type: "ClientInfo"}, node.client_info.name: {enumValues: null, nullable: true, plural: false, type: "String"}, node.client_info.description: {enumValues: null, nullable: true, plural: false, type: "String"}}) { | ||
node(id: "test-id") { | ||
id | ||
... on User { | ||
name | ||
client_info { | ||
name | ||
description | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...tes/relay-transforms/tests/relay_test_operation/fixtures/test_client_fields_query.graphql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
query ClientFieldsQuery @relay_test_operation { | ||
node(id: "test-id") { | ||
id | ||
... on User { | ||
name | ||
client_info { | ||
name | ||
description | ||
} | ||
} | ||
} | ||
} | ||
|
||
# %extensions% | ||
|
||
extend type User { | ||
client_info: ClientInfo | ||
} | ||
|
||
type ClientInfo { | ||
name: String | ||
description: String | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ query QueryWitEnums @relay_test_operation { | |
} | ||
} | ||
} | ||
# %extensions% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ query SimpleQuery @relay_test_operation { | |
} | ||
} | ||
} | ||
# %extensions% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,14 +5,55 @@ | |
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
use std::sync::Arc; | ||
|
||
use common::FeatureFlag; | ||
use common::SourceLocationKey; | ||
use fixture_tests::Fixture; | ||
use graphql_test_helpers::apply_transform_for_test; | ||
use graphql_ir::build; | ||
use graphql_ir::Program; | ||
use graphql_syntax::parse_executable; | ||
use graphql_test_helpers::diagnostics_to_sorted_string; | ||
use graphql_text_printer::print_fragment; | ||
use graphql_text_printer::print_operation; | ||
use graphql_text_printer::PrinterOptions; | ||
use regex::Regex; | ||
use relay_test_schema::get_test_schema_with_extensions; | ||
use relay_transforms::generate_test_operation_metadata; | ||
|
||
pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> { | ||
let test_path_regex = Some(Regex::new(r#"^test"#).unwrap()); | ||
apply_transform_for_test(fixture, |program| { | ||
generate_test_operation_metadata(program, &test_path_regex) | ||
}) | ||
let parts: Vec<_> = fixture.content.split("%extensions%").collect(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I referenced other |
||
|
||
if let [base, extensions] = parts.as_slice() { | ||
let source_location = SourceLocationKey::standalone(fixture.file_name); | ||
let ast = parse_executable(base, source_location).unwrap(); | ||
let schema = get_test_schema_with_extensions(extensions); | ||
|
||
let ir = build(&schema, &ast.definitions).unwrap(); | ||
let program = Program::from_definitions(Arc::clone(&schema), ir); | ||
|
||
let test_path_regex = Some(Regex::new(r#"^test"#).unwrap()); | ||
|
||
let next_program = generate_test_operation_metadata(&program, &test_path_regex) | ||
.map_err(|diagnostics| diagnostics_to_sorted_string(fixture.content, &diagnostics))?; | ||
|
||
let printer_options = PrinterOptions { | ||
debug_directive_data: true, | ||
..Default::default() | ||
}; | ||
|
||
let mut printed = next_program | ||
.operations() | ||
.map(|def| print_operation(&schema, def, printer_options.clone())) | ||
.chain( | ||
next_program | ||
.fragments() | ||
.map(|def| print_fragment(&schema, def, printer_options.clone())), | ||
) | ||
.collect::<Vec<_>>(); | ||
printed.sort(); | ||
Ok(printed.join("\n\n")) | ||
} else { | ||
panic!("Expected exactly one %extensions% section marker.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the new behavior with the feature flag enabled. This extra metadata will allow
MockPayloadGenerator
to auto-mock client fields when they're not provided in the associated resolver