mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-19 07:19:45 +02:00
Fix GraphQL introspection breaking app
https://feedback.yaak.app/p/workspace-crash-when-graphql-introspection-returns-unexpected-response
This commit is contained in:
@@ -108,12 +108,11 @@ export function useIntrospectGraphQL(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
const parseResult = tryParseIntrospectionToSchema(introspection.data.content);
|
||||||
const schema = buildClientSchema(JSON.parse(introspection.data.content).data);
|
if ('error' in parseResult) {
|
||||||
setSchema(schema);
|
setError(parseResult.error);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
} else {
|
||||||
} catch (e: any) {
|
setSchema(parseResult.schema);
|
||||||
setError('message' in e ? e.message : String(e));
|
|
||||||
}
|
}
|
||||||
}, [introspection.data?.content]);
|
}, [introspection.data?.content]);
|
||||||
|
|
||||||
@@ -135,7 +134,26 @@ export function useCurrentGraphQLSchema(request: HttpRequest) {
|
|||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (result.data == null) return null;
|
if (result.data == null) return null;
|
||||||
if (result.data.content == null || result.data.content === '') return null;
|
if (result.data.content == null || result.data.content === '') return null;
|
||||||
const schema = buildClientSchema(JSON.parse(result.data.content).data);
|
const r = tryParseIntrospectionToSchema(result.data.content);
|
||||||
return schema;
|
return 'error' in r ? null : r.schema;
|
||||||
}, [result.data]);
|
}, [result.data]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function tryParseIntrospectionToSchema(
|
||||||
|
content: string,
|
||||||
|
): { schema: GraphQLSchema } | { error: string } {
|
||||||
|
let parsedResponse;
|
||||||
|
try {
|
||||||
|
parsedResponse = JSON.parse(content).data;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
} catch (e: any) {
|
||||||
|
return { error: String('message' in e ? e.message : e) };
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return { schema: buildClientSchema(parsedResponse, {}) };
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
} catch (e: any) {
|
||||||
|
return { error: String('message' in e ? e.message : e) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user