Fixes and improvements on Native Queries

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/9433
GitOrigin-RevId: 2a9b31e4867871a2f6c51db3c6449e0f496266c7
This commit is contained in:
Luca Restagno 2023-06-07 15:13:34 +02:00 committed by hasura-bot
parent 504ef83b11
commit eefa345bf8
9 changed files with 44 additions and 24 deletions

View File

@ -36,7 +36,7 @@ const fillAndSubmitForm: Story['play'] = async ({ canvasElement }) => {
const errorMessages = [
'Native Query Name is required',
'Database is required',
'Paramater Name is required',
'Parameter Name is required',
'Query Return Type is required',
];
@ -45,7 +45,7 @@ const fillAndSubmitForm: Story['play'] = async ({ canvasElement }) => {
}
// remove param added for error testing
await userEvent.click(c.getByText('Remove'));
await userEvent.click(c.getAllByText('Remove')[0]);
await userEvent.type(
c.getByPlaceholderText('Name that exposes this model in GraphQL API'),
@ -65,8 +65,8 @@ const fillAndSubmitForm: Story['play'] = async ({ canvasElement }) => {
await userEvent.click(await c.findByText('Add Parameter'));
await userEvent.type(c.getByPlaceholderText('Parameter Name'), 'param1');
await userEvent.type(c.getByPlaceholderText('Default Value'), 'default');
await userEvent.click(c.getByTestId('required-switch'));
await userEvent.type(c.getByPlaceholderText('Description'), 'description');
await userEvent.click(c.getByTestId('nullable-switch'));
await userEvent.selectOptions(
await c.findByLabelText('Query Return Type', undefined, { timeout: 3000 }),

View File

@ -215,7 +215,7 @@ export const AddNativeQuery = ({
/>
) : null}
<div className="flex flex-row justify-end gap-2">
{/*
{/*
Validate Button will remain hidden until we have more information about how to handle standalone validation
Slack thread: https://hasurahq.slack.com/archives/C04LV93JNSH/p1682965503376129
*/}

View File

@ -10,9 +10,9 @@ import { FaPlusCircle } from 'react-icons/fa';
import { Button } from '../../../../../new-components/Button';
import {
GraphQLSanitizedInputField,
InputField,
Select,
fieldLabelStyles,
InputField,
} from '../../../../../new-components/Form';
import { BooleanInput } from '../../components/BooleanInput';
import { useCardedTableFromReactTableWithRef } from '../../components/CardedTableFromReactTable';
@ -57,23 +57,26 @@ export const ArgumentsField = ({ types }: { types: string[] }) => {
),
header: 'Type',
}),
columnHelper.accessor('default_value', {
id: 'default_value',
columnHelper.accessor('description', {
id: 'description',
cell: ({ row }) => (
<InputField
noErrorPlaceholder
placeholder="Default Value"
name={`arguments.${row.index}.default_value`}
placeholder="Description"
name={`arguments.${row.index}.description`}
/>
),
header: 'Default Value',
header: 'Description',
}),
columnHelper.accessor('required', {
id: 'required',
columnHelper.accessor('nullable', {
id: 'nullable',
cell: ({ row }) => (
<BooleanInput name={`arguments.${row.index}.required`} />
<BooleanInput
name={`arguments.${row.index}.nullable`}
dataTestId="nullable-switch"
/>
),
header: 'Required',
header: 'Nullable',
}),
columnHelper.display({
id: 'action',
@ -110,6 +113,8 @@ export const ArgumentsField = ({ types }: { types: string[] }) => {
append({
name: '',
type: 'text',
nullable: false,
description: '',
});
}}
>

View File

@ -16,10 +16,10 @@ export const schema = implement<NativeQueryForm>().with({
type: z.enum(['query', 'mutation']).default('query').optional(),
arguments: z
.object({
name: reqString('Paramater Name'),
name: reqString('Parameter Name'),
type: reqString('Parameter Type'),
default_value: z.string().optional(),
required: z.boolean().optional(),
description: z.string().optional(),
nullable: z.boolean().optional(),
})
.array(),
code: reqString('Sql Query'),

View File

@ -1,11 +1,14 @@
import React, { useState } from 'react';
import React, { useEffect, useState } from 'react';
import { InjectedRouter, Link, withRouter } from 'react-router';
import { useDestructiveAlert } from '../../../../new-components/Alert';
import { Button } from '../../../../new-components/Button';
import { Tabs } from '../../../../new-components/Tabs';
import { hasuraToast } from '../../../../new-components/Toasts';
import { usePushRoute } from '../../../ConnectDBRedesign/hooks';
import { useMetadata } from '../../../hasura-metadata-api';
import {
useInvalidateMetadata,
useMetadata,
} from '../../../hasura-metadata-api';
import { useTrackLogicalModel } from '../../hooks/useTrackLogicalModel';
import { useTrackNativeQuery } from '../../hooks/useTrackNativeQuery';
import { LogicalModelWidget } from '../LogicalModelWidget/LogicalModelWidget';
@ -33,6 +36,17 @@ export const LandingPage = ({ pathname }: { pathname: string }) => {
)
.flat()
);
const invalidateMetadata = useInvalidateMetadata();
useEffect(() => {
/**
* Workaround to avoid that a metadata migration that happened in the legacy part of the Console (i.e. Run SQL)
* might affect the metadata migrations in the child components of this page,
* resulting in the error "metadata resource version referenced (x) did not match current version"
*/
invalidateMetadata();
}, []);
const nativeQueries = data?.queries ?? [];
const logicalModels = data?.models ?? [];

View File

@ -115,6 +115,7 @@ export const FieldsInput = ({
<div className={clsx(fieldLabelStyles, 'mb-0')}>Fields</div>
<Button
icon={<FaPlusCircle />}
disabled={!types || types.length === 0}
onClick={() => {
append({ name: '', type: 'text', nullable: true });
}}

View File

@ -1,7 +1,7 @@
import { z } from 'zod';
export const addLogicalModelValidationSchema = z.object({
dataSourceName: z.string(),
dataSourceName: z.string().min(1, 'Source is required'),
name: z.string().min(1, 'Name is a required field'),
fields: z
.object({

View File

@ -27,7 +27,7 @@ export const BooleanInput = ({
error={fieldState.error}
>
<Switch
data-testid="required-switch"
data-testid={wrapperProps.dataTestId || 'switch'}
checked={value}
onCheckedChange={onChange}
disabled={disabled}

View File

@ -1,7 +1,7 @@
export type NativeQueryArgument = {
type: string;
default_value?: string;
required?: boolean;
description?: string;
nullable?: boolean;
};
export type NativeQuery = {