Skip to content

Commit 22a3c89

Browse files
Alex Danofffacebook-github-bot
authored andcommitted
import ClientRequest for client only mutations
Reviewed By: alunyov Differential Revision: D50805852 fbshipit-source-id: 222e4e81becfa62b108afdb1fab17189f7163d3b
1 parent c36131a commit 22a3c89

File tree

7 files changed

+294
-3
lines changed

7 files changed

+294
-3
lines changed

compiler/crates/relay-compiler/src/build_project/artifact_generated_types.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ impl ArtifactGeneratedTypes {
4343
("Query", "ConcreteRequest, Query")
4444
}
4545
}
46-
OperationKind::Mutation => ("Mutation", "ConcreteRequest, Mutation"),
46+
OperationKind::Mutation => {
47+
if is_client_only {
48+
("Mutation", "ClientRequest, Mutation")
49+
} else {
50+
("Mutation", "ConcreteRequest, Mutation")
51+
}
52+
}
4753
OperationKind::Subscription => (
4854
"GraphQLSubscription",
4955
"ConcreteRequest, GraphQLSubscription",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
==================================== INPUT ====================================
2+
//- bar.js
3+
graphql`mutation barMutation {
4+
foo_mutation
5+
}`
6+
7+
//- relay.config.json
8+
{
9+
"language": "flow",
10+
"schema": "./schema.graphql",
11+
"eagerEsModules": true,
12+
"featureFlags": {
13+
"enable_relay_resolver_transform": true
14+
},
15+
"schemaExtensions": [
16+
"./extensions.graphql"
17+
]
18+
}
19+
20+
//- schema.graphql
21+
22+
type Mutation
23+
24+
25+
//- extensions.graphql
26+
27+
extend type Mutation {
28+
foo_mutation: Boolean
29+
}
30+
==================================== OUTPUT ===================================
31+
//- __generated__/barMutation.graphql.js
32+
/**
33+
* <auto-generated> SignedSource<<8c2ec235b8b068c2c2fffbc3aae787b8>>
34+
* @flow
35+
* @lightSyntaxTransform
36+
* @nogrep
37+
*/
38+
39+
/* eslint-disable */
40+
41+
'use strict';
42+
43+
/*::
44+
import type { ClientRequest, Mutation } from 'relay-runtime';
45+
export type barMutation$variables = {||};
46+
export type barMutation$data = {|
47+
+foo_mutation: ?boolean,
48+
|};
49+
export type barMutation = {|
50+
response: barMutation$data,
51+
variables: barMutation$variables,
52+
|};
53+
*/
54+
55+
var node/*: ClientRequest*/ = (function(){
56+
var v0 = [
57+
{
58+
"kind": "ClientExtension",
59+
"selections": [
60+
{
61+
"alias": null,
62+
"args": null,
63+
"kind": "ScalarField",
64+
"name": "foo_mutation",
65+
"storageKey": null
66+
}
67+
]
68+
}
69+
];
70+
return {
71+
"fragment": {
72+
"argumentDefinitions": [],
73+
"kind": "Fragment",
74+
"metadata": null,
75+
"name": "barMutation",
76+
"selections": (v0/*: any*/),
77+
"type": "Mutation",
78+
"abstractKey": null
79+
},
80+
"kind": "Request",
81+
"operation": {
82+
"argumentDefinitions": [],
83+
"kind": "Operation",
84+
"name": "barMutation",
85+
"selections": (v0/*: any*/)
86+
},
87+
"params": {
88+
"cacheID": "b7409af7b3a13247f776ad3f9192c84b",
89+
"id": null,
90+
"metadata": {},
91+
"name": "barMutation",
92+
"operationKind": "mutation",
93+
"text": null
94+
}
95+
};
96+
})();
97+
98+
(node/*: any*/).hash = "1f3610a117a92bb877caf826f77fae63";
99+
100+
export default ((node/*: any*/)/*: Mutation<
101+
barMutation$variables,
102+
barMutation$data,
103+
>*/);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//- bar.js
2+
graphql`mutation barMutation {
3+
foo_mutation
4+
}`
5+
6+
//- relay.config.json
7+
{
8+
"language": "flow",
9+
"schema": "./schema.graphql",
10+
"eagerEsModules": true,
11+
"featureFlags": {
12+
"enable_relay_resolver_transform": true
13+
},
14+
"schemaExtensions": [
15+
"./extensions.graphql"
16+
]
17+
}
18+
19+
//- schema.graphql
20+
21+
type Mutation
22+
23+
24+
//- extensions.graphql
25+
26+
extend type Mutation {
27+
foo_mutation: Boolean
28+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
==================================== INPUT ====================================
2+
//- foo.js
3+
/**
4+
* @RelayResolver Mutation.foo_mutation: Boolean
5+
*/
6+
7+
//- bar.js
8+
graphql`mutation barMutation {
9+
foo_mutation
10+
}`
11+
12+
//- relay.config.json
13+
{
14+
"language": "flow",
15+
"schema": "./schema.graphql",
16+
"eagerEsModules": true,
17+
"featureFlags": {
18+
"enable_relay_resolver_transform": true
19+
}
20+
}
21+
22+
//- schema.graphql
23+
24+
type Mutation
25+
==================================== OUTPUT ===================================
26+
//- __generated__/barMutation.graphql.js
27+
/**
28+
* <auto-generated> SignedSource<<7f1de50339842bab9cecc72c6fbc076f>>
29+
* @flow
30+
* @lightSyntaxTransform
31+
* @nogrep
32+
*/
33+
34+
/* eslint-disable */
35+
36+
'use strict';
37+
38+
/*::
39+
import type { ClientRequest, Mutation } from 'relay-runtime';
40+
import {foo_mutation as mutationFooMutationResolverType} from "../foo.js";
41+
// Type assertion validating that `mutationFooMutationResolverType` resolver is correctly implemented.
42+
// A type error here indicates that the type signature of the resolver module is incorrect.
43+
(mutationFooMutationResolverType: () => ?boolean);
44+
export type barMutation$variables = {||};
45+
export type barMutation$data = {|
46+
+foo_mutation: ?boolean,
47+
|};
48+
export type barMutation = {|
49+
response: barMutation$data,
50+
variables: barMutation$variables,
51+
|};
52+
*/
53+
54+
import {foo_mutation as mutationFooMutationResolver} from './../foo';
55+
56+
var node/*: ClientRequest*/ = {
57+
"fragment": {
58+
"argumentDefinitions": [],
59+
"kind": "Fragment",
60+
"metadata": null,
61+
"name": "barMutation",
62+
"selections": [
63+
{
64+
"kind": "ClientExtension",
65+
"selections": [
66+
{
67+
"alias": null,
68+
"args": null,
69+
"fragment": null,
70+
"kind": "RelayResolver",
71+
"name": "foo_mutation",
72+
"resolverModule": mutationFooMutationResolver,
73+
"path": "foo_mutation"
74+
}
75+
]
76+
}
77+
],
78+
"type": "Mutation",
79+
"abstractKey": null
80+
},
81+
"kind": "Request",
82+
"operation": {
83+
"argumentDefinitions": [],
84+
"kind": "Operation",
85+
"name": "barMutation",
86+
"selections": [
87+
{
88+
"kind": "ClientExtension",
89+
"selections": [
90+
{
91+
"name": "foo_mutation",
92+
"args": null,
93+
"fragment": null,
94+
"kind": "RelayResolver",
95+
"storageKey": null,
96+
"isOutputType": true
97+
}
98+
]
99+
}
100+
]
101+
},
102+
"params": {
103+
"cacheID": "b7409af7b3a13247f776ad3f9192c84b",
104+
"id": null,
105+
"metadata": {},
106+
"name": "barMutation",
107+
"operationKind": "mutation",
108+
"text": null
109+
}
110+
};
111+
112+
(node/*: any*/).hash = "1f3610a117a92bb877caf826f77fae63";
113+
114+
export default ((node/*: any*/)/*: Mutation<
115+
barMutation$variables,
116+
barMutation$data,
117+
>*/);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
//- foo.js
2+
/**
3+
* @RelayResolver Mutation.foo_mutation: Boolean
4+
*/
5+
6+
//- bar.js
7+
graphql`mutation barMutation {
8+
foo_mutation
9+
}`
10+
11+
//- relay.config.json
12+
{
13+
"language": "flow",
14+
"schema": "./schema.graphql",
15+
"eagerEsModules": true,
16+
"featureFlags": {
17+
"enable_relay_resolver_transform": true
18+
}
19+
}
20+
21+
//- schema.graphql
22+
23+
type Mutation

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,28 @@
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<<04c298d7b18b4ef4e4be2c9c820b2e46>>
7+
* @generated SignedSource<<6a4360c4cb2d5b7641f3a41ae33f6a27>>
88
*/
99

1010
mod relay_compiler_integration;
1111

1212
use relay_compiler_integration::transform_fixture;
1313
use fixture_tests::test_fixture;
1414

15+
#[tokio::test]
16+
async fn client_mutation_extension() {
17+
let input = include_str!("relay_compiler_integration/fixtures/client_mutation_extension.input");
18+
let expected = include_str!("relay_compiler_integration/fixtures/client_mutation_extension.expected");
19+
test_fixture(transform_fixture, "client_mutation_extension.input", "relay_compiler_integration/fixtures/client_mutation_extension.expected", input, expected).await;
20+
}
21+
22+
#[tokio::test]
23+
async fn client_mutation_resolver() {
24+
let input = include_str!("relay_compiler_integration/fixtures/client_mutation_resolver.input");
25+
let expected = include_str!("relay_compiler_integration/fixtures/client_mutation_resolver.expected");
26+
test_fixture(transform_fixture, "client_mutation_resolver.input", "relay_compiler_integration/fixtures/client_mutation_resolver.expected", input, expected).await;
27+
}
28+
1529
#[tokio::test]
1630
async fn simple_fragment() {
1731
let input = include_str!("relay_compiler_integration/fixtures/simple_fragment.input");

packages/relay-runtime/util/RelayConcreteNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export type ClientRequestParameters = {
7474
+text: null,
7575
// common fields
7676
+name: string,
77-
+operationKind: 'query',
77+
+operationKind: 'query' | 'mutation',
7878
+providedVariables?: ProvidedVariablesType,
7979
+metadata: {[key: string]: mixed, ...},
8080
};

0 commit comments

Comments
 (0)