Skip to content

Commit e21ccdc

Browse files
mrtnzlmladeira-github-bot
authored andcommitted
Universe: use Relay 13 and the new Rust Compiler
This commit upgrades Relay to version 13 and switches from the old Relay Compiler to the new Rust one (since both things go together). Basically, the main change is that now we have only one Relay config for the whole monorepo and the compiler is being executed for the whole monorepo as well (while being much faster). Additionally, Relay support is directly integrated into Flow so in many cases I simply removed previous Flow types (see `useLazyLoadQuery` and `useFragment`). There is still ongoing effort to improve the Flow types in Relay so not everything is finalized. For this reason I decided to use "Compat" types mode. Similarly, some hooks (`useMutation` and `usePreloadedQuery` for example) still require explicit types information so I didn't change these yet. Regardless of that, we are pretty close to use "Final" types. We just need to wait for the Relay team to finish everything. Many issues were already resolved but there are still some that need to be fixed (not blocking this PR): - facebook/relay#3700 - relayjs/eslint-plugin-relay#131 - prettier/prettier#6102 Important links with additional information: - https://relay.dev/blog/2021/12/08/introducing-the-new-relay-compiler/ - https://github.com/facebook/relay/releases/tag/v13.0.0 - https://github.com/facebook/relay/releases/tag/v13.0.0-rc.0 - https://github.com/facebook/relay/releases/tag/v13.0.0-rc.1 - https://github.com/facebook/relay/releases/tag/v13.0.0-rc.2 adeira-source-id: bc3d10741250e32b6fd399245f62d25484c6ae70
1 parent 6eb01a6 commit e21ccdc

26 files changed

+49
-852
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Unreleased
22

3+
- The old Relay Compiler wrapper has been replaces with the new Rust Compiler. This is the only compiler available in Relay 13+ and you can read more about this change here: https://relay.dev/blog/2021/12/08/introducing-the-new-relay-compiler/
4+
35
# 4.0.0
46

57
- **Breaking**: Relay version upgraded to 12.0.0, for more information please visit: https://github.com/facebook/relay/releases/tag/v12.0.0
Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
// @flow
22

33
let fetchSchemaOptions;
4-
let relayCompilerOptions;
54
beforeEach(() => {
65
jest.isolateModules(() => {
76
fetchSchemaOptions = require('../options').fetchSchemaOptions;
8-
relayCompilerOptions = require('../options').relayCompilerOptions;
97
});
108
});
119

@@ -35,55 +33,3 @@ describe('fetch schema', () => {
3533
});
3634
});
3735
});
38-
39-
describe('relay compiler', () => {
40-
it('no args', () => {
41-
expect(() => relayCompilerOptions(['node', 'test'])).toThrowErrorMatchingInlineSnapshot(
42-
`"Option --src is required."`,
43-
);
44-
});
45-
46-
it('with only src', () => {
47-
expect(() =>
48-
relayCompilerOptions(['node', 'test', '--src=AAA']),
49-
).toThrowErrorMatchingInlineSnapshot(`"Option --schema is required."`);
50-
});
51-
52-
it('with only schema', () => {
53-
expect(() =>
54-
relayCompilerOptions(['node', 'test', '--schema=BBB']),
55-
).toThrowErrorMatchingInlineSnapshot(`"Option --src is required."`);
56-
});
57-
58-
it('with only validate', () => {
59-
expect(() =>
60-
relayCompilerOptions(['node', 'test', '--validate']),
61-
).toThrowErrorMatchingInlineSnapshot(`"Option --src is required."`);
62-
});
63-
64-
it('with only watch', () => {
65-
expect(() =>
66-
relayCompilerOptions(['node', 'test', '--watch']),
67-
).toThrowErrorMatchingInlineSnapshot(`"Option --src is required."`);
68-
});
69-
70-
it('with src,schema', () => {
71-
expect(relayCompilerOptions(['node', 'test', '--src=AAA', '--schema=BBB'])).toStrictEqual({
72-
src: 'AAA',
73-
schema: 'BBB',
74-
validate: false,
75-
watch: false,
76-
});
77-
});
78-
79-
it('with all', () => {
80-
expect(
81-
relayCompilerOptions(['node', 'test', '--src=AAA', '--schema=BBB', '--validate', '--watch']),
82-
).toStrictEqual({
83-
src: 'AAA',
84-
schema: 'BBB',
85-
validate: true,
86-
watch: true,
87-
});
88-
});
89-
});

