Skip to content

Commit 86fc7d7

Browse files
committed
config: allow 'extra' in root of single-project config files
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
1 parent 27c0a38 commit 86fc7d7

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-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
@@ -1584,6 +1584,10 @@
15841584
"type": "string"
15851585
}
15861586
},
1587+
"extra": {
1588+
"description": "A placeholder for allowing extra information in the config file",
1589+
"default": null
1590+
},
15871591
"featureFlags": {
15881592
"description": "Enable and disable experimental or legacy behaviors. WARNING! These are not stable and may change at any time.",
15891593
"default": null,

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

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

954958
impl Default for SingleProjectConfigFile {
@@ -972,6 +976,7 @@ impl Default for SingleProjectConfigFile {
972976
module_import_config: Default::default(),
973977
resolvers_schema_module: Default::default(),
974978
no_source_control: Some(false),
979+
extra: Default::default(),
975980
}
976981
}
977982
}
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)