@graphql-tools/load
Version:
A set of utils for faster development of GraphQL tools
55 lines (54 loc) • 2.25 kB
TypeScript
import { BuildSchemaOptions, GraphQLSchema } from 'graphql';
import { IExecutableSchemaDefinition } from '@graphql-tools/schema';
import { LoadTypedefsOptions, UnnormalizedTypeDefPointer } from './load-typedefs.js';
export type SchemaSortMode = 'lexicographic' | 'typesOnly';
export type LoadSchemaOptions = BuildSchemaOptions & LoadTypedefsOptions & Partial<IExecutableSchemaDefinition> & {
/**
* Adds a list of Sources in to `extensions.sources`
*
* Disabled by default.
*/
includeSources?: boolean;
/**
* How to sort the schema when `sort` is true.
*
* `lexicographic` (default) uses GraphQL's `lexicographicSortSchema`.
* Types, fields, arguments, and enum values are all reordered.
*
* `typesOnly` sorts only the type list. Field and enum value order stay as loaded.
*
* @example
* Given:
* ```graphql
* enum DayOfWeek { SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY }
* type Query { d: String z: String a: String day: DayOfWeek }
* ```
*
* `sort: true`:
* ```graphql
* enum DayOfWeek { FRIDAY MONDAY SATURDAY SUNDAY THURSDAY TUESDAY WEDNESDAY }
* type Query { a: String d: String day: DayOfWeek z: String }
* ```
*
* `sort: true, sortMode: 'typesOnly'`:
* ```graphql
* enum DayOfWeek { SUNDAY MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY }
* type Query { d: String z: String a: String day: DayOfWeek }
* ```
*
* `sort: false` ignores `sortMode`.
*/
sortMode?: SchemaSortMode;
};
/**
* Asynchronously loads a schema from the provided pointers.
* @param schemaPointers Pointers to the sources to load the schema from
* @param options Additional options
*/
export declare function loadSchema(schemaPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], options: LoadSchemaOptions): Promise<GraphQLSchema>;
/**
* Synchronously loads a schema from the provided pointers.
* @param schemaPointers Pointers to the sources to load the schema from
* @param options Additional options
*/
export declare function loadSchemaSync(schemaPointers: UnnormalizedTypeDefPointer | UnnormalizedTypeDefPointer[], options: LoadSchemaOptions): GraphQLSchema;