bin/commander/options.js

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -34,45 +34,3 @@ module.exports.fetchSchemaOptions = function (
3434

3535
return config;
3636
};
37-
38-
/*::
39-
40-
type RelayCompilerOptions = {
41-
+src: string,
42-
+schema: string,
43-
+validate: boolean,
44-
+watch: boolean,
45-
}
46-
47-
*/
48-
49-
module.exports.relayCompilerOptions = function (
50-
argToParse: $ReadOnlyArray<string>,
51-
) /*: RelayCompilerOptions */ {
52-
const relayConfig = RelayConfig.loadConfig() ?? {};
53-
54-
const options = program
55-
// Please note: try not to extend this CLI if possible. Always prefer "relay.config.js" file.
56-
.option('--src <src>')
57-
.option('--schema <schema>')
58-
.option('--validate', 'Activates validate only mode', false)
59-
.option(
60-
'--watch',
61-
'This option currently REQUIRES Watchman (https://facebook.github.io/watchman/) to be installed.',
62-
false,
63-
)
64-
.parse(argToParse)
65-
.opts();
66-
67-
const config = {
68-
src: options.src ?? relayConfig.src,
69-
schema: options.schema ?? relayConfig.schema,
70-
validate: options.validate ?? relayConfig.validate,
71-
watch: options.watch ?? relayConfig.watch,
72-
};
73-
74-
invariant(config.src != null, 'Option --src is required.');
75-
invariant(config.schema != null, 'Option --schema is required.');
76-
77-
return config;
78-
};

bin/relay-compiler.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

package.json

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,27 @@
1818
"adeira-fetch-schema": "bin/fetch-schema.js",
1919
"adeira-relay-compiler": "bin/relay-compiler.js"
2020
},
21-
"scripts": {
22-
"test": "yarn eslint src && yarn flow src",
23-
"regenerate": "./bin/relay-compiler.js --src=./src --schema=./schema.graphql"
24-
},
2521
"dependencies": {
2622
"@adeira/fetch": "^2.1.0",
2723
"@adeira/js": "^2.1.1",
2824
"@adeira/monorepo-utils": "^0.11.0",
2925
"@adeira/signed-source": "^2.0.0",
3026
"@babel/register": "^7.16.7",
3127
"@babel/runtime": "^7.16.7",
32-
"babel-plugin-relay": "^12.0.0",
28+
"babel-plugin-relay": "^13.0.0",
3329
"commander": "^8.3.0",
3430
"is-ci": "^3.0.1",
35-
"react-relay": "^12.0.0",
36-
"relay-compiler": "^12.0.0",
37-
"relay-config": "^12.0.1",
38-
"relay-runtime": "^12.0.0"
31+
"react-relay": "^13.0.0",
32+
"relay-compiler": "^13.0.0",
33+
"relay-config": "0.0.0-main-d92b9e55",
34+
"relay-runtime": "^13.0.0"
3935
},
4036
"devDependencies": {
4137
"@testing-library/react-hooks": "^7.0.2",
4238
"react": "^17.0.2",
4339
"react-dom": "^17.0.2",
4440
"react-test-renderer": "^17.0.2",
45-
"relay-test-utils": "^12.0.0"
41+
"relay-test-utils": "^13.0.0"
4642
},
4743
"peerDependencies": {
4844
"graphql": "^15.0.0",

src/__flowtests__/useLazyLoadQuery.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const query = graphql`
88
}
99
`;
1010

11+
type QueryVariables = {};
12+
1113
type QueryTypeMock = {
1214
+variables: {},
1315
+response: {},
@@ -16,16 +18,16 @@ type QueryTypeMock = {
1618
module.exports = {
1719
validUsage: (): (() => void) => {
1820
return function TestComponent() {
19-
useLazyLoadQuery<QueryTypeMock>(query);
20-
useLazyLoadQuery<QueryTypeMock>(query, {});
21+
useLazyLoadQuery<QueryVariables, QueryTypeMock>(query);
22+
useLazyLoadQuery<QueryVariables, QueryTypeMock>(query, Object.freeze({}));
2123
};
2224
},
2325

2426
// Invalid usages:
2527
invalidUsage: (): (() => void) => {
2628
return function TestComponent() {
2729
// $FlowExpectedError[incompatible-call]: should be an object
28-
useLazyLoadQuery<QueryTypeMock>(query, 'invalid');
30+
useLazyLoadQuery<QueryVariables, QueryTypeMock>(query, 'invalid');
2931
};
3032
},
3133
};

src/__tests__/__generated__/QueryRendererTestQuery.graphql.js

Lines changed: 25 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compiler/__tests__/__fixtures__/schemas/invalidSignatureSchema.schema.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/compiler/__tests__/__fixtures__/schemas/missingSignatureSchema.graphql.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/compiler/__tests__/__fixtures__/schemas/validSchema.graphql.txt

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/compiler/__tests__/__generated__/useRefetchableFragment.graphql.js

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)