mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
bbaf619f63
swc_bundler: - [x] Fix wrapped esms. (denoland/deno#9307) - [x] Make test secure.
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
// Loaded from https://deno.land/x/graphql_deno@v15.0.0/lib/utilities/introspectionFromSchema.js
|
|
|
|
|
|
import invariant from '../jsutils/invariant.js';
|
|
import isPromise from '../jsutils/isPromise.js';
|
|
import { parse } from '../language/parser.js';
|
|
import { execute } from '../execution/execute.js';
|
|
import { getIntrospectionQuery } from './getIntrospectionQuery.js';
|
|
/**
|
|
* Build an IntrospectionQuery from a GraphQLSchema
|
|
*
|
|
* IntrospectionQuery is useful for utilities that care about type and field
|
|
* relationships, but do not need to traverse through those relationships.
|
|
*
|
|
* This is the inverse of buildClientSchema. The primary use case is outside
|
|
* of the server context, for instance when doing schema comparisons.
|
|
*/
|
|
|
|
export function introspectionFromSchema(schema, options) {
|
|
const optionsWithDefaults = {
|
|
directiveIsRepeatable: true,
|
|
schemaDescription: true,
|
|
...options
|
|
};
|
|
const document = parse(getIntrospectionQuery(optionsWithDefaults));
|
|
const result = execute({
|
|
schema,
|
|
document
|
|
});
|
|
invariant(!isPromise(result) && !result.errors && result.data);
|
|
return result.data;
|
|
} |