Skip to content

Commit 83b6e37

Browse files
fix(graphql): graphql tab schema not handling tabs correctly (#13850)
Fixes #13833 When generating graphql schemas, named tabs were not properly being accounted for. This PR fixes that and ensure that the correct schema types are generated for named tabs.
1 parent 42b5935 commit 83b6e37

File tree

4 files changed

+356
-55
lines changed

4 files changed

+356
-55
lines changed

.vscode/launch.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,27 @@
269269
"outputCapture": "std",
270270
"request": "launch",
271271
"type": "node-terminal"
272+
},
273+
{
274+
"name": "Debug GraphQL Schema Generation",
275+
"type": "node",
276+
"request": "launch",
277+
"program": "${workspaceFolder}/test/generateGraphQLSchema.ts",
278+
"args": ["graphql"],
279+
"cwd": "${workspaceFolder}",
280+
"env": {
281+
"NODE_OPTIONS": "--no-deprecation --no-experimental-strip-types"
282+
},
283+
"runtimeArgs": [
284+
"--no-deprecation",
285+
"--no-experimental-strip-types",
286+
"--import",
287+
"@swc-node/register/esm-register"
288+
],
289+
"console": "integratedTerminal",
290+
"outputCapture": "std",
291+
"sourceMaps": true,
292+
"skipFiles": ["<node_internals>/**"]
272293
}
273294
],
274295
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

packages/graphql/src/schema/buildPoliciesType.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const buildFields = (label, fieldsToBuild) =>
6969
}
7070
}
7171

72-
if (!field.name && field.fields) {
72+
if (!field.name && field.fields && field.fields.length) {
7373
const subFields = buildFields(label, field.fields)
7474

7575
return {
@@ -81,6 +81,18 @@ const buildFields = (label, fieldsToBuild) =>
8181
if (field.type === 'tabs') {
8282
return field.tabs.reduce(
8383
(fieldsWithTabFields, tab) => {
84+
if ('name' in tab) {
85+
if (tab.fields.length) {
86+
const tabName = formatName(tab.name)
87+
fieldsWithTabFields[tabName] = {
88+
type: new GraphQLObjectType({
89+
name: `${label}_${tabName}`,
90+
fields: buildFields(`${label}_${tabName}`, tab.fields),
91+
}),
92+
}
93+
}
94+
return fieldsWithTabFields
95+
}
8496
return {
8597
...fieldsWithTabFields,
8698
...buildFields(label, tab.fields),

packages/graphql/src/schema/recursivelyBuildNestedPaths.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@ export const recursivelyBuildNestedPaths = ({ field, nestedFieldName2, parentNam
2222
...recursivelyBuildNestedPaths({
2323
field: {
2424
...tab,
25-
type: 'name' in tab ? 'group' : 'row',
25+
...('name' in tab
26+
? {
27+
name: `${nestedFieldName ? `${nestedFieldName}__` : ''}${tab.name}`,
28+
type: 'group',
29+
}
30+
: {
31+
type: 'row',
32+
}),
2633
},
2734
nestedFieldName2: nestedFieldName,
2835
parentName,

0 commit comments

Comments
 (0)