Skip to content

Allow buildSchema() to take options. #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export {
} from './utilities';

export type {
BuildSchemaOptions,
BreakingChange,
DangerousChange,
IntrospectionOptions,
Expand Down
20 changes: 12 additions & 8 deletions src/utilities/buildASTSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { valueFromAST } from './valueFromAST';
import blockStringValue from '../language/blockStringValue';
import { TokenKind } from '../language/lexer';
import { parse } from '../language/parser';
import type { ParseOptions } from '../language/parser';
import type { Source } from '../language/source';
import { getDirectiveValues } from '../execution/values';
import { Kind } from '../language/kinds';
Expand Down Expand Up @@ -72,7 +73,7 @@ import type {
GraphQLFieldConfig,
} from '../type/definition';

type Options = {|
export type BuildSchemaOptions = {
...GraphQLSchemaValidationOptions,

/**
Expand All @@ -83,7 +84,7 @@ type Options = {|
* Default: false
*/
commentDescriptions?: boolean,
|};
};

function buildWrappedType(
innerType: GraphQLType,
Expand Down Expand Up @@ -128,7 +129,7 @@ function getNamedTypeNode(typeNode: TypeNode): NamedTypeNode {
*/
export function buildASTSchema(
ast: DocumentNode,
options?: Options,
options?: BuildSchemaOptions,
): GraphQLSchema {
if (!ast || ast.kind !== Kind.DOCUMENT) {
throw new Error('Must provide a document ast.');
Expand Down Expand Up @@ -246,13 +247,13 @@ type TypeResolver = (typeRef: NamedTypeNode) => GraphQLNamedType;

export class ASTDefinitionBuilder {
_typeDefinitionsMap: TypeDefinitionsMap;
_options: ?Options;
_options: ?BuildSchemaOptions;
_resolveType: TypeResolver;
_cache: ObjMap<GraphQLNamedType>;

constructor(
typeDefinitionsMap: TypeDefinitionsMap,
options: ?Options,
options: ?BuildSchemaOptions,
resolveType: TypeResolver,
) {
this._typeDefinitionsMap = typeDefinitionsMap;
Expand Down Expand Up @@ -464,7 +465,7 @@ function getDeprecationReason(
*/
export function getDescription(
node: { +description?: StringValueNode, +loc?: Location },
options: ?Options,
options: ?BuildSchemaOptions,
): void | string {
if (node.description) {
return node.description.value;
Expand Down Expand Up @@ -503,6 +504,9 @@ function getLeadingCommentBlock(node): void | string {
* A helper function to build a GraphQLSchema directly from a source
* document.
*/
export function buildSchema(source: string | Source): GraphQLSchema {
return buildASTSchema(parse(source));
export function buildSchema(
source: string | Source,
options: BuildSchemaOptions & ParseOptions,
): GraphQLSchema {
return buildASTSchema(parse(source, options), options);
}
1 change: 1 addition & 0 deletions src/utilities/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export { buildClientSchema } from './buildClientSchema';

// Build a GraphQLSchema from GraphQL Schema language.
export { buildASTSchema, buildSchema, getDescription } from './buildASTSchema';
export type { BuildSchemaOptions } from './buildASTSchema';

// Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST.
export { extendSchema } from './extendSchema';
Expand Down