node_modules.apollo-codegen.src.introspectSchema.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apollo-client-maven-plugin Show documentation
Show all versions of apollo-client-maven-plugin Show documentation
Maven plugin for generating graphql clients
import * as fs from 'fs';
import { buildASTSchema, graphql, parse, DocumentNode, GraphQLSchema } from 'graphql';
import { introspectionQuery } from 'graphql/utilities';
import { ToolError } from 'apollo-codegen-core/lib/errors'
declare module "graphql/utilities/buildASTSchema" {
function buildASTSchema(
ast: DocumentNode,
options?: { assumeValid?: boolean, commentDescriptions?: boolean },
): GraphQLSchema;
}
export async function introspect(schemaContents: string) {
const schema = buildASTSchema(parse(schemaContents), { commentDescriptions: true });
return await graphql(schema, introspectionQuery);
}
export default async function introspectSchema(schemaPath: string, outputPath: string) {
if (!fs.existsSync(schemaPath)) {
throw new ToolError(`Cannot find GraphQL schema file: ${schemaPath}`);
}
const schemaContents = fs.readFileSync(schemaPath).toString();
const result = await introspect(schemaContents);
if (result.errors) {
throw new ToolError(`Errors in introspection query result: ${result.errors}`);
}
fs.writeFileSync(outputPath, JSON.stringify(result, null, 2));
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy