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

Commit8cce449

Browse files
tyao1facebook-github-bot
authored andcommitted
A RelayResolverValue generic
Reviewed By: evanyeungDifferential Revision: D58156313fbshipit-source-id: 776c27e1f120e808320cbe0f789f2f808900d816
1 parent722b18f commit8cce449

File tree

6 files changed

+298
-3
lines changed

6 files changed

+298
-3
lines changed

‎compiler/crates/relay-schema-generation/src/lib.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ fn return_type_to_type_annotation(
826826
source_location:SourceLocationKey,
827827
return_type:&FlowTypeAnnotation,
828828
) ->DiagnosticsResult<TypeAnnotation>{
829-
let(return_type, is_optional) = schema_extractor::unwrap_nullable_type(return_type);
829+
let(return_type,mutis_optional) = schema_extractor::unwrap_nullable_type(return_type);
830830
let location =to_location(source_location, return_type);
831831
let type_annotation =match return_type{
832832
FlowTypeAnnotation::GenericTypeAnnotation(node) =>{
@@ -871,6 +871,20 @@ fn return_type_to_type_annotation(
871871
)]);
872872
}
873873
}
874+
"RelayResolverValue" =>{
875+
// Special case for `RelayResolverValue`, it is always optional
876+
is_optional =true;
877+
TypeAnnotation::Named(NamedTypeAnnotation{
878+
name:Identifier{
879+
span: location.span(),
880+
token:Token{
881+
span: location.span(),
882+
kind:TokenKind::Identifier,
883+
},
884+
value:intern!("RelayResolverValue"),
885+
},
886+
})
887+
}
874888
_ =>{
875889
returnErr(vec![Diagnostic::error(
876890
SchemaGenerationError::UnSupportedGeneric{
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
==================================== INPUT ====================================
2+
//- module.js
3+
4+
/**
5+
* Copyright (c) Meta Platforms, Inc. and affiliates.
6+
*
7+
* This source code is licensed under the MIT license found in the
8+
* LICENSE file in the root directory of this source tree.
9+
*/
10+
11+
import type CatFlowType from 'Cat';
12+
13+
import type { RelayResolverValue } from 'relay-runtime';
14+
15+
/**
16+
* @RelayResolver
17+
*/
18+
export function Cat(id: DataID): CatFlowType {
19+
return {};
20+
}
21+
22+
/**
23+
* @RelayResolver
24+
*/
25+
export function complexValue(cat: CatFlowType): RelayResolverValue<{a: 1, b: 2}> {
26+
return {a: 1, b: 2};
27+
}
28+
29+
/**
30+
* @RelayResolver
31+
*/
32+
export function optionalRelayResolverValue(cat: CatFlowType): ?RelayResolverValue<{a: 1, b: 2}> {
33+
return null;
34+
}
35+
36+
/**
37+
* @RelayResolver
38+
*/
39+
export function relayResolveValueOverridesAllOtherAnnotation(cat: CatFlowType): ?RelayResolverValue<IdOf<"Cat">> {
40+
return {id: '1'};
41+
}
42+
==================================== OUTPUT ===================================
43+
Field(
44+
TerseRelayResolver(
45+
TerseRelayResolverIr {
46+
field: FieldDefinition {
47+
name: Identifier {
48+
span: 419:431,
49+
token: Token {
50+
span: 419:431,
51+
kind: Identifier,
52+
},
53+
value: "complexValue",
54+
},
55+
type_: Named(
56+
NamedTypeAnnotation {
57+
name: Identifier {
58+
span: 451:483,
59+
token: Token {
60+
span: 451:483,
61+
kind: Identifier,
62+
},
63+
value: "RelayResolverValue",
64+
},
65+
},
66+
),
67+
arguments: None,
68+
directives: [],
69+
description: None,
70+
hack_source: None,
71+
span: 419:431,
72+
},
73+
type_: WithLocation {
74+
location: <generated>:330:333,
75+
item: "Cat",
76+
},
77+
root_fragment: None,
78+
deprecated: None,
79+
semantic_non_null: None,
80+
live: None,
81+
location: module.js:419:431,
82+
fragment_arguments: None,
83+
source_hash: ResolverSourceHash(
84+
"fc15c065174264428a3632fe9cf329d6",
85+
),
86+
},
87+
),
88+
)
89+
extend type Cat {
90+
complexValue: RelayResolverValue @relay_resolver(fragment_name: "Cat____relay_model_instance", generated_fragment: true, inject_fragment_data: "__relay_model_instance", has_output_type: true, import_name: "complexValue", import_path: "module.js") @resolver_source_hash(value: "fc15c065174264428a3632fe9cf329d6")
91+
}
92+
93+
94+
Field(
95+
TerseRelayResolver(
96+
TerseRelayResolverIr {
97+
field: FieldDefinition {
98+
name: Identifier {
99+
span: 554:580,
100+
token: Token {
101+
span: 554:580,
102+
kind: Identifier,
103+
},
104+
value: "optionalRelayResolverValue",
105+
},
106+
type_: Named(
107+
NamedTypeAnnotation {
108+
name: Identifier {
109+
span: 601:633,
110+
token: Token {
111+
span: 601:633,
112+
kind: Identifier,
113+
},
114+
value: "RelayResolverValue",
115+
},
116+
},
117+
),
118+
arguments: None,
119+
directives: [],
120+
description: None,
121+
hack_source: None,
122+
span: 554:580,
123+
},
124+
type_: WithLocation {
125+
location: <generated>:330:333,
126+
item: "Cat",
127+
},
128+
root_fragment: None,
129+
deprecated: None,
130+
semantic_non_null: None,
131+
live: None,
132+
location: module.js:554:580,
133+
fragment_arguments: None,
134+
source_hash: ResolverSourceHash(
135+
"fc15c065174264428a3632fe9cf329d6",
136+
),
137+
},
138+
),
139+
)
140+
extend type Cat {
141+
optionalRelayResolverValue: RelayResolverValue @relay_resolver(fragment_name: "Cat____relay_model_instance", generated_fragment: true, inject_fragment_data: "__relay_model_instance", has_output_type: true, import_name: "optionalRelayResolverValue", import_path: "module.js") @resolver_source_hash(value: "fc15c065174264428a3632fe9cf329d6")
142+
}
143+
144+
145+
Field(
146+
TerseRelayResolver(
147+
TerseRelayResolverIr {
148+
field: FieldDefinition {
149+
name: Identifier {
150+
span: 696:740,
151+
token: Token {
152+
span: 696:740,
153+
kind: Identifier,
154+
},
155+
value: "relayResolveValueOverridesAllOtherAnnotation",
156+
},
157+
type_: Named(
158+
NamedTypeAnnotation {
159+
name: Identifier {
160+
span: 761:792,
161+
token: Token {
162+
span: 761:792,
163+
kind: Identifier,
164+
},
165+
value: "RelayResolverValue",
166+
},
167+
},
168+
),
169+
arguments: None,
170+
directives: [],
171+
description: None,
172+
hack_source: None,
173+
span: 696:740,
174+
},
175+
type_: WithLocation {
176+
location: <generated>:330:333,
177+
item: "Cat",
178+
},
179+
root_fragment: None,
180+
deprecated: None,
181+
semantic_non_null: None,
182+
live: None,
183+
location: module.js:696:740,
184+
fragment_arguments: None,
185+
source_hash: ResolverSourceHash(
186+
"fc15c065174264428a3632fe9cf329d6",
187+
),
188+
},
189+
),
190+
)
191+
extend type Cat {
192+
relayResolveValueOverridesAllOtherAnnotation: RelayResolverValue @relay_resolver(fragment_name: "Cat____relay_model_instance", generated_fragment: true, inject_fragment_data: "__relay_model_instance", has_output_type: true, import_name: "relayResolveValueOverridesAllOtherAnnotation", import_path: "module.js") @resolver_source_hash(value: "fc15c065174264428a3632fe9cf329d6")
193+
}
194+
195+
196+
Type(
197+
StrongObjectResolver(
198+
StrongObjectIr {
199+
type_name: Identifier {
200+
span: 330:333,
201+
token: Token {
202+
span: 330:333,
203+
kind: Identifier,
204+
},
205+
value: "Cat",
206+
},
207+
rhs_location: module.js:330:333,
208+
root_fragment: WithLocation {
209+
location: module.js:330:333,
210+
item: FragmentDefinitionName(
211+
"Cat__id",
212+
),
213+
},
214+
description: None,
215+
deprecated: None,
216+
live: None,
217+
semantic_non_null: None,
218+
location: module.js:330:333,
219+
implements_interfaces: [],
220+
source_hash: ResolverSourceHash(
221+
"fc15c065174264428a3632fe9cf329d6",
222+
),
223+
},
224+
),
225+
)
226+
type Cat @__RelayResolverModel {
227+
id: ID!
228+
__relay_model_instance: RelayResolverValue! @relay_resolver(generated_fragment: true, fragment_name: "Cat__id", import_name: "Cat", import_path: "module.js", inject_fragment_data: "id") @resolver_source_hash(value: "fc15c065174264428a3632fe9cf329d6") @unselectable(reason: "This field is intended only for Relay's internal use")
229+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//- module.js
2+
3+
/**
4+
* Copyright (c) Meta Platforms, Inc. and affiliates.
5+
*
6+
* This source code is licensed under the MIT license found in the
7+
* LICENSE file in the root directory of this source tree.
8+
*/
9+
10+
import type CatFlowType from 'Cat';
11+
12+
import type { RelayResolverValue } from 'relay-runtime';
13+
14+
/**
15+
* @RelayResolver
16+
*/
17+
export function Cat(id: DataID): CatFlowType {
18+
return {};
19+
}
20+
21+
/**
22+
* @RelayResolver
23+
*/
24+
export function complexValue(cat: CatFlowType): RelayResolverValue<{a: 1, b: 2}> {
25+
return {a: 1, b: 2};
26+
}
27+
28+
/**
29+
* @RelayResolver
30+
*/
31+
export function optionalRelayResolverValue(cat: CatFlowType): ?RelayResolverValue<{a: 1, b: 2}> {
32+
return null;
33+
}
34+
35+
/**
36+
* @RelayResolver
37+
*/
38+
export function relayResolveValueOverridesAllOtherAnnotation(cat: CatFlowType): ?RelayResolverValue<IdOf<"Cat">> {
39+
return {id: '1'};
40+
}

‎compiler/crates/relay-schema-generation/tests/docblock_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<<8ea8d4359f6e14415e193be12974b772>>
7+
* @generated SignedSource<<4de8fcba1c45e8cec09648c0767a6efe>>
88
*/
99

1010
mod docblock;
@@ -103,6 +103,13 @@ async fn return_optional_weak_object() {
103103
test_fixture(transform_fixture,file!(),"return-optional-weak-object.input","docblock/fixtures/return-optional-weak-object.expected", input, expected).await;
104104
}
105105

106+
#[tokio::test]
107+
asyncfnreturn_relay_resolver_value(){
108+
let input =include_str!("docblock/fixtures/return-relay-resolver-value.input");
109+
let expected =include_str!("docblock/fixtures/return-relay-resolver-value.expected");
110+
test_fixture(transform_fixture,file!(),"return-relay-resolver-value.input","docblock/fixtures/return-relay-resolver-value.expected", input, expected).await;
111+
}
112+
106113
#[tokio::test]
107114
asyncfnroot_fragment(){
108115
let input =include_str!("docblock/fixtures/root-fragment.input");

‎packages/relay-runtime/experimental.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,14 @@ import type {DataID} from './util/RelayRuntimeTypes';
1515

1616
constresolverDataInjector=require('./store/experimental-live-resolvers/resolverDataInjector');
1717

18+
// Annotates a strong object return type, where `A` is the GraphQL typename
1819
// eslint-disable-next-line no-unused-vars
1920
exporttypeIdOf<A>=DataID;
2021

22+
// Annotates a `RelayResolverValue` GraphQL return type
23+
// eslint-disable-next-line no-unused-vars
24+
exporttypeRelayResolverValue<A>=A;
25+
2126
module.exports={
2227
resolverDataInjector,
2328
};

‎packages/relay-runtime/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export type {Local3DPayload} from './util/createPayloadFor3DField';
239239
exporttype{Direction}from'./util/getPaginationVariables';
240240
exporttype{RequestIdentifier}from'./util/getRequestIdentifier';
241241
exporttype{ResolverFunction}from'./util/ReaderNode';
242-
exporttype{IdOf}from'./experimental';
242+
exporttype{IdOf,RelayResolverValue}from'./experimental';
243243

244244
// As early as possible, check for the existence of the JavaScript globals which
245245
// Relay Runtime relies upon, and produce a clear message if they do not exist.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp