Skip to content

Commit

Permalink
Relay: fix generated artifacts of 'useRefetchableFragment'
Browse files Browse the repository at this point in the history
This issue affects upstream as well, see: facebook/relay#3404

We have the advantage of having the generated output under control so I fixed it here for `@adeira/relay` and reported it to the upstream.

adeira-source-id: 079091984297d98698575e38e48da94aff601017
  • Loading branch information
mrtnzlml authored and adeira-github-bot committed Mar 12, 2021
1 parent d62baad commit bbff1bb
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 1 deletion.

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.

19 changes: 19 additions & 0 deletions src/compiler/__tests__/useRefetchableFragment.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow

import { graphql } from '../../index';

it('generates and flow checks the fragment as expected', () => {
// This is technically a Flow test (we are forcing generation of Relay artifacts).
// Relay Compiler generated invalid artifacts for eager ES modules, see:
// https://github.com/adeira/universe/issues/1975

graphql`
fragment useRefetchableFragment on RootQuery
@refetchable(queryName: "useRefetchableFragmentRefetchQuery") {
# eslint-disable-next-line relay/unused-fields
node(id: "my-id") {
__typename
}
}
`;
});
5 changes: 5 additions & 0 deletions src/compiler/createPrintRequireDefaultModuleDependency.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// @flow strict

export default function createPrintRequireDefaultModuleDependency(): (string) => string {
return (moduleName) => `require('./${moduleName}.js').default`;
}
3 changes: 2 additions & 1 deletion src/compiler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { globSync } from '@adeira/monorepo-utils';

import buildLanguagePlugin from './buildLanguagePlugin';
import buildWatchExpression from './buildWatchExpression';
import createPrintRequireDefaultModuleDependency from './createPrintRequireDefaultModuleDependency';
import getSchemaSource from './getSchemaSource';

type ExternalOptions = {|
Expand Down Expand Up @@ -175,7 +176,7 @@ function getRelayFileWriter(
noFutureProofEnums,
extension: languagePlugin.outputExtension,
typeGenerator: languagePlugin.typeGenerator,
outputDir,
printModuleDependency: createPrintRequireDefaultModuleDependency(),
// repersist: isCI, // TODO
};

Expand Down

0 comments on commit bbff1bb

Please sign in to comment.