console: fix gql try it button

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
This commit is contained in:
Varun Choudhary 2022-11-02 12:19:33 +05:30 committed by hasura-bot
parent 1538490bdd
commit bb0b95dd77
2 changed files with 9 additions and 4 deletions

View File

@ -143,6 +143,7 @@ describe('generateGqlQueryFromTable', () => {
} }
} }
" "
`); `);
expect(variables).toBe(undefined); expect(variables).toBe(undefined);

View File

@ -86,10 +86,12 @@ export const generateGqlQueryFromTable = (
const fieldName = table.table_name; const fieldName = table.table_name;
const fields = table.columns; const fields = table.columns;
const pascalCaseName = toPascalCase(fieldName); const pascalCaseName = toPascalCase(fieldName);
const tableSchemaPart =
table.table_schema !== 'public' ? `${table.table_schema}_` : '';
if (operationType === 'query') { if (operationType === 'query') {
const query = `query Get${pascalCaseName} { const query = `query Get${pascalCaseName} {
${fieldName} { ${tableSchemaPart}${fieldName} {
${indentFields(fields, 2)} ${indentFields(fields, 2)}
} }
} }
@ -113,8 +115,9 @@ export const generateGqlQueryFromTable = (
.map(sf => `${sf.column_name}: $${sf.column_name}`) .map(sf => `${sf.column_name}: $${sf.column_name}`)
.join(', ') .join(', ')
.trim(); .trim();
const query = `mutation Insert${pascalCaseName}(${args}) { const query = `mutation Insert${pascalCaseName}(${args}) {
insert_${fieldName}(objects: {${argsUsage}}) { insert_${tableSchemaPart}${fieldName}(objects: {${argsUsage}}) {
affected_rows affected_rows
returning { returning {
${indentFields(fields, 3)} ${indentFields(fields, 3)}
@ -145,7 +148,7 @@ export const generateGqlQueryFromTable = (
); );
const query = `subscription Get${pascalCaseName}StreamingSubscription { 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 initialValueColumn.column_name
}: ${initialValue}}}) { }: ${initialValue}}}) {
${indentFields(fields, 2)} ${indentFields(fields, 2)}
@ -160,11 +163,12 @@ export const generateGqlQueryFromTable = (
if (operationType === 'subscription') { if (operationType === 'subscription') {
const query = `subscription Get${pascalCaseName}StreamingSubscription { const query = `subscription Get${pascalCaseName}StreamingSubscription {
${fieldName} { ${tableSchemaPart}${fieldName} {
${indentFields(fields, 2)} ${indentFields(fields, 2)}
} }
} }
`; `;
return { return {
query, query,