Skip to content

Commit

Permalink
fix test utils for ResolverFragments
Browse files Browse the repository at this point in the history
Summary:
Fix for #3718

 ---

When we're bundling `relay-rutime` the bundle script puts all JS files in the `lib` directory.

So, when we're requiring this
`relay-runtime/store/ResolverFragments` module from `relay-runtime` it is not there. It's in the  `relay-runtime/lib/store/ResolverFragments`.

The proposed fix is to re-export `ResolverFragments` from `relay-runtime`.

Reviewed By: kassens

Differential Revision: D33454330

fbshipit-source-id: 2922e8eccfa51ff25873d3557a4febb56392d00d
  • Loading branch information
alunyov authored and facebook-github-bot committed Jan 6, 2022
1 parent 4f1a0b0 commit a93d922
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions packages/relay-runtime/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const RelayModernStore = require('./store/RelayModernStore');
const RelayOperationTracker = require('./store/RelayOperationTracker');
const RelayRecordSource = require('./store/RelayRecordSource');
const RelayStoreUtils = require('./store/RelayStoreUtils');
const ResolverFragments = require('./store/ResolverFragments');
const ViewerPattern = require('./store/ViewerPattern');
const requestSubscription = require('./subscription/requestSubscription');
const createPayloadFor3DField = require('./util/createPayloadFor3DField');
Expand Down Expand Up @@ -352,6 +353,7 @@ module.exports = {
getPendingOperationsForFragment: getPendingOperationsForFragment,
getValueAtPath: getValueAtPath,
__internal: {
ResolverFragments,
OperationTracker: RelayOperationTracker,
createRelayContext: createRelayContext,
getOperationVariables: RelayConcreteVariables.getOperationVariables,
Expand Down
4 changes: 2 additions & 2 deletions packages/relay-runtime/store/ResolverFragments.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function withResolverContext<T>(context: ResolverContext, cb: () => T): T {
// The declarations ensure that the type of the returned data is:
// - non-nullable if the provided ref type is non-nullable
// - nullable if the provided ref type is nullable
// - array of non-nullable if the privoided ref type is an array of
// - array of non-nullable if the provided ref type is an array of
// non-nullable refs
// - array of nullable if the privoided ref type is an array of nullable refs
// - array of nullable if the provided ref type is an array of nullable refs

declare function readFragment<
TKey: {+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
Expand Down
6 changes: 4 additions & 2 deletions packages/relay-test-utils/RelayResolverTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

'use strict';

const ResolverFragments = require('relay-runtime/store/ResolverFragments');
const {
__internal: {ResolverFragments},
} = require('relay-runtime');

/**
* Utility function for testing Relay Resolvers. Pass the resolver function and
Expand All @@ -20,7 +22,7 @@ const ResolverFragments = require('relay-runtime/store/ResolverFragments');
*
* *Note:* Relay fragment data includes a special `$fragmentType` key which is
* impossible for non-Relay code to construct. In tests you can work around
* this by passing `null` with a Flow supression:
* this by passing `null` with a Flow suppression:
*
* ```
* const fragmentData = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@

import type {RelayResolverTestUtilsTest$key} from './__generated__/RelayResolverTestUtilsTest.graphql';

// TODO: T109483224 Make sure the test utils are working correctly, when `readFragment` is
// required from `relay-runtime`.
const {readFragment} = require('../../relay-runtime/store/ResolverFragments');
const {testResolver} = require('../RelayResolverTestUtils');
const {graphql} = require('relay-runtime');
const {readFragment} = require('relay-runtime/store/ResolverFragments');

function myTestResolver(rootKey: RelayResolverTestUtilsTest$key): string {
const user = readFragment(
Expand Down

0 comments on commit a93d922

Please sign in to comment.