Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1cf472

Browse files
gordyffacebook-github-bot
authored andcommitted
Emit semanticNonNull in generated schema
Reviewed By: captbaritoneDifferential Revision: D55775523fbshipit-source-id: 6ef31680a4aa5099c8486e6ae70699fdbbf104c4
1 parentddfa2b0 commitd1cf472

File tree

6 files changed

+140
-3
lines changed

6 files changed

+140
-3
lines changed

‎compiler/crates/relay-docblock/src/ir.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ lazy_static! {
8787
DirectiveName("deprecated".intern());
8888
static refDEPRECATED_REASON_ARGUMENT_NAME:ArgumentName =ArgumentName("reason".intern());
8989
static refMODEL_CUSTOM_SCALAR_TYPE_SUFFIX:StringKey ="Model".intern();
90+
static refSEMANTIC_NON_NULL_DIRECTIVE_NAME:DirectiveName =
91+
DirectiveName("semanticNonNull".intern());
9092
}
9193

9294
#[derive(Debug,Clone,PartialEq)]
@@ -431,14 +433,13 @@ trait ResolverIr: Sized {
431433
object:Option<&Object>,
432434
project_config:ResolverProjectConfig<'_,'_>,
433435
) ->Vec<ConstantDirective>{
434-
let location =self.location();
435-
let span = location.span();
436436
letmut directives:Vec<ConstantDirective> =vec![
437437
self.directive(object, project_config),
438438
resolver_source_hash_directive(self.source_hash()),
439439
];
440440

441441
ifletSome(deprecated) =self.deprecated(){
442+
let span = deprecated.key_location().span();
442443
directives.push(ConstantDirective{
443444
span,
444445
at:dummy_token(span),
@@ -452,6 +453,16 @@ trait ResolverIr: Sized {
452453
})
453454
}
454455

456+
ifletSome(semantic_non_null) =self.semantic_non_null(){
457+
let span = semantic_non_null.key_location.span();
458+
directives.push(ConstantDirective{
459+
span,
460+
at:dummy_token(span),
461+
name:string_key_as_identifier(SEMANTIC_NON_NULL_DIRECTIVE_NAME.0),
462+
arguments:None,
463+
})
464+
}
465+
455466
directives
456467
}
457468

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
==================================== INPUT ====================================
2+
/**
3+
* Copyright (c) Meta Platforms, Inc. and affiliates.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
// relay:allow_legacy_verbose_syntax
10+
11+
/**
12+
* @RelayResolver
13+
*
14+
* @onType User
15+
* @fieldName favorite_page
16+
* @rootFragment myRootFragment
17+
* @semanticNonNull
18+
*
19+
* The user's favorite page! They probably clicked something in the UI
20+
* to tell us that it was their favorite page and then we put that in a
21+
* database or something. Then we got that info out again and put it out
22+
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
23+
*/
24+
25+
graphql`
26+
fragment myRootFragment on User {
27+
id
28+
}
29+
`
30+
==================================== OUTPUT ===================================
31+
extend type User {
32+
favorite_page: RelayResolverValue @relay_resolver(import_path: "/path/to/test/fixture/relay-resolver-semantic-non-null.js", fragment_name: "myRootFragment", import_name: "favorite_page") @resolver_source_hash(value: "5f25cc9a9a8677d930bf1e8b447a769d") @semanticNonNull
33+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// relay:allow_legacy_verbose_syntax
9+
10+
/**
11+
*@RelayResolver
12+
*
13+
*@onType User
14+
*@fieldName favorite_page
15+
*@rootFragment myRootFragment
16+
*@semanticNonNull
17+
*
18+
* The user's favorite page! They probably clicked something in the UI
19+
* to tell us that it was their favorite page and then we put that in a
20+
* database or something. Then we got that info out again and put it out
21+
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
22+
*/
23+
24+
graphql`
25+
fragment myRootFragment on User {
26+
id
27+
}
28+
`
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
==================================== INPUT ====================================
2+
/**
3+
* Copyright (c) Meta Platforms, Inc. and affiliates.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* @RelayResolver User.favorite_page: Page
11+
* @rootFragment myRootFragment
12+
* @semanticNonNull
13+
*
14+
* The user's favorite page! They probably clicked something in the UI
15+
* to tell us that it was their favorite page and then we put that in a
16+
* database or something. Then we got that info out again and put it out
17+
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
18+
*/
19+
20+
graphql`
21+
fragment myRootFragment on User {
22+
id
23+
}
24+
`
25+
==================================== OUTPUT ===================================
26+
extend type User {
27+
favorite_page: Page @relay_resolver(import_path: "/path/to/test/fixture/terse-relay-resolver-semantic-non-null.js", fragment_name: "myRootFragment", import_name: "favorite_page") @resolver_source_hash(value: "27524a0a58f36e5480cea6a72c2c0a88") @semanticNonNull
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
/**
9+
*@RelayResolver User.favorite_page: Page
10+
*@rootFragment myRootFragment
11+
*@semanticNonNull
12+
*
13+
* The user's favorite page! They probably clicked something in the UI
14+
* to tell us that it was their favorite page and then we put that in a
15+
* database or something. Then we got that info out again and put it out
16+
* again. Anyway, I'm rambling now. Its a page that the user likes. A lot.
17+
*/
18+
19+
graphql`
20+
fragment myRootFragment on User {
21+
id
22+
}
23+
`

‎compiler/crates/relay-docblock/tests/to_schema_test.rs

Lines changed: 15 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<<1ffacfeab59157dc3df605ce3d320d2c>>
7+
* @generated SignedSource<<352f018a582767211d069064d155a271>>
88
*/
99

1010
mod to_schema;
@@ -131,6 +131,13 @@ async fn relay_resolver_on_type_with_interface_invalid() {
131131
test_fixture(transform_fixture,file!(),"relay-resolver-on-type-with-interface.invalid.js","to_schema/fixtures/relay-resolver-on-type-with-interface.invalid.expected", input, expected).await;
132132
}
133133

134+
#[tokio::test]
135+
asyncfnrelay_resolver_semantic_non_null(){
136+
let input =include_str!("to_schema/fixtures/relay-resolver-semantic-non-null.js");
137+
let expected =include_str!("to_schema/fixtures/relay-resolver-semantic-non-null.expected");
138+
test_fixture(transform_fixture,file!(),"relay-resolver-semantic-non-null.js","to_schema/fixtures/relay-resolver-semantic-non-null.expected", input, expected).await;
139+
}
140+
134141
#[tokio::test]
135142
asyncfnrelay_resolver_strong_object(){
136143
let input =include_str!("to_schema/fixtures/relay-resolver-strong-object.js");
@@ -243,6 +250,13 @@ async fn terse_relay_resolver_non_existent_type_invalid() {
243250
test_fixture(transform_fixture,file!(),"terse-relay-resolver-non-existent-type.invalid.js","to_schema/fixtures/terse-relay-resolver-non-existent-type.invalid.expected", input, expected).await;
244251
}
245252

253+
#[tokio::test]
254+
asyncfnterse_relay_resolver_semantic_non_null(){
255+
let input =include_str!("to_schema/fixtures/terse-relay-resolver-semantic-non-null.js");
256+
let expected =include_str!("to_schema/fixtures/terse-relay-resolver-semantic-non-null.expected");
257+
test_fixture(transform_fixture,file!(),"terse-relay-resolver-semantic-non-null.js","to_schema/fixtures/terse-relay-resolver-semantic-non-null.expected", input, expected).await;
258+
}
259+
246260
#[tokio::test]
247261
asyncfnterse_relay_resolver_with_output_type(){
248262
let input =include_str!("to_schema/fixtures/terse-relay-resolver-with-output-type.js");

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp