diff --git a/packages/relay-test-utils/RelayMockPayloadGenerator.js b/packages/relay-test-utils/RelayMockPayloadGenerator.js index 7577b8f2abf9e..0d59861eacdf9 100644 --- a/packages/relay-test-utils/RelayMockPayloadGenerator.js +++ b/packages/relay-test-utils/RelayMockPayloadGenerator.js @@ -528,7 +528,7 @@ class RelayMockPayloadGenerator { false, path, null, - null, + defaultValues, ), }; } diff --git a/packages/relay-test-utils/__tests__/RelayMockPayloadGenerator-test.js b/packages/relay-test-utils/__tests__/RelayMockPayloadGenerator-test.js index aaffe53457d40..c86cd03c00f85 100644 --- a/packages/relay-test-utils/__tests__/RelayMockPayloadGenerator-test.js +++ b/packages/relay-test-utils/__tests__/RelayMockPayloadGenerator-test.js @@ -1891,3 +1891,44 @@ test('generate mock for streamed fragments with if condition false', () => { {generateDeferredPayload: true}, ); }); + +test('should generate data for @match with PlainUserNameRenderer_name and use defaults from mock resolvers', () => { + graphql` + fragment RelayMockPayloadGeneratorTest67Fragment on User { + id + nameRenderer { + ...RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name + @module(name: "PlainUserNameRenderer.react") + } + } + `; + graphql` + fragment RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name on PlainUserNameRenderer { + plaintext + data { + text + } + } + `; + + testGeneratedData( + graphql` + query RelayMockPayloadGeneratorTest67Query @relay_test_operation { + node(id: "my-id") { + ...RelayMockPayloadGeneratorTest67Fragment + } + } + `, + { + UserNameRenderer() { + return { + __typename: 'PlainUserNameRenderer', + __module_operation: require('./__generated__/RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql'), + data: { + text: 'hello world', + }, + }; + }, + }, + ); +}); diff --git a/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67Fragment.graphql.js b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67Fragment.graphql.js new file mode 100644 index 0000000000000..10c7457933361 --- /dev/null +++ b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67Fragment.graphql.js @@ -0,0 +1,92 @@ +/** + * 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. + * + * @oncall relay + * + * @generated SignedSource<> + * @flow + * @lightSyntaxTransform + * @nogrep + */ + +/* eslint-disable */ + +'use strict'; + +// @dataDrivenDependency RelayMockPayloadGeneratorTest67Fragment.nameRenderer {"branches":{"PlainUserNameRenderer":{"component":"PlainUserNameRenderer.react","fragment":"RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql"}},"plural":false} + +/*:: +import type { Fragment, ReaderFragment } from 'relay-runtime'; +import type { RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$fragmentType } from "./RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name.graphql"; +import type { FragmentType } from "relay-runtime"; +declare export opaque type RelayMockPayloadGeneratorTest67Fragment$fragmentType: FragmentType; +export type RelayMockPayloadGeneratorTest67Fragment$data = {| + +id: string, + +nameRenderer: ?{| + +__fragmentPropName?: ?string, + +__module_component?: ?string, + +$fragmentSpreads: RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$fragmentType, + |}, + +$fragmentType: RelayMockPayloadGeneratorTest67Fragment$fragmentType, +|}; +export type RelayMockPayloadGeneratorTest67Fragment$key = { + +$data?: RelayMockPayloadGeneratorTest67Fragment$data, + +$fragmentSpreads: RelayMockPayloadGeneratorTest67Fragment$fragmentType, + ... +}; +*/ + +var node/*: ReaderFragment*/ = { + "argumentDefinitions": [], + "kind": "Fragment", + "metadata": null, + "name": "RelayMockPayloadGeneratorTest67Fragment", + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "id", + "storageKey": null + }, + { + "alias": null, + "args": null, + "concreteType": null, + "kind": "LinkedField", + "name": "nameRenderer", + "plural": false, + "selections": [ + { + "kind": "InlineFragment", + "selections": [ + { + "args": null, + "documentName": "RelayMockPayloadGeneratorTest67Fragment", + "fragmentName": "RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name", + "fragmentPropName": "name", + "kind": "ModuleImport" + } + ], + "type": "PlainUserNameRenderer", + "abstractKey": null + } + ], + "storageKey": null + } + ], + "type": "User", + "abstractKey": null +}; + +if (__DEV__) { + (node/*: any*/).hash = "f0621398b162c8e470bd7beb63d0d78a"; +} + +module.exports = ((node/*: any*/)/*: Fragment< + RelayMockPayloadGeneratorTest67Fragment$fragmentType, + RelayMockPayloadGeneratorTest67Fragment$data, +>*/); diff --git a/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql.js b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql.js new file mode 100644 index 0000000000000..984a4e2b41e28 --- /dev/null +++ b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql.js @@ -0,0 +1,68 @@ +/** + * 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. + * + * @oncall relay + * + * @generated SignedSource<> + * @flow + * @lightSyntaxTransform + * @nogrep + */ + +/* eslint-disable */ + +'use strict'; + +/*:: +import type { NormalizationSplitOperation } from 'relay-runtime'; + +*/ + +var node/*: NormalizationSplitOperation*/ = { + "kind": "SplitOperation", + "metadata": {}, + "name": "RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization", + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "plaintext", + "storageKey": null + }, + { + "alias": null, + "args": null, + "concreteType": "PlainUserNameData", + "kind": "LinkedField", + "name": "data", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "text", + "storageKey": null + }, + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "id", + "storageKey": null + } + ], + "storageKey": null + } + ] +}; + +if (__DEV__) { + (node/*: any*/).hash = "6292a26c9ba4d0e57ddcc19c901e1cbe"; +} + +module.exports = node; diff --git a/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name.graphql.js b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name.graphql.js new file mode 100644 index 0000000000000..7747ae034909f --- /dev/null +++ b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name.graphql.js @@ -0,0 +1,80 @@ +/** + * 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. + * + * @oncall relay + * + * @generated SignedSource<<91e22cebe4e9def2c1d15095ed5522be>> + * @flow + * @lightSyntaxTransform + * @nogrep + */ + +/* eslint-disable */ + +'use strict'; + +/*:: +import type { Fragment, ReaderFragment } from 'relay-runtime'; +import type { FragmentType } from "relay-runtime"; +declare export opaque type RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$fragmentType: FragmentType; +export type RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$data = {| + +data: ?{| + +text: ?string, + |}, + +plaintext: ?string, + +$fragmentType: RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$fragmentType, +|}; +export type RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$key = { + +$data?: RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$data, + +$fragmentSpreads: RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$fragmentType, + ... +}; +*/ + +var node/*: ReaderFragment*/ = { + "argumentDefinitions": [], + "kind": "Fragment", + "metadata": null, + "name": "RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name", + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "plaintext", + "storageKey": null + }, + { + "alias": null, + "args": null, + "concreteType": "PlainUserNameData", + "kind": "LinkedField", + "name": "data", + "plural": false, + "selections": [ + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "text", + "storageKey": null + } + ], + "storageKey": null + } + ], + "type": "PlainUserNameRenderer", + "abstractKey": null +}; + +if (__DEV__) { + (node/*: any*/).hash = "6292a26c9ba4d0e57ddcc19c901e1cbe"; +} + +module.exports = ((node/*: any*/)/*: Fragment< + RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$fragmentType, + RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$data, +>*/); diff --git a/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67Query.graphql.js b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67Query.graphql.js new file mode 100644 index 0000000000000..d3e35f35fa3aa --- /dev/null +++ b/packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest67Query.graphql.js @@ -0,0 +1,213 @@ +/** + * 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. + * + * @oncall relay + * + * @generated SignedSource<> + * @flow + * @lightSyntaxTransform + * @nogrep + */ + +/* eslint-disable */ + +'use strict'; + +// @indirectDataDrivenDependency RelayMockPayloadGeneratorTest67Fragment.nameRenderer {"branches":{"PlainUserNameRenderer":{"component":"PlainUserNameRenderer.react","fragment":"RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql"}},"plural":false} + +/*:: +import type { ConcreteRequest, Query } from 'relay-runtime'; +import type { RelayMockPayloadGeneratorTest67Fragment$fragmentType } from "./RelayMockPayloadGeneratorTest67Fragment.graphql"; +export type RelayMockPayloadGeneratorTest67Query$variables = {||}; +export type RelayMockPayloadGeneratorTest67Query$data = {| + +node: ?{| + +$fragmentSpreads: RelayMockPayloadGeneratorTest67Fragment$fragmentType, + |}, +|}; +export type RelayMockPayloadGeneratorTest67Query = {| + response: RelayMockPayloadGeneratorTest67Query$data, + variables: RelayMockPayloadGeneratorTest67Query$variables, +|}; +*/ + +var node/*: ConcreteRequest*/ = (function(){ +var v0 = [ + { + "kind": "Literal", + "name": "id", + "value": "my-id" + } +], +v1 = { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "__typename", + "storageKey": null +}, +v2 = { + "enumValues": null, + "nullable": false, + "plural": false, + "type": "String" +}, +v3 = { + "enumValues": null, + "nullable": true, + "plural": false, + "type": "JSDependency" +}, +v4 = { + "enumValues": null, + "nullable": true, + "plural": false, + "type": "String" +}; +return { + "fragment": { + "argumentDefinitions": [], + "kind": "Fragment", + "metadata": null, + "name": "RelayMockPayloadGeneratorTest67Query", + "selections": [ + { + "alias": null, + "args": (v0/*: any*/), + "concreteType": null, + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + { + "args": null, + "kind": "FragmentSpread", + "name": "RelayMockPayloadGeneratorTest67Fragment" + } + ], + "storageKey": "node(id:\"my-id\")" + } + ], + "type": "Query", + "abstractKey": null + }, + "kind": "Request", + "operation": { + "argumentDefinitions": [], + "kind": "Operation", + "name": "RelayMockPayloadGeneratorTest67Query", + "selections": [ + { + "alias": null, + "args": (v0/*: any*/), + "concreteType": null, + "kind": "LinkedField", + "name": "node", + "plural": false, + "selections": [ + (v1/*: any*/), + { + "alias": null, + "args": null, + "kind": "ScalarField", + "name": "id", + "storageKey": null + }, + { + "kind": "InlineFragment", + "selections": [ + { + "alias": null, + "args": null, + "concreteType": null, + "kind": "LinkedField", + "name": "nameRenderer", + "plural": false, + "selections": [ + (v1/*: any*/), + { + "kind": "InlineFragment", + "selections": [ + { + "args": null, + "documentName": "RelayMockPayloadGeneratorTest67Fragment", + "fragmentName": "RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name", + "fragmentPropName": "name", + "kind": "ModuleImport" + } + ], + "type": "PlainUserNameRenderer", + "abstractKey": null + } + ], + "storageKey": null + } + ], + "type": "User", + "abstractKey": null + } + ], + "storageKey": "node(id:\"my-id\")" + } + ] + }, + "params": { + "cacheID": "0ae903db9d578aaf4dd7019f4d024645", + "id": null, + "metadata": { + "relayTestingSelectionTypeInfo": { + "node": { + "enumValues": null, + "nullable": true, + "plural": false, + "type": "Node" + }, + "node.__typename": (v2/*: any*/), + "node.id": { + "enumValues": null, + "nullable": false, + "plural": false, + "type": "ID" + }, + "node.nameRenderer": { + "enumValues": null, + "nullable": true, + "plural": false, + "type": "UserNameRenderer" + }, + "node.nameRenderer.__module_component_RelayMockPayloadGeneratorTest67Fragment": (v3/*: any*/), + "node.nameRenderer.__module_operation_RelayMockPayloadGeneratorTest67Fragment": (v3/*: any*/), + "node.nameRenderer.__typename": (v2/*: any*/), + "node.nameRenderer.data": { + "enumValues": null, + "nullable": true, + "plural": false, + "type": "PlainUserNameData" + }, + "node.nameRenderer.data.id": { + "enumValues": null, + "nullable": true, + "plural": false, + "type": "ID" + }, + "node.nameRenderer.data.text": (v4/*: any*/), + "node.nameRenderer.plaintext": (v4/*: any*/) + } + }, + "name": "RelayMockPayloadGeneratorTest67Query", + "operationKind": "query", + "text": "query RelayMockPayloadGeneratorTest67Query {\n node(id: \"my-id\") {\n __typename\n ...RelayMockPayloadGeneratorTest67Fragment\n id\n }\n}\n\nfragment RelayMockPayloadGeneratorTest67Fragment on User {\n id\n nameRenderer {\n __typename\n ... on PlainUserNameRenderer {\n ...RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name\n __module_operation_RelayMockPayloadGeneratorTest67Fragment: js(module: \"RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql\", id: \"RelayMockPayloadGeneratorTest67Fragment.nameRenderer\")\n __module_component_RelayMockPayloadGeneratorTest67Fragment: js(module: \"PlainUserNameRenderer.react\", id: \"RelayMockPayloadGeneratorTest67Fragment.nameRenderer\")\n }\n }\n}\n\nfragment RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name on PlainUserNameRenderer {\n plaintext\n data {\n text\n id\n }\n}\n" + } +}; +})(); + +if (__DEV__) { + (node/*: any*/).hash = "09729a7c122a5fedbea96ed60b70ee3b"; +} + +module.exports = ((node/*: any*/)/*: Query< + RelayMockPayloadGeneratorTest67Query$variables, + RelayMockPayloadGeneratorTest67Query$data, +>*/); diff --git a/packages/relay-test-utils/__tests__/__snapshots__/RelayMockPayloadGenerator-test.js.snap b/packages/relay-test-utils/__tests__/__snapshots__/RelayMockPayloadGenerator-test.js.snap index 3380cd9d29bb3..5541969e6b028 100644 --- a/packages/relay-test-utils/__tests__/__snapshots__/RelayMockPayloadGenerator-test.js.snap +++ b/packages/relay-test-utils/__tests__/__snapshots__/RelayMockPayloadGenerator-test.js.snap @@ -1373,6 +1373,56 @@ fragment RelayMockPayloadGeneratorTest13Fragment on Viewer { } `; +exports[`should generate data for @match with PlainUserNameRenderer_name and use defaults from mock resolvers 1`] = ` +~~~~~~~~~~ INPUT ~~~~~~~~~~ +query RelayMockPayloadGeneratorTest67Query { + node(id: "my-id") { + __typename + ...RelayMockPayloadGeneratorTest67Fragment + id + } +} + +fragment RelayMockPayloadGeneratorTest67Fragment on User { + id + nameRenderer { + __typename + ... on PlainUserNameRenderer { + ...RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name + __module_operation_RelayMockPayloadGeneratorTest67Fragment: js(module: "RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization.graphql", id: "RelayMockPayloadGeneratorTest67Fragment.nameRenderer") + __module_component_RelayMockPayloadGeneratorTest67Fragment: js(module: "PlainUserNameRenderer.react", id: "RelayMockPayloadGeneratorTest67Fragment.nameRenderer") + } + } +} + +fragment RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name on PlainUserNameRenderer { + plaintext + data { + text + id + } +} + +~~~~~~~~~~ OUTPUT ~~~~~~~~~~ +{ + "data": { + "node": { + "__typename": "User", + "id": "", + "nameRenderer": { + "__typename": "PlainUserNameRenderer", + "__module_operation_RelayMockPayloadGeneratorTest67Fragment": "RelayMockPayloadGeneratorTest67PlainUserNameRenderer_name$normalization", + "plaintext": "", + "data": { + "text": "hello world", + "id": "" + } + } + } + } +} +`; + exports[`should return \`null\` for selection if that is specified in default values 1`] = ` ~~~~~~~~~~ INPUT ~~~~~~~~~~ query RelayMockPayloadGeneratorTest19Query {