From bb0b95dd7758d26efa88914f7fe658bd6cd2e980 Mon Sep 17 00:00:00 2001 From: Varun Choudhary <68095256+Varun-Choudhary@users.noreply.github.com> Date: Wed, 2 Nov 2022 12:19:33 +0530 Subject: [PATCH] console: fix gql try it button MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This PR fix the issue with `GraphIQL Try` button. The issue is when we create a new schema other then public and try the gql operation using the `GraphIQL Try` button, it give the query and all but the query field is just only table name not the schemaName_table name so it will give me an error saying that query_field doesn’t exist [Slack thread](https://hasurahq.slack.com/archives/CKATHV1J7/p1667214392972649?thread_ts=1667202504.721889&cid=CKATHV1J7) PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6635 GitOrigin-RevId: e1403db0c3e63d88d2380fe1137137329910f990 --- .../generateGqlQueryFromTable.test.tsx | 1 + .../src/components/Common/EditableHeading/utils.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/console/src/components/Common/EditableHeading/generateGqlQueryFromTable.test.tsx b/console/src/components/Common/EditableHeading/generateGqlQueryFromTable.test.tsx index 392e6793607..4a693858497 100644 --- a/console/src/components/Common/EditableHeading/generateGqlQueryFromTable.test.tsx +++ b/console/src/components/Common/EditableHeading/generateGqlQueryFromTable.test.tsx @@ -142,6 +142,7 @@ describe('generateGqlQueryFromTable', () => { name } } + " `); diff --git a/console/src/components/Common/EditableHeading/utils.ts b/console/src/components/Common/EditableHeading/utils.ts index fecc7481219..eea90e33ef6 100644 --- a/console/src/components/Common/EditableHeading/utils.ts +++ b/console/src/components/Common/EditableHeading/utils.ts @@ -86,10 +86,12 @@ export const generateGqlQueryFromTable = ( const fieldName = table.table_name; const fields = table.columns; const pascalCaseName = toPascalCase(fieldName); + const tableSchemaPart = + table.table_schema !== 'public' ? `${table.table_schema}_` : ''; if (operationType === 'query') { const query = `query Get${pascalCaseName} { - ${fieldName} { + ${tableSchemaPart}${fieldName} { ${indentFields(fields, 2)} } } @@ -113,8 +115,9 @@ export const generateGqlQueryFromTable = ( .map(sf => `${sf.column_name}: $${sf.column_name}`) .join(', ') .trim(); + const query = `mutation Insert${pascalCaseName}(${args}) { - insert_${fieldName}(objects: {${argsUsage}}) { + insert_${tableSchemaPart}${fieldName}(objects: {${argsUsage}}) { affected_rows returning { ${indentFields(fields, 3)} @@ -145,7 +148,7 @@ export const generateGqlQueryFromTable = ( ); const query = `subscription Get${pascalCaseName}StreamingSubscription { - ${fieldName}_stream(batch_size: 10, cursor: {initial_value: {${ + ${tableSchemaPart}${fieldName}_stream(batch_size: 10, cursor: {initial_value: {${ initialValueColumn.column_name }: ${initialValue}}}) { ${indentFields(fields, 2)} @@ -160,10 +163,11 @@ export const generateGqlQueryFromTable = ( if (operationType === 'subscription') { const query = `subscription Get${pascalCaseName}StreamingSubscription { - ${fieldName} { + ${tableSchemaPart}${fieldName} { ${indentFields(fields, 2)} } } + `; return {