relay-test-utils
Version:
Utilities for testing Relay applications.
43 lines (34 loc) • 1.07 kB
Flow
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
* @oncall relay
*/
;
import type {RelayResolverTestUtilsFlowTest$key} from './__generated__/RelayResolverTestUtilsFlowTest.graphql';
const {testResolver} = require('../RelayResolverTestUtils');
const {graphql} = require('relay-runtime');
const {readFragment} = require('relay-runtime/store/ResolverFragments');
function myTestResolver(rootKey: RelayResolverTestUtilsFlowTest$key): string {
const user = readFragment(
graphql`
fragment RelayResolverTestUtilsFlowTest on User {
name
}
`,
rootKey,
);
return `Hello ${user.name ?? 'stranger'}!`;
}
testResolver(myTestResolver, {name: 'Elizabeth'});
// $FlowExpectedError foo is an unexpected key
testResolver(myTestResolver, {
name: 'Elizabeth',
foo: 'bar',
});
// $FlowExpectedError Object is not a string
testResolver(myTestResolver, {name: {}});