Skip to content

Commit

Permalink
Universe: use Relay 13 and the new Rust Compiler
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mrtnzlml authored and kodiakhq[bot] committed Jan 7, 2022
1 parent c7c6b10 commit bc3d107
Show file tree
Hide file tree
Showing 116 changed files with 2,080 additions and 2,695 deletions.
4 changes: 3 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
node_modules/

src/babel-preset-adeira/src/__tests__/__fixtures__
src/example-relay/__github__/flow-typed
src/sx-tailwind-website/__github__/flow-typed

# https://github.com/prettier/prettier/issues/6102
**/__generated__/*.graphql.js

# https://github.com/eslint/eslint/issues/8429
!**/.storybook
6 changes: 6 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,9 @@ suppress_type=$FlowFixMe
; This option is always ON in the strict mode. We are enabling it even for the classic mode.
; Function parameters are considered const (i.e., treated as if they were declared with const rather than let).
experimental.const_params=true

relay_integration=true
relay_integration.module_prefix=./__generated__/
; TODO: consider removing the following excludes
relay_integration.excludes=.*/__tests__/.*
relay_integration.excludes=.*/__flowtests__/.*
42 changes: 42 additions & 0 deletions relay.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// @flow strict

module.exports = {
root: '.',
sources: {
'src/abacus-backoffice': 'abacus',
'src/abacus-kochka': 'abacus',
'src/example-relay': 'example-relay',
},
excludes: ['**/__flowtests__/**'],
codegenCommand: './node_modules/.bin/relay-compiler',
projects: {
'abacus': {
language: 'flow',
flowEnums: [
// TODO: doesn't work (https://github.com/facebook/relay/issues/3596#issuecomment-1003148218)
'SupportedCurrency',
'SupportedLocale',
],
flowTypegen: {
phase: 'Compat', // TODO: "Final"
},
schema: 'src/abacus/schema.graphql',
customScalarTypes: {
ProductImageUploadable: 'string',
},
testPathRegex: '__tests__',
featureFlags: {
no_inline: { kind: 'enabled' },
},
},
'example-relay': {
language: 'flow',
flowTypegen: {
phase: 'Compat', // TODO: "Final"
},
schema: 'src/example-relay/schema.graphql',
schemaExtensions: ['src/example-relay/src/LocalForm'],
},
},
isDevVariableName: '__DEV__',
};
11 changes: 0 additions & 11 deletions src/abacus-backoffice/relay.config.js

This file was deleted.

7 changes: 3 additions & 4 deletions src/abacus-backoffice/src/NavigationHeaderBadge.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import React, { type Node } from 'react';
import sx from '@adeira/sx';
import { graphql, useLazyLoadQuery } from '@adeira/relay';

import type { NavigationHeaderBadgeQuery } from './__generated__/NavigationHeaderBadgeQuery.graphql';

function ProdBadge(): Node {
return <span className={styles('prod')}>PROD</span>;
}
Expand All @@ -15,7 +13,8 @@ function DevBadge(): Node {
}

export default function NavigationHeaderBadge(): Node {
const data = useLazyLoadQuery<NavigationHeaderBadgeQuery>(
// eslint-disable-next-line relay/generated-flow-types -- https://github.com/relayjs/eslint-plugin-relay/issues/131
const data = useLazyLoadQuery(
graphql`
query NavigationHeaderBadgeQuery {
auth {
Expand All @@ -25,7 +24,7 @@ export default function NavigationHeaderBadge(): Node {
}
}
`,
{},
Object.freeze({}),
{
fetchPolicy: 'store-or-network',
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions src/abacus-backoffice/src/analytics/AnalyticsRedirectsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { Badge, Link, Table } from '@adeira/sx-design';
import React, { type Node } from 'react';
import { useLazyLoadQuery, graphql } from '@adeira/relay';

import type { AnalyticsRedirectsPageQuery } from './__generated__/AnalyticsRedirectsPageQuery.graphql';

export default function AnalyticsRedirectsPage(): Node {
const { analytics } = useLazyLoadQuery<AnalyticsRedirectsPageQuery>(graphql`
// eslint-disable-next-line relay/generated-flow-types -- https://github.com/relayjs/eslint-plugin-relay/issues/131
const { analytics } = useLazyLoadQuery(graphql`
query AnalyticsRedirectsPageQuery {
analytics {
redirectHits {
Expand Down
Loading

0 comments on commit bc3d107

Please sign in to comment.