Skip to content

Commit 292ae5a

Browse files
sjbaragfacebook-github-bot
authored andcommitted
config: allow 'extra' in root of single-project config files (#5030)
Summary: The 'extra' property was previously only declared for the projects in a multi-project config file. Since unknown fields are considered an error when parsing single-project config files, this made it impossible to include arbitrary metadata via a package.json config or a relay.config.json file. Allow 'extra' at the root of a single-project config file to better-match the structure of projects in a multi-project config. fixes #5029 Pull Request resolved: #5030 Reviewed By: tyao1 Differential Revision: D77896280 Pulled By: captbaritone fbshipit-source-id: f4f3cc2904c674705adb8f73e672e8e4ffb2c372
1 parent e2aaaa8 commit 292ae5a

File tree

5 files changed

+101
-1
lines changed

5 files changed

+101
-1
lines changed

compiler/crates/relay-compiler/relay-compiler-config-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,10 @@
13851385
"type": "string"
13861386
}
13871387
},
1388+
"extra": {
1389+
"description": "A placeholder for allowing extra information in the config file",
1390+
"default": null
1391+
},
13881392
"featureFlags": {
13891393
"description": "Enable and disable experimental or legacy behaviors.\nWARNING! These are not stable and may change at any time.",
13901394
"anyOf": [

compiler/crates/relay-compiler/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,10 @@ pub struct SingleProjectConfigFile {
950950
/// Opt out of source control checks/integration.
951951
#[serde(default)]
952952
pub no_source_control: Option<bool>,
953+
954+
/// A placeholder for allowing extra information in the config file
955+
#[serde(default)]
956+
pub extra: serde_json::Value,
953957
}
954958

955959
impl Default for SingleProjectConfigFile {
@@ -973,6 +977,7 @@ impl Default for SingleProjectConfigFile {
973977
module_import_config: Default::default(),
974978
resolvers_schema_module: Default::default(),
975979
no_source_control: Some(false),
980+
extra: Default::default(),
976981
}
977982
}
978983
}
@@ -1055,6 +1060,7 @@ impl SingleProjectConfigFile {
10551060
feature_flags: self.feature_flags,
10561061
module_import_config: self.module_import_config,
10571062
resolvers_schema_module: self.resolvers_schema_module,
1063+
extra: self.extra,
10581064
..Default::default()
10591065
};
10601066

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
==================================== INPUT ====================================
2+
//- foo.js
3+
graphql`
4+
fragment foo on User {
5+
name
6+
}`;
7+
8+
//- relay.config.json
9+
{
10+
"language": "typescript",
11+
"schema": "./schema.graphql",
12+
"extra": {
13+
"is_metadata": true,
14+
"tags": ["free-form", "unstructured"]
15+
}
16+
}
17+
18+
//- schema.graphql
19+
type Query { me: User }
20+
type User { name: String }
21+
==================================== OUTPUT ===================================
22+
//- __generated__/foo.graphql.ts
23+
/**
24+
* <auto-generated> SignedSource<<d2b6a2fbf057fd52d8aa0869bcccbe8e>>
25+
* @lightSyntaxTransform
26+
* @nogrep
27+
*/
28+
29+
/* tslint:disable */
30+
/* eslint-disable */
31+
// @ts-nocheck
32+
33+
import { ReaderFragment } from 'relay-runtime';
34+
import { FragmentRefs } from "relay-runtime";
35+
export type foo$data = {
36+
readonly name: string | null | undefined;
37+
readonly " $fragmentType": "foo";
38+
};
39+
export type foo$key = {
40+
readonly " $data"?: foo$data;
41+
readonly " $fragmentSpreads": FragmentRefs<"foo">;
42+
};
43+
44+
const node: ReaderFragment = {
45+
"argumentDefinitions": [],
46+
"kind": "Fragment",
47+
"metadata": null,
48+
"name": "foo",
49+
"selections": [
50+
{
51+
"alias": null,
52+
"args": null,
53+
"kind": "ScalarField",
54+
"name": "name",
55+
"storageKey": null
56+
}
57+
],
58+
"type": "User",
59+
"abstractKey": null
60+
};
61+
62+
(node as any).hash = "01d5e51e4b7ff55557834f125c21745d";
63+
64+
export default node;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//- foo.js
2+
graphql`
3+
fragment foo on User {
4+
name
5+
}`;
6+
7+
//- relay.config.json
8+
{
9+
"language": "typescript",
10+
"schema": "./schema.graphql",
11+
"extra": {
12+
"is_metadata": true,
13+
"tags": ["free-form", "unstructured"]
14+
}
15+
}
16+
17+
//- schema.graphql
18+
type Query { me: User }
19+
type User { name: String }

compiler/crates/relay-compiler/tests/relay_compiler_integration_test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c8632d2cc8a8adc3915d1de9ce475bba>>
7+
* @generated SignedSource<<a2971e0e5624155ca2839e4911ee608b>>
88
*/
99

1010
mod relay_compiler_integration;
@@ -96,6 +96,13 @@ async fn exec_resolvers_directive_with_root_fragment() {
9696
test_fixture(transform_fixture, file!(), "exec_resolvers_directive_with_root_fragment.input", "relay_compiler_integration/fixtures/exec_resolvers_directive_with_root_fragment.expected", input, expected).await;
9797
}
9898

99+
#[tokio::test]
100+
async fn extra_in_single_file_config() {
101+
let input = include_str!("relay_compiler_integration/fixtures/extra_in_single_file_config.input");
102+
let expected = include_str!("relay_compiler_integration/fixtures/extra_in_single_file_config.expected");
103+
test_fixture(transform_fixture, file!(), "extra_in_single_file_config.input", "relay_compiler_integration/fixtures/extra_in_single_file_config.expected", input, expected).await;
104+
}
105+
99106
#[tokio::test]
100107
async fn fragment_alias_nested_in_inline_fragment() {
101108
let input = include_str!("relay_compiler_integration/fixtures/fragment_alias_nested_in_inline_fragment.input");

0 commit comments

Comments
 (0)