mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-22 08:38:29 +02:00
Format GraphQL variables
This commit is contained in:
@@ -2,6 +2,7 @@ import { updateSchema } from 'cm6-graphql';
|
|||||||
import type { EditorView } from 'codemirror';
|
import type { EditorView } from 'codemirror';
|
||||||
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
import { useCallback, useEffect, useMemo, useRef } from 'react';
|
||||||
import { useIntrospectGraphQL } from '../hooks/useIntrospectGraphQL';
|
import { useIntrospectGraphQL } from '../hooks/useIntrospectGraphQL';
|
||||||
|
import { tryFormatJson } from '../lib/formatters';
|
||||||
import type { HttpRequest } from '../lib/models';
|
import type { HttpRequest } from '../lib/models';
|
||||||
import { Button } from './core/Button';
|
import { Button } from './core/Button';
|
||||||
import type { EditorProps } from './core/Editor';
|
import type { EditorProps } from './core/Editor';
|
||||||
@@ -89,10 +90,10 @@ export function GraphQLEditor({ defaultValue, onChange, baseRequest, ...extraEdi
|
|||||||
onClick={() => {
|
onClick={() => {
|
||||||
dialog.show({
|
dialog.show({
|
||||||
title: 'Introspection Failed',
|
title: 'Introspection Failed',
|
||||||
size: 'sm',
|
size: 'dynamic',
|
||||||
id: 'introspection-failed',
|
id: 'introspection-failed',
|
||||||
render: () => (
|
render: () => (
|
||||||
<div className="whitespace-pre-wrap">
|
<>
|
||||||
<FormattedError>{error ?? 'unknown'}</FormattedError>
|
<FormattedError>{error ?? 'unknown'}</FormattedError>
|
||||||
<div className="w-full mt-3">
|
<div className="w-full mt-3">
|
||||||
<Button
|
<Button
|
||||||
@@ -107,7 +108,7 @@ export function GraphQLEditor({ defaultValue, onChange, baseRequest, ...extraEdi
|
|||||||
Try Again
|
Try Again
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</>
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
@@ -121,6 +122,7 @@ export function GraphQLEditor({ defaultValue, onChange, baseRequest, ...extraEdi
|
|||||||
<Separator variant="primary" />
|
<Separator variant="primary" />
|
||||||
<p className="pt-1 text-gray-500 text-sm">Variables</p>
|
<p className="pt-1 text-gray-500 text-sm">Variables</p>
|
||||||
<Editor
|
<Editor
|
||||||
|
format={tryFormatJson}
|
||||||
contentType="application/json"
|
contentType="application/json"
|
||||||
defaultValue={JSON.stringify(variables, null, 2)}
|
defaultValue={JSON.stringify(variables, null, 2)}
|
||||||
heightMode="auto"
|
heightMode="auto"
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export function Dialog({
|
|||||||
<span />
|
<span />
|
||||||
)}
|
)}
|
||||||
{description && <p id={descriptionId}>{description}</p>}
|
{description && <p id={descriptionId}>{description}</p>}
|
||||||
<div className="h-full w-full">{children}</div>
|
<div className="h-full w-full grid grid-cols-[minmax(0,1fr)]">{children}</div>
|
||||||
{/*Put close at the end so that it's the last thing to be tabbed to*/}
|
{/*Put close at the end so that it's the last thing to be tabbed to*/}
|
||||||
{!hideX && (
|
{!hideX && (
|
||||||
<IconButton
|
<IconButton
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ interface Props {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function FormattedError({ children }: Props) {
|
export function FormattedError({ children }: Props) {
|
||||||
|
console.log('ERROR', children);
|
||||||
return (
|
return (
|
||||||
<pre
|
<pre
|
||||||
className={classNames(
|
className={classNames(
|
||||||
'text-sm select-auto cursor-text bg-gray-100 p-3 rounded',
|
'w-full text-sm select-auto cursor-text bg-gray-100 p-3 rounded',
|
||||||
'whitespace-normal border border-red-500 border-dashed',
|
'whitespace-pre border border-red-500 border-dashed overflow-x-auto',
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
@@ -44,8 +44,9 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (response.status < 200 || response.status >= 300) {
|
if (response.status < 200 || response.status >= 300) {
|
||||||
|
const text = await getResponseBodyText(response);
|
||||||
return Promise.reject(
|
return Promise.reject(
|
||||||
new Error(`Request failed with status ${response.status}.\n\n${response.body}`),
|
new Error(`Request failed with status ${response.status}.\n\n${text}`),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user