facebook / facebook/relay

Bug: Flow error when using `--eagerESModules` and `@refetchable`

Open
#3,404 2 comments 1 reaction 0 assignees View on GitHub
bug wontfix
Dominant language
Rust
Stars
19k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

Hola! πŸ‘‹ This issue is for Relay 11.0.0. I created a reproducible demo here: https://github.com/mrtnzlml/bug-relay-useRefetchableFragment-flow

Specifically, the issue is with this line: https://github.com/mrtnzlml/bug-relay-useRefetchableFragment-flow/blob/53ee2bf03395037e72ad306f99df801ff4639491/__generated__/bugRelayUseRefetchableFragmentFlow.graphql.js#L36

# Problem

Flow throws an error when generating artifacts with `--eagerESModules` and `@refetchable`:

```text
Error β”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆβ”ˆ __generated__/bugRelayUseRefetchableFragmentFlow.graphql.js:36:20

Cannot assign object literal to node because property bugRelayUseRefetchableFragmentFlowQuery is missing in
ConcreteRequest [1] but exists in module ./bugRelayUseRefetchableFragmentFlowQuery.graphql.js [2] in property
metadata.refetch.operation. [incompatible-type]

__generated__/bugRelayUseRefetchableFragmentFlow.graphql.js
33β”‚ "refetch": {
34β”‚ "connection": null,
35β”‚ "fragmentPathInResult": [],
[2] 36β”‚ "operation": require('./bugRelayUseRefetchableFragmentFlowQuery.graphql.js')
37β”‚ }
38β”‚ },
39β”‚ "name": "bugRelayUseRefetchableFragmentFlow",

node_modules/relay-runtime/util/ReaderNode.js.flow
[1] 68β”‚ +operation: string | ConcreteRequest,

Found 1 error
```

# Steps to reproduce

1) clone https://github.com/mrtnzlml/bug-relay-useRefetchableFragment-flow
2) `yarn install`
3) `yarn run relay-compiler --src=. --schema=schema.graphql --eagerESModules`
4) `yarn run flow` πŸ’₯

# Possible solution

The artifact could be generated with `require(…).default` when using `--eagerESModules` option like so:

```diff
"metadata": {
"refetch": {
"connection": null,
"fragmentPathInResult": [],
- "operation": require('./bugRelayUseRefetchableFragmentFlowQuery.graphql.js')
+ "operation": require('./bugRelayUseRefetchableFragmentFlowQuery.graphql.js').default
}
}
```

_(no Flow errors)_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.