/*** IMPORT ------------------------------------------- ***/ import { buildClientSchema, getIntrospectionQuery, printSchema, type GraphQLSchema, type IntrospectionQuery } from "graphql"; /*** UTILITY ------------------------------------------ ***/ import type { Fetcher } from "../fetcher/types.ts"; /*** EXPORT ------------------------------------------- ***/ export class SchemaStore { error = $state(null); loading = $state(false); schema = $state(null); sdl = $state(""); async introspect(fetcher: Fetcher) { this.loading = true; this.error = null; try { const result = await fetcher({ query: getIntrospectionQuery() }); const data = (result as { data: IntrospectionQuery }).data; this.schema = buildClientSchema(data); this.sdl = printSchema(this.schema); } catch(err) { this.error = String(err); } finally { this.loading = false; } } }