mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-24 18:31:16 +01:00
Fix graphql instrospection
This commit is contained in:
@@ -156,7 +156,7 @@
|
||||
|
||||
/* NOTE: Extra selector required to override default styles */
|
||||
.cm-tooltip.cm-tooltip {
|
||||
@apply shadow-lg bg-gray-50 rounded text-gray-700 border border-gray-200 z-50 pointer-events-auto text-sm;
|
||||
@apply shadow-lg bg-gray-50 rounded text-gray-700 border border-gray-200 z-50 pointer-events-auto text-[0.75rem];
|
||||
|
||||
&.cm-completionInfo-right {
|
||||
@apply ml-1;
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { GraphQLSchema } from 'graphql';
|
||||
import { buildClientSchema, getIntrospectionQuery } from '../components/core/Editor';
|
||||
import { minPromiseMillis } from '../lib/minPromiseMillis';
|
||||
import type { HttpRequest } from '../lib/models';
|
||||
import { getResponseBodyText } from '../lib/responseBody';
|
||||
import { sendEphemeralRequest } from '../lib/sendEphemeralRequest';
|
||||
import { useDebouncedValue } from './useDebouncedValue';
|
||||
|
||||
@@ -35,11 +36,12 @@ export function useIntrospectGraphQL(baseRequest: HttpRequest) {
|
||||
);
|
||||
}
|
||||
|
||||
if (response.body === null) {
|
||||
const body = await getResponseBodyText(response);
|
||||
if (body === null) {
|
||||
return Promise.reject(new Error('Empty body returned in response'));
|
||||
}
|
||||
|
||||
const { data } = JSON.parse(response.body);
|
||||
const { data } = JSON.parse(body);
|
||||
return buildClientSchema(data);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,20 +1,12 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { readBinaryFile } from '@tauri-apps/api/fs';
|
||||
import type { HttpResponse } from '../lib/models';
|
||||
import { getResponseBodyBlob } from '../lib/responseBody';
|
||||
|
||||
export function useResponseBodyBlob(response: HttpResponse) {
|
||||
return useQuery<Uint8Array | null>({
|
||||
enabled: response != null,
|
||||
queryKey: ['response-body-binary', response?.updatedAt],
|
||||
initialData: null,
|
||||
queryFn: async () => {
|
||||
if (response.body) {
|
||||
return Uint8Array.of(...response.body);
|
||||
}
|
||||
if (response.bodyPath) {
|
||||
return readBinaryFile(response.bodyPath);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
queryFn: () => getResponseBodyBlob(response),
|
||||
}).data;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,11 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { readTextFile } from '@tauri-apps/api/fs';
|
||||
import type { HttpResponse } from '../lib/models';
|
||||
import { getResponseBodyText } from '../lib/responseBody';
|
||||
|
||||
export function useResponseBodyText(response: HttpResponse) {
|
||||
return useQuery<string | null>({
|
||||
queryKey: ['response-body-text', response?.updatedAt],
|
||||
initialData: null,
|
||||
queryFn: async () => {
|
||||
if (response.body) {
|
||||
const uint8Array = Uint8Array.of(...response.body);
|
||||
return new TextDecoder().decode(uint8Array);
|
||||
}
|
||||
|
||||
if (response.bodyPath) {
|
||||
return await readTextFile(response.bodyPath);
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
queryFn: () => getResponseBodyText(response),
|
||||
}).data;
|
||||
}
|
||||
|
||||
23
src-web/lib/responseBody.ts
Normal file
23
src-web/lib/responseBody.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { readBinaryFile, readTextFile } from '@tauri-apps/api/fs';
|
||||
import type { HttpResponse } from './models';
|
||||
|
||||
export async function getResponseBodyText(response: HttpResponse): Promise<string | null> {
|
||||
if (response.body) {
|
||||
const uint8Array = Uint8Array.of(...response.body);
|
||||
return new TextDecoder().decode(uint8Array);
|
||||
}
|
||||
if (response.bodyPath) {
|
||||
return await readTextFile(response.bodyPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function getResponseBodyBlob(response: HttpResponse): Promise<Uint8Array | null> {
|
||||
if (response.body) {
|
||||
return Uint8Array.of(...response.body);
|
||||
}
|
||||
if (response.bodyPath) {
|
||||
return readBinaryFile(response.bodyPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import { invoke } from '@tauri-apps/api';
|
||||
import type { HttpRequest, HttpResponse } from './models';
|
||||
|
||||
export function sendEphemeralRequest(request: HttpRequest): Promise<HttpResponse> {
|
||||
export async function sendEphemeralRequest(request: HttpRequest): Promise<HttpResponse> {
|
||||
// Remove some things that we don't want to associate
|
||||
const newRequest = { ...request, id: '', requestId: '', workspaceId: '' };
|
||||
return invoke('send_ephemeral_request', { request: newRequest });
|
||||
|
||||
Reference in New Issue
Block a user