-
Notifications
You must be signed in to change notification settings - Fork 135
/
Copy pathidl.ts
30 lines (27 loc) · 811 Bytes
/
idl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { buildSchema, execute, parse } from "graphql";
import { resolve } from "path";
import {
ApolloIntrospection,
GraphQLIntrospection,
Introspection,
SchemaLoader,
} from "../interface";
import { query as introspectionQuery } from "../utility";
import { readFile } from "../utility/fs";
export interface IIdlSchemaLoaderOptions {
schemaFile: string;
}
export const idlSchemaLoader: SchemaLoader = async (
options: IIdlSchemaLoaderOptions
) => {
const schemaPath = resolve(options.schemaFile);
const idl = await readFile(schemaPath, "utf8");
const introspection = (await execute(
buildSchema(idl),
parse(introspectionQuery)
)) as Introspection;
return (
(introspection as ApolloIntrospection).__schema ||
(introspection as GraphQLIntrospection).data.__schema
);
};