Comparing version 0.1.12 to 0.2.0
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -11,6 +11,2 @@ * Copyright (c) 2015, Facebook, Inc. | ||
/** | ||
* Given a GraphQLError, format it according to the rules described by the | ||
* Response Format, Errors section of the GraphQL Specification. | ||
*/ | ||
'use strict'; | ||
@@ -25,8 +21,13 @@ | ||
var _utilsInvariant = require('../utils/invariant'); | ||
var _jsutilsInvariant = require('../jsutils/invariant'); | ||
var _utilsInvariant2 = _interopRequireDefault(_utilsInvariant); | ||
var _jsutilsInvariant2 = _interopRequireDefault(_jsutilsInvariant); | ||
function formatError(error) { | ||
(0, _utilsInvariant2['default'])(error, 'Received null or undefined error.'); | ||
/** | ||
* Given a GraphQLError, format it according to the rules described by the | ||
* Response Format, Errors section of the GraphQL Specification. | ||
*/ | ||
/*:: import type { GraphQLError } from './GraphQLError';*/ | ||
function formatError(error /*: GraphQLError*/) /*: GraphQLFormattedError*/ { | ||
(0, _jsutilsInvariant2['default'])(error, 'Received null or undefined error.'); | ||
return { | ||
@@ -36,2 +37,11 @@ message: error.message, | ||
}; | ||
} | ||
} | ||
/*:: export type GraphQLFormattedError = { | ||
message: string, | ||
locations: ?Array<GraphQLErrorLocation> | ||
};*/ | ||
/*:: export type GraphQLErrorLocation = { | ||
line: number, | ||
column: number | ||
};*/ |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -25,8 +25,9 @@ * Copyright (c) 2015, Facebook, Inc. | ||
/*:: import type { Node } from '../language/ast';*/ | ||
var GraphQLError = (function (_Error) { | ||
_inherits(GraphQLError, _Error); | ||
function GraphQLError(message, | ||
function GraphQLError(message /*: string*/, | ||
// A flow bug keeps us from declaring nodes as an array of Node | ||
nodes, /*Node*/stack) { | ||
nodes /*:: ?: Array<any/*Node*-/>*/, /*Node*/stack /*:: ?: any*/) { | ||
_classCallCheck(this, GraphQLError); | ||
@@ -33,0 +34,0 @@ |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -3,0 +3,0 @@ * Copyright (c) 2015, Facebook, Inc. |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -26,3 +26,3 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function locatedError(error, nodes) { | ||
function locatedError(error /*: ?Error*/, nodes /*: Array<any>*/) /*: GraphQLError*/ { | ||
var message = error ? error.message || String(error) : 'An unknown error occurred.'; | ||
@@ -29,0 +29,0 @@ var stack = error ? error.stack : null; |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -27,3 +27,4 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function syntaxError(source, position, description) { | ||
/*:: import type { Source } from '../language/source';*/ | ||
function syntaxError(source /*: Source*/, position /*: number*/, description /*: string*/) /*: GraphQLError*/ { | ||
var location = (0, _languageLocation.getLocation)(source, position); | ||
@@ -30,0 +31,0 @@ var error = new _GraphQLError.GraphQLError('Syntax Error ' + source.name + ' (' + location.line + ':' + location.column + ') ' + description + '\n\n' + highlightSourceAtLocation(source, location)); |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -11,11 +11,2 @@ * Copyright (c) 2015, Facebook, Inc. | ||
/** | ||
* This is the primary entry point function for fulfilling GraphQL operations | ||
* by parsing, validating, and executing a GraphQL document along side a | ||
* GraphQL schema. | ||
* | ||
* More sophisticated GraphQL servers, such as those which persist queries, | ||
* may wish to separate the validation and execution phases to a static time | ||
* tooling step, and a server runtime step. | ||
*/ | ||
'use strict'; | ||
@@ -30,9 +21,2 @@ | ||
/** | ||
* The result of a GraphQL parse, validation and execution. | ||
* | ||
* `data` is the result of a successful execution of the query. | ||
* `errors` is included when any errors occurred as a non-empty array. | ||
*/ | ||
var _languageSource = require('./language/source'); | ||
@@ -42,13 +26,25 @@ | ||
var _validator = require('./validator'); | ||
var _validationValidate = require('./validation/validate'); | ||
var _executorExecutor = require('./executor/executor'); | ||
var _executionExecute = require('./execution/execute'); | ||
var _error = require('./error'); | ||
function graphql(schema, requestString, rootValue, variableValues, operationName) { | ||
/*:: import type { GraphQLFormattedError } from './error/formatError';*/ | ||
/** | ||
* This is the primary entry point function for fulfilling GraphQL operations | ||
* by parsing, validating, and executing a GraphQL document along side a | ||
* GraphQL schema. | ||
* | ||
* More sophisticated GraphQL servers, such as those which persist queries, | ||
* may wish to separate the validation and execution phases to a static time | ||
* tooling step, and a server runtime step. | ||
*/ | ||
/*:: import type { GraphQLSchema } from './type/schema';*/ | ||
function graphql(schema /*: GraphQLSchema*/, requestString /*: string*/, rootValue /*:: ?: ?any*/, variableValues /*:: ?: ?{[key: string]: any}*/, operationName /*:: ?: ?string*/) /*: Promise<GraphQLResult>*/ { | ||
return new _Promise(function (resolve) { | ||
var source = new _languageSource.Source(requestString || '', 'GraphQL request'); | ||
var documentAST = (0, _languageParser.parse)(source); | ||
var validationErrors = (0, _validator.validateDocument)(schema, documentAST); | ||
var validationErrors = (0, _validationValidate.validate)(schema, documentAST); | ||
if (validationErrors.length > 0) { | ||
@@ -59,3 +55,3 @@ resolve({ | ||
} else { | ||
resolve((0, _executorExecutor.execute)(schema, documentAST, rootValue, variableValues, operationName).then(function (result) { | ||
resolve((0, _executionExecute.execute)(schema, documentAST, rootValue, variableValues, operationName).then(function (result) { | ||
if (result.errors) { | ||
@@ -73,2 +69,14 @@ return { | ||
}); | ||
} | ||
} | ||
/** | ||
* The result of a GraphQL parse, validation and execution. | ||
* | ||
* `data` is the result of a successful execution of the query. | ||
* `errors` is included when any errors occurred as a non-empty array. | ||
*/ | ||
/*:: type GraphQLResult = { | ||
data?: ?Object; | ||
errors?: Array<GraphQLFormattedError>; | ||
}*/ |
20
index.js
@@ -29,3 +29,3 @@ /** | ||
// Define Types. | ||
// Define GraphQL types. | ||
Object.defineProperty(exports, 'GraphQLSchema', { | ||
@@ -40,3 +40,3 @@ enumerable: true, | ||
// Use Pre-defined Scalar Types. | ||
// Use pre-defined GraphQL scalar types. | ||
Object.defineProperty(exports, 'GraphQLScalarType', { | ||
@@ -93,3 +93,2 @@ enumerable: true, | ||
// Produce and format errors. | ||
Object.defineProperty(exports, 'GraphQLInt', { | ||
@@ -124,17 +123,2 @@ enumerable: true, | ||
} | ||
}); | ||
var _error = require('./error'); | ||
Object.defineProperty(exports, 'GraphQLError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _error.GraphQLError; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'formatError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _error.formatError; | ||
} | ||
}); |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -11,2 +11,8 @@ * Copyright (c) 2015, Facebook, Inc. | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
/** | ||
@@ -16,3 +22,3 @@ * Contains a range of UTF-8 character offsets that identify | ||
*/ | ||
'use strict'; | ||
/*:: import type { Source } from './source';*/ | ||
@@ -22,17 +28,196 @@ /** | ||
*/ | ||
/*:: export type Location = { | ||
start: number; | ||
end: number; | ||
source?: ?Source | ||
}*/ | ||
// Name | ||
/*:: export type Node = Name | ||
| Document | ||
| OperationDefinition | ||
| VariableDefinition | ||
| Variable | ||
| SelectionSet | ||
| Field | ||
| Argument | ||
| FragmentSpread | ||
| InlineFragment | ||
| FragmentDefinition | ||
| IntValue | ||
| FloatValue | ||
| StringValue | ||
| BooleanValue | ||
| EnumValue | ||
| ListValue | ||
| ObjectValue | ||
| ObjectField | ||
| Directive | ||
| ListType | ||
| NonNullType*/ | ||
// Document | ||
/*:: export type Name = { | ||
kind: 'Name'; | ||
loc?: ?Location; | ||
value: string; | ||
}*/ | ||
/*:: export type Document = { | ||
kind: 'Document'; | ||
loc?: ?Location; | ||
definitions: Array<Definition>; | ||
}*/ | ||
/*:: export type Definition = OperationDefinition | ||
| FragmentDefinition*/ | ||
/*:: export type OperationDefinition = { | ||
kind: 'OperationDefinition'; | ||
loc?: ?Location; | ||
operation: 'query' | 'mutation'; | ||
name?: ?Name; | ||
variableDefinitions?: ?Array<VariableDefinition>; | ||
directives?: ?Array<Directive>; | ||
selectionSet: SelectionSet; | ||
}*/ | ||
/*:: export type VariableDefinition = { | ||
kind: 'VariableDefinition'; | ||
loc?: ?Location; | ||
variable: Variable; | ||
type: Type; | ||
defaultValue?: ?Value; | ||
}*/ | ||
/*:: export type Variable = { | ||
kind: 'Variable'; | ||
loc?: ?Location; | ||
name: Name; | ||
}*/ | ||
/*:: export type SelectionSet = { | ||
kind: 'SelectionSet'; | ||
loc?: ?Location; | ||
selections: Array<Selection>; | ||
}*/ | ||
/*:: export type Selection = Field | ||
| FragmentSpread | ||
| InlineFragment*/ | ||
/*:: export type Field = { | ||
kind: 'Field'; | ||
loc?: ?Location; | ||
alias?: ?Name; | ||
name: Name; | ||
arguments?: ?Array<Argument>; | ||
directives?: ?Array<Directive>; | ||
selectionSet?: ?SelectionSet; | ||
}*/ | ||
// Fragments | ||
/*:: export type Argument = { | ||
kind: 'Argument'; | ||
loc?: ?Location; | ||
name: Name; | ||
value: Value; | ||
}*/ | ||
/*:: export type FragmentSpread = { | ||
kind: 'FragmentSpread'; | ||
loc?: ?Location; | ||
name: Name; | ||
directives?: ?Array<Directive>; | ||
}*/ | ||
/*:: export type InlineFragment = { | ||
kind: 'InlineFragment'; | ||
loc?: ?Location; | ||
typeCondition: NamedType; | ||
directives?: ?Array<Directive>; | ||
selectionSet: SelectionSet; | ||
}*/ | ||
// Values | ||
/*:: export type FragmentDefinition = { | ||
kind: 'FragmentDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
typeCondition: NamedType; | ||
directives?: ?Array<Directive>; | ||
selectionSet: SelectionSet; | ||
}*/ | ||
/*:: export type Value = Variable | ||
| IntValue | ||
| FloatValue | ||
| StringValue | ||
| BooleanValue | ||
| EnumValue | ||
| ListValue | ||
| ObjectValue*/ | ||
/*:: export type IntValue = { | ||
kind: 'IntValue'; | ||
loc?: ?Location; | ||
value: string; | ||
}*/ | ||
/*:: export type FloatValue = { | ||
kind: 'FloatValue'; | ||
loc?: ?Location; | ||
value: string; | ||
}*/ | ||
/*:: export type StringValue = { | ||
kind: 'StringValue'; | ||
loc?: ?Location; | ||
value: string; | ||
}*/ | ||
/*:: export type BooleanValue = { | ||
kind: 'BooleanValue'; | ||
loc?: ?Location; | ||
value: boolean; | ||
}*/ | ||
/*:: export type EnumValue = { | ||
kind: 'EnumValue'; | ||
loc?: ?Location; | ||
value: string; | ||
}*/ | ||
/*:: export type ListValue = { | ||
kind: 'ListValue'; | ||
loc?: ?Location; | ||
values: Array<Value>; | ||
}*/ | ||
/*:: export type ObjectValue = { | ||
kind: 'ObjectValue'; | ||
loc?: ?Location; | ||
fields: Array<ObjectField>; | ||
}*/ | ||
// Directives | ||
/*:: export type ObjectField = { | ||
kind: 'ObjectField'; | ||
loc?: ?Location; | ||
name: Name; | ||
value: Value; | ||
}*/ | ||
// Types | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
/*:: export type Directive = { | ||
kind: 'Directive'; | ||
loc?: ?Location; | ||
name: Name; | ||
arguments?: ?Array<Argument>; | ||
}*/ | ||
/*:: export type Type = NamedType | ||
| ListType | ||
| NonNullType*/ | ||
/*:: export type NamedType = { | ||
kind: 'NamedType'; | ||
loc?: ?Location; | ||
name: Name; | ||
};*/ | ||
/*:: export type ListType = { | ||
kind: 'ListType'; | ||
loc?: ?Location; | ||
type: Type; | ||
}*/ | ||
/*:: export type NonNullType = { | ||
kind: 'NonNullType'; | ||
loc?: ?Location; | ||
type: NamedType | ListType; | ||
}*/ |
@@ -49,2 +49,8 @@ /** | ||
}); | ||
Object.defineProperty(exports, 'parseValue', { | ||
enumerable: true, | ||
get: function get() { | ||
return _parser.parseValue; | ||
} | ||
}); | ||
@@ -51,0 +57,0 @@ var _printer = require('./printer'); |
@@ -1,2 +0,2 @@ | ||
/* / | ||
/* @flow / | ||
/** | ||
@@ -13,6 +13,2 @@ * Copyright (c) 2015, Facebook, Inc. | ||
/** | ||
* A representation of a lexed Token. Value is optional, is it is | ||
* not needed for punctuators like BANG or PAREN_L. | ||
*/ | ||
Object.defineProperty(exports, '__esModule', { | ||
@@ -28,2 +24,15 @@ value: true | ||
/** | ||
* A representation of a lexed Token. Value is optional, is it is | ||
* not needed for punctuators like BANG or PAREN_L. | ||
*/ | ||
/*:: import type { Source } from './source';*/ | ||
/*:: export type Token = { | ||
kind: number; | ||
start: number; | ||
end: number; | ||
value: ?string; | ||
};*/ | ||
/** | ||
* Given a Source object, this returns a Lexer for that source. | ||
@@ -39,4 +48,4 @@ * A Lexer is a function that acts like a generator in that every time | ||
*/ | ||
function lex(source) { | ||
/*:: type Lexer = (resetPosition?: number) => Token;*/ | ||
function lex(source /*: Source*/) /*: Lexer*/ { | ||
var prevPosition = 0; | ||
@@ -80,3 +89,3 @@ return function nextToken(resetPosition) { | ||
function getTokenDesc(token) { | ||
function getTokenDesc(token /*: Token*/) /*: string*/ { | ||
return token.value ? getTokenKindDesc(token.kind) + ' "' + token.value + '"' : getTokenKindDesc(token.kind); | ||
@@ -89,3 +98,3 @@ } | ||
function getTokenKindDesc(kind) { | ||
function getTokenKindDesc(kind /*: number*/) /*: string*/ { | ||
return tokenDescription[kind]; | ||
@@ -122,3 +131,3 @@ } | ||
*/ | ||
function makeToken(kind, start, end, value) { | ||
function makeToken(kind /*: number*/, start /*: number*/, end /*: number*/, value /*:: ?: any*/) /*: Token*/ { | ||
return { kind: kind, start: start, end: end, value: value }; | ||
@@ -134,3 +143,3 @@ } | ||
*/ | ||
function readToken(source, fromPosition) { | ||
function readToken(source /*: Source*/, fromPosition /*: number*/) /*: Token*/ { | ||
var body = source.body; | ||
@@ -221,3 +230,3 @@ var bodyLength = body.length; | ||
*/ | ||
function positionAfterWhitespace(body, startPosition) { | ||
function positionAfterWhitespace(body /*: string*/, startPosition /*: number*/) /*: number*/ { | ||
var bodyLength = body.length; | ||
@@ -224,0 +233,0 @@ var position = startPosition; |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -11,5 +11,2 @@ * Copyright (c) 2015, Facebook, Inc. | ||
/** | ||
* Represents a location in a Source. | ||
*/ | ||
'use strict'; | ||
@@ -23,7 +20,15 @@ | ||
/** | ||
* Represents a location in a Source. | ||
*/ | ||
/*:: import type { Source } from './source';*/ | ||
/** | ||
* Takes a Source and a UTF-8 character offset, and returns the corresponding | ||
* line and column as a SourceLocation. | ||
*/ | ||
function getLocation(source, position) { | ||
/*:: type SourceLocation = { | ||
line: number; | ||
column: number; | ||
}*/ | ||
function getLocation(source /*: Source*/, position /*: number*/) /*: SourceLocation*/ { | ||
var line = 1; | ||
@@ -30,0 +35,0 @@ var column = position + 1; |
@@ -16,2 +16,3 @@ /** | ||
exports.parse = parse; | ||
exports.parseValue = parseValue; | ||
exports.parseName = parseName; | ||
@@ -37,3 +38,29 @@ exports.parseConstValue = parseConstValue; | ||
function parse(source, options) { | ||
/*:: import type { | ||
Name, | ||
Variable, | ||
Document, | ||
OperationDefinition, | ||
VariableDefinition, | ||
SelectionSet, | ||
Selection, | ||
Field, | ||
Argument, | ||
FragmentSpread, | ||
InlineFragment, | ||
FragmentDefinition, | ||
Value, | ||
ListValue, | ||
ObjectValue, | ||
ObjectField, | ||
Directive, | ||
Type, | ||
NamedType, | ||
} from './ast';*/ | ||
function parse(source /*: Source | string*/, options /*:: ?: ParseOptions*/) /*: Document*/ { | ||
var sourceObj = source instanceof _source.Source ? source : new _source.Source(source); | ||
@@ -45,6 +72,20 @@ var parser = (0, _parserCore.makeParser)(sourceObj, options || {}); | ||
/** | ||
* Given a string containing a GraphQL value, parse the AST for that value. | ||
* Throws GraphQLError if a syntax error is encountered. | ||
* | ||
* This is useful within tools that operate upon GraphQL Values directly and | ||
* in isolation of complete GraphQL documents. | ||
*/ | ||
function parseValue(source /*: Source | string*/, options /*:: ?: ParseOptions*/) /*: Value*/ { | ||
var sourceObj = source instanceof _source.Source ? source : new _source.Source(source); | ||
var parser = (0, _parserCore.makeParser)(sourceObj, options || {}); | ||
return parseValueLiteral(parser); | ||
} | ||
/** | ||
* Converts a name lex token into a name parse node. | ||
*/ | ||
function parseName(parser) { | ||
function parseName(parser) /*: Name*/ { | ||
var token = (0, _parserCore.expect)(parser, _lexer.TokenKind.NAME); | ||
@@ -60,3 +101,3 @@ return { | ||
function parseDocument(parser) { | ||
function parseDocument(parser) /*: Document*/ { | ||
var start = parser.token.start; | ||
@@ -88,3 +129,3 @@ var definitions = []; | ||
function parseOperationDefinition(parser) { | ||
function parseOperationDefinition(parser) /*: OperationDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -115,7 +156,7 @@ if ((0, _parserCore.peek)(parser, _lexer.TokenKind.BRACE_L)) { | ||
function parseVariableDefinitions(parser) { | ||
function parseVariableDefinitions(parser) /*: Array<VariableDefinition>*/ { | ||
return (0, _parserCore.peek)(parser, _lexer.TokenKind.PAREN_L) ? (0, _parserCore.many)(parser, _lexer.TokenKind.PAREN_L, parseVariableDefinition, _lexer.TokenKind.PAREN_R) : []; | ||
} | ||
function parseVariableDefinition(parser) { | ||
function parseVariableDefinition(parser) /*: VariableDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -126,3 +167,3 @@ return { | ||
type: ((0, _parserCore.expect)(parser, _lexer.TokenKind.COLON), parseType(parser)), | ||
defaultValue: (0, _parserCore.skip)(parser, _lexer.TokenKind.EQUALS) ? parseValue(parser, true) : null, | ||
defaultValue: (0, _parserCore.skip)(parser, _lexer.TokenKind.EQUALS) ? parseValueLiteral(parser, true) : null, | ||
loc: (0, _parserCore.loc)(parser, start) | ||
@@ -132,3 +173,3 @@ }; | ||
function parseVariable(parser) { | ||
function parseVariable(parser) /*: Variable*/ { | ||
var start = parser.token.start; | ||
@@ -143,3 +184,3 @@ (0, _parserCore.expect)(parser, _lexer.TokenKind.DOLLAR); | ||
function parseSelectionSet(parser) { | ||
function parseSelectionSet(parser) /*: SelectionSet*/ { | ||
var start = parser.token.start; | ||
@@ -153,3 +194,3 @@ return { | ||
function parseSelection(parser) { | ||
function parseSelection(parser) /*: Selection*/ { | ||
return (0, _parserCore.peek)(parser, _lexer.TokenKind.SPREAD) ? parseFragment(parser) : parseField(parser); | ||
@@ -161,3 +202,3 @@ } | ||
*/ | ||
function parseField(parser) { | ||
function parseField(parser) /*: Field*/ { | ||
var start = parser.token.start; | ||
@@ -187,7 +228,7 @@ | ||
function parseArguments(parser) { | ||
function parseArguments(parser) /*: Array<Argument>*/ { | ||
return (0, _parserCore.peek)(parser, _lexer.TokenKind.PAREN_L) ? (0, _parserCore.many)(parser, _lexer.TokenKind.PAREN_L, parseArgument, _lexer.TokenKind.PAREN_R) : []; | ||
} | ||
function parseArgument(parser) { | ||
function parseArgument(parser) /*: Argument*/ { | ||
var start = parser.token.start; | ||
@@ -197,3 +238,3 @@ return { | ||
name: parseName(parser), | ||
value: ((0, _parserCore.expect)(parser, _lexer.TokenKind.COLON), parseValue(parser, false)), | ||
value: ((0, _parserCore.expect)(parser, _lexer.TokenKind.COLON), parseValueLiteral(parser, false)), | ||
loc: (0, _parserCore.loc)(parser, start) | ||
@@ -208,3 +249,3 @@ }; | ||
*/ | ||
function parseFragment(parser) { | ||
function parseFragment(parser) /*: FragmentSpread | InlineFragment*/ { | ||
var start = parser.token.start; | ||
@@ -230,3 +271,3 @@ (0, _parserCore.expect)(parser, _lexer.TokenKind.SPREAD); | ||
function parseFragmentName(parser) { | ||
function parseFragmentName(parser) /*: Name*/ { | ||
if (parser.token.value === 'on') { | ||
@@ -238,3 +279,3 @@ throw (0, _parserCore.unexpected)(parser); | ||
function parseFragmentDefinition(parser) { | ||
function parseFragmentDefinition(parser) /*: FragmentDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -254,11 +295,11 @@ (0, _parserCore.expectKeyword)(parser, 'fragment'); | ||
function parseVariableValue(parser) { | ||
return parseValue(parser, false); | ||
function parseConstValue(parser) /*: Value*/ { | ||
return parseValueLiteral(parser, true); | ||
} | ||
function parseConstValue(parser) { | ||
return parseValue(parser, true); | ||
function parseVariableValue(parser) /*: Value*/ { | ||
return parseValueLiteral(parser, false); | ||
} | ||
function parseValue(parser, isConst) { | ||
function parseValueLiteral(parser, isConst /*: boolean*/) /*: Value*/ { | ||
var token = parser.token; | ||
@@ -317,3 +358,3 @@ switch (token.kind) { | ||
function parseList(parser, isConst) { | ||
function parseList(parser, isConst /*: boolean*/) /*: ListValue*/ { | ||
var start = parser.token.start; | ||
@@ -328,3 +369,3 @@ var item = isConst ? parseConstValue : parseVariableValue; | ||
function parseObject(parser, isConst) { | ||
function parseObject(parser, isConst /*: boolean*/) /*: ObjectValue*/ { | ||
var start = parser.token.start; | ||
@@ -344,3 +385,3 @@ (0, _parserCore.expect)(parser, _lexer.TokenKind.BRACE_L); | ||
function parseObjectField(parser, isConst, fieldNames) { | ||
function parseObjectField(parser, isConst /*: boolean*/, fieldNames /*: {[name: string]: boolean}*/) /*: ObjectField*/ { | ||
var start = parser.token.start; | ||
@@ -355,3 +396,3 @@ var name = parseName(parser); | ||
name: name, | ||
value: ((0, _parserCore.expect)(parser, _lexer.TokenKind.COLON), parseValue(parser, isConst)), | ||
value: ((0, _parserCore.expect)(parser, _lexer.TokenKind.COLON), parseValueLiteral(parser, isConst)), | ||
loc: (0, _parserCore.loc)(parser, start) | ||
@@ -363,3 +404,3 @@ }; | ||
function parseDirectives(parser) { | ||
function parseDirectives(parser) /*: Array<Directive>*/ { | ||
var directives = []; | ||
@@ -372,3 +413,3 @@ while ((0, _parserCore.peek)(parser, _lexer.TokenKind.AT)) { | ||
function parseDirective(parser) { | ||
function parseDirective(parser) /*: Directive*/ { | ||
var start = parser.token.start; | ||
@@ -390,3 +431,3 @@ (0, _parserCore.expect)(parser, _lexer.TokenKind.AT); | ||
function parseType(parser) { | ||
function parseType(parser) /*: Type*/ { | ||
var start = parser.token.start; | ||
@@ -415,3 +456,3 @@ var type; | ||
function parseNamedType(parser) { | ||
function parseNamedType(parser) /*: NamedType*/ { | ||
var start = parser.token.start; | ||
@@ -418,0 +459,0 @@ return { |
@@ -10,6 +10,2 @@ /** | ||
/** | ||
* Returns the parser object that is used to store state throughout the | ||
* process of parsing. | ||
*/ | ||
'use strict'; | ||
@@ -21,6 +17,2 @@ | ||
exports.makeParser = makeParser; | ||
/** | ||
* Configuration options to control parser behavior | ||
*/ | ||
exports.loc = loc; | ||
@@ -42,3 +34,8 @@ exports.advance = advance; | ||
function makeParser(source, options) { | ||
/** | ||
* Returns the parser object that is used to store state throughout the | ||
* process of parsing. | ||
*/ | ||
/*:: import type { Token } from './lexer';*/ | ||
function makeParser(source /*: Source*/, options /*: ParseOptions*/) { | ||
var _lexToken = (0, _lexer.lex)(source); | ||
@@ -55,7 +52,25 @@ return { | ||
/** | ||
* Configuration options to control parser behavior | ||
*/ | ||
/** | ||
* Returns a location object, used to identify the place in | ||
* the source that created a given parsed object. | ||
*/ | ||
/*:: export type ParseOptions = { | ||
/** | ||
* By default, the parser creates AST nodes that know the location | ||
* in the source that they correspond to. This configuration flag | ||
* disables that behavior for performance or testing. | ||
*-/ | ||
noLocation?: boolean, | ||
function loc(parser, start) { | ||
/** | ||
* By default, the parser creates AST nodes that contain a reference | ||
* to the source that they were created from. This configuration flag | ||
* disables that behavior for performance or testing. | ||
*-/ | ||
noSource?: boolean, | ||
}*/ | ||
function loc(parser, start /*: number*/) { | ||
if (parser.options.noLocation) { | ||
@@ -81,3 +96,3 @@ return null; | ||
function advance(parser) { | ||
function advance(parser) /*: void*/ { | ||
var prevEnd = parser.token.end; | ||
@@ -92,3 +107,3 @@ parser.prevEnd = prevEnd; | ||
function peek(parser, kind) { | ||
function peek(parser, kind /*: string*/) /*: boolean*/ { | ||
return parser.token.kind === kind; | ||
@@ -102,3 +117,3 @@ } | ||
function skip(parser, kind) { | ||
function skip(parser, kind /*: string*/) /*: boolean*/ { | ||
var match = parser.token.kind === kind; | ||
@@ -116,3 +131,3 @@ if (match) { | ||
function expect(parser, kind) { | ||
function expect(parser, kind /*: string*/) /*: Token*/ { | ||
var token = parser.token; | ||
@@ -132,3 +147,3 @@ if (token.kind === kind) { | ||
function expectKeyword(parser, value) { | ||
function expectKeyword(parser, value /*: string*/) /*: Token*/ { | ||
var token = parser.token; | ||
@@ -147,3 +162,3 @@ if (token.kind === _lexer.TokenKind.NAME && token.value === value) { | ||
function unexpected(parser, atToken) { | ||
function unexpected(parser, atToken /*:: ?: ?Token*/) /*: Error*/ { | ||
var token = atToken || parser.token; | ||
@@ -160,3 +175,3 @@ return (0, _error.syntaxError)(parser.source, token.start, 'Unexpected ' + (0, _lexer.getTokenDesc)(token)); | ||
function any(parser, openKind, parseFn, closeKind) { | ||
function any /*:: <T>*/(parser, openKind /*: number*/, parseFn /*: (parser: any) => T*/, closeKind /*: number*/) /*: Array<T>*/ { | ||
expect(parser, openKind); | ||
@@ -177,3 +192,3 @@ var nodes = []; | ||
function many(parser, openKind, parseFn, closeKind) { | ||
function many /*:: <T>*/(parser, openKind /*: number*/, parseFn /*: (parser: any) => T*/, closeKind /*: number*/) /*: Array<T>*/ { | ||
expect(parser, openKind); | ||
@@ -180,0 +195,0 @@ var nodes = [parseFn(parser)]; |
@@ -16,2 +16,5 @@ /** | ||
exports.print = print; | ||
exports.join = join; | ||
exports.block = block; | ||
exports.wrap = wrap; | ||
@@ -26,97 +29,168 @@ var _visitor = require('./visitor'); | ||
function print(ast) { | ||
return (0, _visitor.visit)(ast, { | ||
leave: { | ||
Name: function Name(node) { | ||
return node.value; | ||
}, | ||
Variable: function Variable(node) { | ||
return '$' + node.name; | ||
}, | ||
return (0, _visitor.visit)(ast, { leave: printDocASTReducer }); | ||
} | ||
// Document | ||
var printDocASTReducer = { | ||
Name: function Name(node) { | ||
return node.value; | ||
}, | ||
Variable: function Variable(node) { | ||
return '$' + node.name; | ||
}, | ||
Document: function Document(node) { | ||
return join(node.definitions, '\n\n') + '\n'; | ||
}, | ||
OperationDefinition: function OperationDefinition(node) { | ||
var op = node.operation; | ||
var name = node.name; | ||
var defs = manyList('(', node.variableDefinitions, ', ', ')'); | ||
var directives = join(node.directives, ' '); | ||
var selectionSet = node.selectionSet; | ||
return !name ? selectionSet : join([op, join([name, defs]), directives, selectionSet], ' '); | ||
}, | ||
VariableDefinition: function VariableDefinition(node) { | ||
return join([node.variable + ': ' + node.type, node.defaultValue], ' = '); | ||
}, | ||
SelectionSet: function SelectionSet(node) { | ||
return length(node.selections) === 0 ? null : indent('{\n' + join(node.selections, '\n')) + '\n}'; | ||
}, | ||
Field: function Field(node) { | ||
return join([join([join([node.alias, node.name], ': '), manyList('(', node.arguments, ', ', ')')]), join(node.directives, ' '), node.selectionSet], ' '); | ||
}, | ||
Argument: function Argument(node) { | ||
return node.name + ': ' + node.value; | ||
}, | ||
// Document | ||
// Fragments | ||
Document: function Document(node) { | ||
return join(node.definitions, '\n\n') + '\n'; | ||
}, | ||
FragmentSpread: function FragmentSpread(node) { | ||
return join(['...' + node.name, join(node.directives, ' ')], ' '); | ||
}, | ||
InlineFragment: function InlineFragment(node) { | ||
return join(['... on', node.typeCondition, join(node.directives, ' '), node.selectionSet], ' '); | ||
}, | ||
FragmentDefinition: function FragmentDefinition(node) { | ||
return join(['fragment', node.name, 'on', node.typeCondition, join(node.directives, ' '), node.selectionSet], ' '); | ||
}, | ||
OperationDefinition: function OperationDefinition(node) { | ||
var op = node.operation; | ||
var name = node.name; | ||
var defs = wrap('(', join(node.variableDefinitions, ', '), ')'); | ||
var directives = join(node.directives, ' '); | ||
var selectionSet = node.selectionSet; | ||
return !name ? selectionSet : join([op, join([name, defs]), directives, selectionSet], ' '); | ||
}, | ||
// Value | ||
VariableDefinition: function VariableDefinition(_ref) { | ||
var variable = _ref.variable; | ||
var type = _ref.type; | ||
var defaultValue = _ref.defaultValue; | ||
return variable + ': ' + type + wrap(' = ', defaultValue); | ||
}, | ||
IntValue: function IntValue(node) { | ||
return node.value; | ||
}, | ||
FloatValue: function FloatValue(node) { | ||
return node.value; | ||
}, | ||
StringValue: function StringValue(node) { | ||
return JSON.stringify(node.value); | ||
}, | ||
BooleanValue: function BooleanValue(node) { | ||
return node.value ? 'true' : 'false'; | ||
}, | ||
EnumValue: function EnumValue(node) { | ||
return node.value; | ||
}, | ||
ListValue: function ListValue(node) { | ||
return '[' + join(node.values, ', ') + ']'; | ||
}, | ||
ObjectValue: function ObjectValue(node) { | ||
return '{' + join(node.fields, ', ') + '}'; | ||
}, | ||
ObjectField: function ObjectField(node) { | ||
return node.name + ': ' + node.value; | ||
}, | ||
SelectionSet: function SelectionSet(_ref2) { | ||
var selections = _ref2.selections; | ||
return block(selections); | ||
}, | ||
// Directive | ||
Field: function Field(_ref3) { | ||
var alias = _ref3.alias; | ||
var name = _ref3.name; | ||
var args = _ref3.arguments; | ||
var directives = _ref3.directives; | ||
var selectionSet = _ref3.selectionSet; | ||
return join([wrap('', alias, ': ') + name + wrap('(', join(args, ', '), ')'), join(directives, ' '), selectionSet], ' '); | ||
}, | ||
Directive: function Directive(node) { | ||
return join(['@' + node.name, manyList('(', node.arguments, ', ', ')')]); | ||
}, | ||
Argument: function Argument(_ref4) { | ||
var name = _ref4.name; | ||
var value = _ref4.value; | ||
return name + ': ' + value; | ||
}, | ||
// Type | ||
// Fragments | ||
NamedType: function NamedType(node) { | ||
return node.name; | ||
}, | ||
ListType: function ListType(node) { | ||
return '[' + node.type + ']'; | ||
}, | ||
NonNullType: function NonNullType(node) { | ||
return node.type + '!'; | ||
} | ||
} | ||
}); | ||
FragmentSpread: function FragmentSpread(_ref5) { | ||
var name = _ref5.name; | ||
var directives = _ref5.directives; | ||
return '...' + name + wrap(' ', join(directives, ' ')); | ||
}, | ||
InlineFragment: function InlineFragment(_ref6) { | ||
var typeCondition = _ref6.typeCondition; | ||
var directives = _ref6.directives; | ||
var selectionSet = _ref6.selectionSet; | ||
return '... on ' + typeCondition + ' ' + wrap('', join(directives, ' '), ' ') + selectionSet; | ||
}, | ||
FragmentDefinition: function FragmentDefinition(_ref7) { | ||
var name = _ref7.name; | ||
var typeCondition = _ref7.typeCondition; | ||
var directives = _ref7.directives; | ||
var selectionSet = _ref7.selectionSet; | ||
return 'fragment ' + name + ' on ' + typeCondition + ' ' + wrap('', join(directives, ' '), ' ') + selectionSet; | ||
}, | ||
// Value | ||
IntValue: function IntValue(_ref8) { | ||
var value = _ref8.value; | ||
return value; | ||
}, | ||
FloatValue: function FloatValue(_ref9) { | ||
var value = _ref9.value; | ||
return value; | ||
}, | ||
StringValue: function StringValue(_ref10) { | ||
var value = _ref10.value; | ||
return JSON.stringify(value); | ||
}, | ||
BooleanValue: function BooleanValue(_ref11) { | ||
var value = _ref11.value; | ||
return JSON.stringify(value); | ||
}, | ||
EnumValue: function EnumValue(_ref12) { | ||
var value = _ref12.value; | ||
return value; | ||
}, | ||
ListValue: function ListValue(_ref13) { | ||
var values = _ref13.values; | ||
return '[' + join(values, ', ') + ']'; | ||
}, | ||
ObjectValue: function ObjectValue(_ref14) { | ||
var fields = _ref14.fields; | ||
return '{' + join(fields, ', ') + '}'; | ||
}, | ||
ObjectField: function ObjectField(_ref15) { | ||
var name = _ref15.name; | ||
var value = _ref15.value; | ||
return name + ': ' + value; | ||
}, | ||
// Directive | ||
Directive: function Directive(_ref16) { | ||
var name = _ref16.name; | ||
var args = _ref16.arguments; | ||
return '@' + name + wrap('(', join(args, ', '), ')'); | ||
}, | ||
// Type | ||
NamedType: function NamedType(_ref17) { | ||
var name = _ref17.name; | ||
return name; | ||
}, | ||
ListType: function ListType(_ref18) { | ||
var type = _ref18.type; | ||
return '[' + type + ']'; | ||
}, | ||
NonNullType: function NonNullType(_ref19) { | ||
var type = _ref19.type; | ||
return type + '!'; | ||
} | ||
}; | ||
/** | ||
* Given maybeArray, print an empty string if it is null or empty, otherwise | ||
* print all items together separated by separator if provided | ||
*/ | ||
exports.printDocASTReducer = printDocASTReducer; | ||
function join(maybeArray, separator) { | ||
return maybeArray ? maybeArray.filter(function (x) { | ||
return !!x; | ||
}).join(separator || '') : ''; | ||
} | ||
/** | ||
* Given maybeArray, print an empty string if it is null or empty, otherwise | ||
* print each item on it's own line, wrapped in an indented "{ }" block. | ||
*/ | ||
function block(maybeArray) { | ||
return length(maybeArray) ? indent('{\n' + join(maybeArray, '\n')) + '\n}' : ''; | ||
} | ||
/** | ||
* If maybeString is not null or empty, then wrap with start and end, otherwise | ||
* print an empty string. | ||
*/ | ||
function wrap(start, maybeString, end) { | ||
return maybeString ? start + maybeString + (end || '') : ''; | ||
} | ||
function indent(maybeString) { | ||
@@ -126,14 +200,4 @@ return maybeString && maybeString.replace(/\n/g, '\n '); | ||
function manyList(start, list, separator, end) { | ||
return length(list) === 0 ? null : start + join(list, separator) + end; | ||
} | ||
function length(maybeArray) { | ||
return maybeArray ? maybeArray.length : 0; | ||
} | ||
function join(maybeArray, separator) { | ||
return maybeArray ? maybeArray.filter(function (x) { | ||
return !!x; | ||
}).join(separator || '') : ''; | ||
} |
@@ -1,2 +0,2 @@ | ||
/*@flow*/ | ||
/** | ||
@@ -15,2 +15,77 @@ * Copyright (c) 2015, Facebook, Inc. | ||
value: true | ||
}); | ||
}); | ||
/*:: import type { | ||
Location, | ||
Name, | ||
Value, | ||
Type, | ||
NamedType | ||
} from '../ast';*/ | ||
/*:: export type SchemaDocument = { | ||
kind: 'SchemaDocument'; | ||
loc?: ?Location; | ||
definitions: Array<SchemaDefinition>; | ||
}*/ | ||
/*:: export type SchemaDefinition = | ||
TypeDefinition | | ||
InterfaceDefinition | | ||
UnionDefinition | | ||
ScalarDefinition | | ||
EnumDefinition | | ||
InputObjectDefinition*/ | ||
/*:: export type TypeDefinition = { | ||
kind: 'TypeDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
interfaces?: ?Array<NamedType>; | ||
fields: Array<FieldDefinition>; | ||
}*/ | ||
/*:: export type FieldDefinition = { | ||
kind: 'FieldDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
arguments: Array<InputValueDefinition>; | ||
type: Type; | ||
}*/ | ||
/*:: export type InputValueDefinition = { | ||
kind: 'InputValueDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
type: Type; | ||
defaultValue?: ?Value; | ||
}*/ | ||
/*:: export type InterfaceDefinition = { | ||
kind: 'InterfaceDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
fields: Array<FieldDefinition>; | ||
}*/ | ||
/*:: export type UnionDefinition = { | ||
kind: 'UnionDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
types: Array<NamedType>; | ||
}*/ | ||
/*:: export type ScalarDefinition = { | ||
kind: 'ScalarDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
}*/ | ||
/*:: export type EnumDefinition = { | ||
kind: 'EnumDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
values: Array<EnumValueDefinition>; | ||
}*/ | ||
/*:: export type EnumValueDefinition = { | ||
kind: 'EnumValueDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
}*/ | ||
/*:: export type InputObjectDefinition = { | ||
kind: 'InputObjectDefinition'; | ||
loc?: ?Location; | ||
name: Name; | ||
fields: Array<InputValueDefinition>; | ||
}*/ |
@@ -23,4 +23,4 @@ /** | ||
exports.FIELD_DEFINITION = FIELD_DEFINITION; | ||
var ARGUMENT_DEFINITION = 'ArgumentDefinition'; | ||
exports.ARGUMENT_DEFINITION = ARGUMENT_DEFINITION; | ||
var INPUT_VALUE_DEFINITION = 'InputValueDefinition'; | ||
exports.INPUT_VALUE_DEFINITION = INPUT_VALUE_DEFINITION; | ||
var INTERFACE_DEFINITION = 'InterfaceDefinition'; | ||
@@ -37,4 +37,2 @@ exports.INTERFACE_DEFINITION = INTERFACE_DEFINITION; | ||
var INPUT_OBJECT_DEFINITION = 'InputObjectDefinition'; | ||
exports.INPUT_OBJECT_DEFINITION = INPUT_OBJECT_DEFINITION; | ||
var INPUT_FIELD_DEFINITION = 'InputFieldDefinition'; | ||
exports.INPUT_FIELD_DEFINITION = INPUT_FIELD_DEFINITION; | ||
exports.INPUT_OBJECT_DEFINITION = INPUT_OBJECT_DEFINITION; |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -16,3 +16,3 @@ * Copyright (c) 2015, Facebook, Inc. | ||
}); | ||
exports.parseSchema = parseSchema; | ||
exports.parseSchemaIntoAST = parseSchemaIntoAST; | ||
@@ -29,3 +29,17 @@ var _source = require('../source'); | ||
function parseSchema(source, options) { | ||
/*:: import type { NamedType } from '../ast';*/ | ||
/*:: import type { | ||
SchemaDocument, | ||
SchemaDefinition, | ||
TypeDefinition, | ||
FieldDefinition, | ||
InputValueDefinition, | ||
EnumDefinition, | ||
EnumValueDefinition, | ||
InterfaceDefinition, | ||
UnionDefinition, | ||
InputObjectDefinition, | ||
ScalarDefinition, | ||
} from './ast';*/ | ||
function parseSchemaIntoAST(source /*: Source | string*/, options /*:: ?: ParseOptions*/) /*: SchemaDocument*/ { | ||
var sourceObj = source instanceof _source.Source ? source : new _source.Source(source); | ||
@@ -39,3 +53,3 @@ var parser = (0, _parserCore.makeParser)(sourceObj, options || {}); | ||
*/ | ||
function parseSchemaDocument(parser) { | ||
function parseSchemaDocument(parser) /*: SchemaDocument*/ { | ||
var start = parser.token.start; | ||
@@ -63,3 +77,3 @@ var definitions = []; | ||
*/ | ||
function parseSchemaDefinition(parser) { | ||
function parseSchemaDefinition(parser) /*: SchemaDefinition*/ { | ||
if (!(0, _parserCore.peek)(parser, _lexer.TokenKind.NAME)) { | ||
@@ -91,3 +105,3 @@ throw (0, _parserCore.unexpected)(parser); | ||
*/ | ||
function parseTypeDefinition(parser) { | ||
function parseTypeDefinition(parser) /*: TypeDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -110,3 +124,3 @@ (0, _parserCore.expectKeyword)(parser, 'type'); | ||
*/ | ||
function parseImplementsInterfaces(parser) { | ||
function parseImplementsInterfaces(parser) /*: Array<NamedType>*/ { | ||
var types = []; | ||
@@ -127,3 +141,3 @@ if (parser.token.value === 'implements') { | ||
*/ | ||
function parseFieldDefinition(parser) { | ||
function parseFieldDefinition(parser) /*: FieldDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -144,19 +158,17 @@ var name = (0, _parser.parseName)(parser); | ||
/** | ||
* ArgumentsDefinition : ( ArgumentDefinition+ ) | ||
* ArgumentsDefinition : ( InputValueDefinition+ ) | ||
*/ | ||
function parseArgumentDefs(parser) { | ||
function parseArgumentDefs(parser) /*: Array<InputValueDefinition>*/ { | ||
if (!(0, _parserCore.peek)(parser, _lexer.TokenKind.PAREN_L)) { | ||
return []; | ||
} | ||
return (0, _parserCore.many)(parser, _lexer.TokenKind.PAREN_L, parseArgumentDef, _lexer.TokenKind.PAREN_R); | ||
return (0, _parserCore.many)(parser, _lexer.TokenKind.PAREN_L, parseInputValueDef, _lexer.TokenKind.PAREN_R); | ||
} | ||
/** | ||
* ArgumentDefinition : ArgumentName : Value[Const] DefaultValue? | ||
* InputValueDefinition : Name : Value[Const] DefaultValue? | ||
* | ||
* ArgumentName : Name | ||
* | ||
* DefaultValue : = Value[Const] | ||
*/ | ||
function parseArgumentDef(parser) { | ||
function parseInputValueDef(parser) /*: InputValueDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -171,3 +183,3 @@ var name = (0, _parser.parseName)(parser); | ||
return { | ||
kind: _kinds.ARGUMENT_DEFINITION, | ||
kind: _kinds.INPUT_VALUE_DEFINITION, | ||
name: name, | ||
@@ -183,3 +195,3 @@ type: type, | ||
*/ | ||
function parseInterfaceDefinition(parser) { | ||
function parseInterfaceDefinition(parser) /*: InterfaceDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -200,3 +212,3 @@ (0, _parserCore.expectKeyword)(parser, 'interface'); | ||
*/ | ||
function parseUnionDefinition(parser) { | ||
function parseUnionDefinition(parser) /*: UnionDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -220,3 +232,3 @@ (0, _parserCore.expectKeyword)(parser, 'union'); | ||
*/ | ||
function parseUnionMembers(parser) { | ||
function parseUnionMembers(parser) /*: Array<NamedType>*/ { | ||
var members = []; | ||
@@ -232,3 +244,3 @@ do { | ||
*/ | ||
function parseScalarDefinition(parser) { | ||
function parseScalarDefinition(parser) /*: ScalarDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -247,3 +259,3 @@ (0, _parserCore.expectKeyword)(parser, 'scalar'); | ||
*/ | ||
function parseEnumDefinition(parser) { | ||
function parseEnumDefinition(parser) /*: EnumDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -266,3 +278,3 @@ (0, _parserCore.expectKeyword)(parser, 'enum'); | ||
*/ | ||
function parseEnumValueDefinition(parser) { | ||
function parseEnumValueDefinition(parser) /*: EnumValueDefinition*/ { | ||
var start = parser.token.start; | ||
@@ -278,9 +290,9 @@ var name = (0, _parser.parseName)(parser); | ||
/** | ||
* InputObjectDefinition : `input` TypeName { InputFieldDefinition+ } | ||
* InputObjectDefinition : `input` TypeName { InputValueDefinition+ } | ||
*/ | ||
function parseInputObjectDefinition(parser) { | ||
function parseInputObjectDefinition(parser) /*: InputObjectDefinition*/ { | ||
var start = parser.token.start; | ||
(0, _parserCore.expectKeyword)(parser, 'input'); | ||
var name = (0, _parser.parseName)(parser); | ||
var fields = (0, _parserCore.any)(parser, _lexer.TokenKind.BRACE_L, parseInputFieldDefinition, _lexer.TokenKind.BRACE_R); | ||
var fields = (0, _parserCore.any)(parser, _lexer.TokenKind.BRACE_L, parseInputValueDef, _lexer.TokenKind.BRACE_R); | ||
return { | ||
@@ -292,18 +304,2 @@ kind: _kinds.INPUT_OBJECT_DEFINITION, | ||
}; | ||
} | ||
/** | ||
* InputFieldDefinition : FieldName : Type | ||
*/ | ||
function parseInputFieldDefinition(parser) { | ||
var start = parser.token.start; | ||
var name = (0, _parser.parseName)(parser); | ||
(0, _parserCore.expect)(parser, _lexer.TokenKind.COLON); | ||
var type = (0, _parser.parseType)(parser); | ||
return { | ||
kind: _kinds.INPUT_FIELD_DEFINITION, | ||
name: name, | ||
type: type, | ||
loc: (0, _parserCore.loc)(parser, start) | ||
}; | ||
} |
@@ -12,35 +12,97 @@ /** | ||
var _regeneratorRuntime = require('babel-runtime/regenerator')['default']; | ||
Object.defineProperty(exports, '__esModule', { | ||
value: true | ||
}); | ||
exports.getIntrospectionResult = getIntrospectionResult; | ||
exports.printSchema = printSchema; | ||
var _parser = require('./parser'); | ||
var _visitor = require('./visitor'); | ||
var _materializer = require('./materializer'); | ||
var _printer = require('../printer'); | ||
var _typeIntrospectionQuery = require('./../../type/introspectionQuery'); | ||
/** | ||
* Converts a Schema AST into a string, using one set of reasonable | ||
* formatting rules. | ||
*/ | ||
var _ = require('../../'); | ||
function printSchema(ast) { | ||
return (0, _visitor.visitSchema)(ast, { leave: printSchemaASTReducer }); | ||
} | ||
function getIntrospectionResult(body, queryType) { | ||
var doc, schema; | ||
return _regeneratorRuntime.async(function getIntrospectionResult$(context$1$0) { | ||
while (1) switch (context$1$0.prev = context$1$0.next) { | ||
case 0: | ||
doc = (0, _parser.parseSchema)(body); | ||
schema = (0, _materializer.materializeSchema)(doc, queryType); | ||
context$1$0.next = 4; | ||
return _regeneratorRuntime.awrap((0, _.graphql)(schema, _typeIntrospectionQuery.introspectionQuery)); | ||
var printSchemaASTReducer = { | ||
Name: _printer.printDocASTReducer.Name, | ||
case 4: | ||
return context$1$0.abrupt('return', context$1$0.sent); | ||
// Document | ||
case 5: | ||
case 'end': | ||
return context$1$0.stop(); | ||
} | ||
}, null, this); | ||
} | ||
SchemaDocument: function SchemaDocument(_ref) { | ||
var definitions = _ref.definitions; | ||
return (0, _printer.join)(definitions, '\n\n') + '\n'; | ||
}, | ||
TypeDefinition: function TypeDefinition(_ref2) { | ||
var name = _ref2.name; | ||
var interfaces = _ref2.interfaces; | ||
var fields = _ref2.fields; | ||
return 'type ' + name + ' ' + (0, _printer.wrap)('implements ', (0, _printer.join)(interfaces, ', '), ' ') + (0, _printer.block)(fields); | ||
}, | ||
FieldDefinition: function FieldDefinition(_ref3) { | ||
var name = _ref3.name; | ||
var args = _ref3.arguments; | ||
var type = _ref3.type; | ||
return name + (0, _printer.wrap)('(', (0, _printer.join)(args, ', '), ')') + ': ' + type; | ||
}, | ||
InputValueDefinition: function InputValueDefinition(_ref4) { | ||
var name = _ref4.name; | ||
var type = _ref4.type; | ||
var defaultValue = _ref4.defaultValue; | ||
return name + ': ' + type + (0, _printer.wrap)(' = ', defaultValue); | ||
}, | ||
InterfaceDefinition: function InterfaceDefinition(_ref5) { | ||
var name = _ref5.name; | ||
var fields = _ref5.fields; | ||
return 'interface ' + name + ' ' + (0, _printer.block)(fields); | ||
}, | ||
UnionDefinition: function UnionDefinition(_ref6) { | ||
var name = _ref6.name; | ||
var types = _ref6.types; | ||
return 'union ' + name + ' = ' + (0, _printer.join)(types, ' | '); | ||
}, | ||
ScalarDefinition: function ScalarDefinition(_ref7) { | ||
var name = _ref7.name; | ||
return 'scalar ' + name; | ||
}, | ||
EnumDefinition: function EnumDefinition(_ref8) { | ||
var name = _ref8.name; | ||
var values = _ref8.values; | ||
return 'enum ' + name + ' ' + (0, _printer.block)(values); | ||
}, | ||
EnumValueDefinition: function EnumValueDefinition(_ref9) { | ||
var name = _ref9.name; | ||
return name; | ||
}, | ||
InputObjectDefinition: function InputObjectDefinition(_ref10) { | ||
var name = _ref10.name; | ||
var fields = _ref10.fields; | ||
return 'input ' + name + ' ' + (0, _printer.block)(fields); | ||
}, | ||
// Value | ||
IntValue: _printer.printDocASTReducer.IntValue, | ||
FloatValue: _printer.printDocASTReducer.FloatValue, | ||
StringValue: _printer.printDocASTReducer.StringValue, | ||
BooleanValue: _printer.printDocASTReducer.BooleanValue, | ||
EnumValue: _printer.printDocASTReducer.EnumValue, | ||
ListValue: _printer.printDocASTReducer.ListValue, | ||
ObjectValue: _printer.printDocASTReducer.ObjectValue, | ||
ObjectField: _printer.printDocASTReducer.ObjectField, | ||
// Type | ||
NamedType: _printer.printDocASTReducer.NamedType, | ||
ListType: _printer.printDocASTReducer.ListType, | ||
NonNullType: _printer.printDocASTReducer.NonNullType | ||
}; | ||
exports.printSchemaASTReducer = printSchemaASTReducer; |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -25,3 +25,3 @@ * Copyright (c) 2015, Facebook, Inc. | ||
var Source = function Source(body, name) { | ||
var Source = function Source(body /*: string*/, name /*:: ?: string*/) { | ||
_classCallCheck(this, Source); | ||
@@ -28,0 +28,0 @@ |
@@ -19,3 +19,3 @@ /** | ||
exports.getVisitFn = getVisitFn; | ||
var VisitorKeys = { | ||
var QueryDocumentKeys = { | ||
Name: [], | ||
@@ -51,3 +51,3 @@ | ||
exports.VisitorKeys = VisitorKeys; | ||
exports.QueryDocumentKeys = QueryDocumentKeys; | ||
var BREAK = {}; | ||
@@ -143,4 +143,4 @@ | ||
function visit(root, visitor) { | ||
var visitorKeys = visitor.keys || VisitorKeys; | ||
function visit(root, visitor, keyMap) { | ||
var visitorKeys = keyMap || QueryDocumentKeys; | ||
@@ -147,0 +147,0 @@ var stack; |
{ | ||
"name": "graphql", | ||
"version": "0.1.12", | ||
"version": "0.2.0", | ||
"description": "A Query Language and Runtime which can target any service.", | ||
@@ -26,14 +26,21 @@ "contributors": [ | ||
"es7.asyncFunctions" | ||
], | ||
"plugins": [ | ||
"flow-comments" | ||
], | ||
"blacklist": [ | ||
"flow" | ||
] | ||
}, | ||
"scripts": { | ||
"test": "npm run lint && npm run check && mocha $npm_package_options_mocha", | ||
"test": "npm run lint && npm run check && npm run testonly", | ||
"testonly": "mocha $npm_package_options_mocha", | ||
"lint": "eslint src", | ||
"check": "flow check", | ||
"build": "mkdir dist && babel src --ignore __tests__ --out-dir dist/ && cp package.json dist/", | ||
"watch": "babel scripts/watch.js | node", | ||
"cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha", | ||
"coveralls": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", | ||
"cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha", | ||
"preversion": "npm test", | ||
"prepublish": "not-in-install && (if [ \"$CI\" = true ]; then babel src --ignore __tests__ --out-dir ./; else echo 'Only CI can publish. Read CONTRIBUTING.md' 1>&2; exit 1; fi) || in-install" | ||
"prepublish": ". ./scripts/prepublish.sh" | ||
}, | ||
@@ -47,2 +54,3 @@ "dependencies": { | ||
"babel-eslint": "4.0.5", | ||
"babel-plugin-flow-comments": "1.0.9", | ||
"bluebird": "2.9.34", | ||
@@ -53,4 +61,3 @@ "chai": "3.0.0", | ||
"eslint": "0.24.0", | ||
"flow-bin": "0.13.1", | ||
"in-publish": "2.0.0", | ||
"flow-bin": "0.14.0", | ||
"isparta": "3.0.3", | ||
@@ -57,0 +64,0 @@ "minimist": "1.1.2", |
@@ -52,3 +52,3 @@ # GraphQL.js | ||
``` | ||
```sh | ||
npm install graphql | ||
@@ -126,34 +126,12 @@ ``` | ||
After cloning this repo, ensure dependencies are installed by running: | ||
We actively welcome pull requests, learn how to | ||
[contribute](https://github.com/graphql/graphql-js/blob/master/CONTRIBUTING.md). | ||
```sh | ||
npm install | ||
``` | ||
### Changelog | ||
GraphQL is written in ES6 and uses [Babel](http://babeljs.io/) for ES5 | ||
transpilation and [Flow](http://flowtype.org/) for type safety. Widely | ||
consumable JavaScript can be produced by running: | ||
Changes are tracked as [Github releases](https://github.com/graphql/graphql-js/releases). | ||
```sh | ||
npm run build | ||
``` | ||
### License | ||
Once `npm run build` has run, you may `import` or `require()` directly from | ||
node. | ||
After developing, the full test suite can be evaluated by running: | ||
```sh | ||
npm test | ||
``` | ||
While actively developing, we recommend running | ||
```sh | ||
npm run watch | ||
``` | ||
in a terminal. This will watch the file system run lint, tests, and type | ||
checking automatically whenever you save a js file. | ||
To lint the JS files and type interface checks run `npm run lint`. | ||
GraphQL is [BSD-licensed](https://github.com/graphql/graphql-js/blob/master/LICENSE). | ||
We also provide an additional [patent grant](https://github.com/graphql/graphql-js/blob/master/PATENTS). |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -3,0 +3,0 @@ * Copyright (c) 2015, Facebook, Inc. |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -11,13 +11,4 @@ * Copyright (c) 2015, Facebook, Inc. | ||
/** | ||
* These are all of the possible kinds of types. | ||
*/ | ||
'use strict'; | ||
// Predicates | ||
/** | ||
* These types may be used as input types for arguments and directives. | ||
*/ | ||
var _createClass = require('babel-runtime/helpers/create-class')['default']; | ||
@@ -37,40 +28,43 @@ | ||
exports.isInputType = isInputType; | ||
/** | ||
* These types may be used as output types as the result of fields. | ||
*/ | ||
exports.isOutputType = isOutputType; | ||
/** | ||
* These types may describe types which may be leaf values. | ||
*/ | ||
exports.isLeafType = isLeafType; | ||
/** | ||
* These types may describe the parent context of a selection set. | ||
*/ | ||
exports.isCompositeType = isCompositeType; | ||
/** | ||
* These types may describe the parent context of a selection set. | ||
*/ | ||
exports.isAbstractType = isAbstractType; | ||
/** | ||
* These types can all accept null as a value. | ||
*/ | ||
exports.getNullableType = getNullableType; | ||
/** | ||
* These named types do not include modifiers like List or NonNull. | ||
*/ | ||
exports.getNamedType = getNamedType; | ||
var _utilsInvariant = require('../utils/invariant'); | ||
var _jsutilsInvariant = require('../jsutils/invariant'); | ||
var _utilsInvariant2 = _interopRequireDefault(_utilsInvariant); | ||
var _jsutilsInvariant2 = _interopRequireDefault(_jsutilsInvariant); | ||
var _languageKinds = require('../language/kinds'); | ||
function isInputType(type) { | ||
/*:: import type { Value } from '../language/ast';*/ | ||
/** | ||
* These are all of the possible kinds of types. | ||
*/ | ||
/*:: import type { GraphQLSchema } from './schema';*/ | ||
// Predicates | ||
/** | ||
* These types may be used as input types for arguments and directives. | ||
*/ | ||
/*:: export type GraphQLType = | ||
GraphQLScalarType | | ||
GraphQLObjectType | | ||
GraphQLInterfaceType | | ||
GraphQLUnionType | | ||
GraphQLEnumType | | ||
GraphQLInputObjectType | | ||
GraphQLList | | ||
GraphQLNonNull;*/ | ||
/*:: export type GraphQLInputType = | ||
GraphQLScalarType | | ||
GraphQLEnumType | | ||
GraphQLInputObjectType | | ||
GraphQLList | | ||
GraphQLNonNull;*/ | ||
function isInputType(type /*: ?GraphQLType*/) /*: boolean*/ { | ||
var namedType = getNamedType(type); | ||
@@ -80,3 +74,15 @@ return namedType instanceof GraphQLScalarType || namedType instanceof GraphQLEnumType || namedType instanceof GraphQLInputObjectType; | ||
function isOutputType(type) { | ||
/** | ||
* These types may be used as output types as the result of fields. | ||
*/ | ||
/*:: export type GraphQLOutputType = | ||
GraphQLScalarType | | ||
GraphQLObjectType | | ||
GraphQLInterfaceType | | ||
GraphQLUnionType | | ||
GraphQLEnumType | | ||
GraphQLList | | ||
GraphQLNonNull;*/ | ||
function isOutputType(type /*: ?GraphQLType*/) /*: boolean*/ { | ||
var namedType = getNamedType(type); | ||
@@ -86,3 +92,10 @@ return namedType instanceof GraphQLScalarType || namedType instanceof GraphQLObjectType || namedType instanceof GraphQLInterfaceType || namedType instanceof GraphQLUnionType || namedType instanceof GraphQLEnumType; | ||
function isLeafType(type) { | ||
/** | ||
* These types may describe types which may be leaf values. | ||
*/ | ||
/*:: export type GraphQLLeafType = | ||
GraphQLScalarType | | ||
GraphQLEnumType;*/ | ||
function isLeafType(type /*: ?GraphQLType*/) /*: boolean*/ { | ||
var namedType = getNamedType(type); | ||
@@ -92,15 +105,53 @@ return namedType instanceof GraphQLScalarType || namedType instanceof GraphQLEnumType; | ||
function isCompositeType(type) { | ||
/** | ||
* These types may describe the parent context of a selection set. | ||
*/ | ||
/*:: export type GraphQLCompositeType = | ||
GraphQLObjectType | | ||
GraphQLInterfaceType | | ||
GraphQLUnionType;*/ | ||
function isCompositeType(type /*: ?GraphQLType*/) /*: boolean*/ { | ||
return type instanceof GraphQLObjectType || type instanceof GraphQLInterfaceType || type instanceof GraphQLUnionType; | ||
} | ||
function isAbstractType(type) { | ||
/** | ||
* These types may describe the parent context of a selection set. | ||
*/ | ||
/*:: export type GraphQLAbstractType = | ||
GraphQLInterfaceType | | ||
GraphQLUnionType;*/ | ||
function isAbstractType(type /*: ?GraphQLType*/) /*: boolean*/ { | ||
return type instanceof GraphQLInterfaceType || type instanceof GraphQLUnionType; | ||
} | ||
function getNullableType(type) { | ||
/** | ||
* These types can all accept null as a value. | ||
*/ | ||
/*:: export type GraphQLNullableType = | ||
GraphQLScalarType | | ||
GraphQLObjectType | | ||
GraphQLInterfaceType | | ||
GraphQLUnionType | | ||
GraphQLEnumType | | ||
GraphQLInputObjectType | | ||
GraphQLList;*/ | ||
function getNullableType(type /*: ?GraphQLType*/) /*: ?GraphQLNullableType*/ { | ||
return type instanceof GraphQLNonNull ? type.ofType : type; | ||
} | ||
function getNamedType(type) { | ||
/** | ||
* These named types do not include modifiers like List or NonNull. | ||
*/ | ||
/*:: export type GraphQLNamedType = | ||
GraphQLScalarType | | ||
GraphQLObjectType | | ||
GraphQLInterfaceType | | ||
GraphQLUnionType | | ||
GraphQLEnumType | | ||
GraphQLInputObjectType;*/ | ||
function getNamedType(type /*: ?GraphQLType*/) /*: ?GraphQLNamedType*/ { | ||
var unmodifiedType = type; | ||
@@ -133,6 +184,6 @@ while (unmodifiedType instanceof GraphQLList || unmodifiedType instanceof GraphQLNonNull) { | ||
/*<T>*/ | ||
function GraphQLScalarType(config /*<T>*/) { | ||
function GraphQLScalarType(config /*: GraphQLScalarTypeConfig*/ /*<T>*/) { | ||
_classCallCheck(this, GraphQLScalarType); | ||
(0, _utilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
(0, _jsutilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
this.name = config.name; | ||
@@ -145,3 +196,3 @@ this.description = config.description; | ||
key: 'coerce', | ||
value: function coerce(value) /*T*/{ | ||
value: function coerce(value /*: any*/) /*T*/ /*: ?any*/ { | ||
var coercer = this._scalarConfig.coerce; | ||
@@ -152,3 +203,3 @@ return coercer(value); | ||
key: 'coerceLiteral', | ||
value: function coerceLiteral(value) /*T*/{ | ||
value: function coerceLiteral(value /*: Value*/) /*T*/ /*: ?any*/ { | ||
var coercer = this._scalarConfig.coerceLiteral; | ||
@@ -159,3 +210,3 @@ return coercer ? coercer(value) : null; | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return this.name; | ||
@@ -169,3 +220,2 @@ } | ||
exports.GraphQLScalarType = GraphQLScalarType; | ||
/*T*/ | ||
@@ -209,8 +259,13 @@ /** | ||
*/ | ||
/*:: export type GraphQLScalarTypeConfig/*<T>*-/ = { | ||
name: string; | ||
description?: ?string; | ||
coerce: (value: any) => ?any/*T*-/; | ||
coerceLiteral: (value: Value) => ?any/*T*-/; | ||
}*/ /*T*/ | ||
var GraphQLObjectType = (function () { | ||
function GraphQLObjectType(config) { | ||
function GraphQLObjectType(config /*: GraphQLObjectTypeConfig*/) { | ||
_classCallCheck(this, GraphQLObjectType); | ||
(0, _utilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
(0, _jsutilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
this.name = config.name; | ||
@@ -224,3 +279,3 @@ this.description = config.description; | ||
key: 'getFields', | ||
value: function getFields() { | ||
value: function getFields() /*: GraphQLFieldDefinitionMap*/ { | ||
return this._fields || (this._fields = defineFieldMap(this._typeConfig.fields)); | ||
@@ -230,3 +285,3 @@ } | ||
key: 'getInterfaces', | ||
value: function getInterfaces() { | ||
value: function getInterfaces() /*: Array<GraphQLInterfaceType>*/ { | ||
return this._interfaces || (this._interfaces = defineInterfaces(this._typeConfig.interfaces || [])); | ||
@@ -236,3 +291,3 @@ } | ||
key: 'isTypeOf', | ||
value: function isTypeOf(value) { | ||
value: function isTypeOf(value /*: any*/) /*: ?boolean*/ { | ||
var predicate = this._typeConfig.isTypeOf; | ||
@@ -245,3 +300,3 @@ if (predicate) { | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return this.name; | ||
@@ -256,12 +311,12 @@ } | ||
function resolveMaybeThunk(thingOrThunk) { | ||
function resolveMaybeThunk /*:: <T>*/(thingOrThunk /*: T | () => T*/) /*: T*/ { | ||
return typeof thingOrThunk === 'function' ? thingOrThunk() : thingOrThunk; | ||
} | ||
function defineInterfaces(interfacesOrThunk) { | ||
function defineInterfaces(interfacesOrThunk) /*: Array<GraphQLInterfaceType>*/ { | ||
return resolveMaybeThunk(interfacesOrThunk); | ||
} | ||
function defineFieldMap(fields) { | ||
var fieldMap = resolveMaybeThunk(fields); | ||
function defineFieldMap(fields /*: GraphQLFieldConfigMap*/) /*: GraphQLFieldDefinitionMap*/ { | ||
var fieldMap /*: any*/ = resolveMaybeThunk(fields); | ||
_Object$keys(fieldMap).forEach(function (fieldName) { | ||
@@ -275,3 +330,3 @@ var field = fieldMap[fieldName]; | ||
var arg = field.args[argName]; | ||
(0, _utilsInvariant2['default'])(arg.type, 'Arg must supply type. ' + fieldName + '.' + argName); | ||
(0, _jsutilsInvariant2['default'])(arg.type, 'Arg must supply type. ' + fieldName + '.' + argName); | ||
return { | ||
@@ -301,2 +356,59 @@ name: argName, | ||
/*:: export type GraphQLObjectTypeConfig = { | ||
name: string; | ||
interfaces?: GraphQLInterfacesThunk | Array<GraphQLInterfaceType>; | ||
fields: GraphQLFieldConfigMapThunk | GraphQLFieldConfigMap; | ||
isTypeOf?: (value: any) => boolean; | ||
description?: ?string | ||
}*/ | ||
/*:: type GraphQLInterfacesThunk = () => Array<GraphQLInterfaceType>;*/ | ||
/*:: type GraphQLFieldConfigMapThunk = () => GraphQLFieldConfigMap;*/ | ||
/*:: export type GraphQLFieldConfig = { | ||
type: GraphQLOutputType; | ||
args?: GraphQLFieldConfigArgumentMap; | ||
resolve?: ( | ||
source?: any, | ||
args?: ?{[argName: string]: any}, | ||
context?: any, | ||
fieldAST?: any, | ||
fieldType?: any, | ||
parentType?: any, | ||
schema?: GraphQLSchema | ||
) => any; | ||
deprecationReason?: string; | ||
description?: ?string; | ||
}*/ | ||
/*:: export type GraphQLFieldConfigArgumentMap = { | ||
[argName: string]: GraphQLArgumentConfig; | ||
};*/ | ||
/*:: export type GraphQLArgumentConfig = { | ||
type: GraphQLInputType; | ||
defaultValue?: any; | ||
}*/ | ||
/*:: export type GraphQLFieldConfigMap = { | ||
[fieldName: string]: GraphQLFieldConfig; | ||
};*/ | ||
/*:: export type GraphQLFieldDefinition = { | ||
name: string; | ||
description: ?string; | ||
type: GraphQLOutputType; | ||
args: Array<GraphQLArgument>; | ||
resolve?: ( | ||
source?: any, | ||
args?: ?{[argName: string]: any}, | ||
context?: any, | ||
fieldAST?: any, | ||
fieldType?: any, | ||
parentType?: any, | ||
schema?: GraphQLSchema | ||
) => any; | ||
deprecationReason?: ?string; | ||
}*/ | ||
/*:: export type GraphQLArgument = { | ||
name: string; | ||
type: GraphQLInputType; | ||
defaultValue?: any; | ||
description?: ?string; | ||
};*/ | ||
/** | ||
@@ -320,8 +432,10 @@ * Interface Type Definition | ||
*/ | ||
/*:: export type GraphQLFieldDefinitionMap = { | ||
[fieldName: string]: GraphQLFieldDefinition; | ||
};*/ | ||
var GraphQLInterfaceType = (function () { | ||
function GraphQLInterfaceType(config) { | ||
function GraphQLInterfaceType(config /*: GraphQLInterfaceTypeConfig*/) { | ||
_classCallCheck(this, GraphQLInterfaceType); | ||
(0, _utilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
(0, _jsutilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
this.name = config.name; | ||
@@ -335,3 +449,3 @@ this.description = config.description; | ||
key: 'getFields', | ||
value: function getFields() { | ||
value: function getFields() /*: GraphQLFieldDefinitionMap*/ { | ||
return this._fields || (this._fields = defineFieldMap(this._typeConfig.fields)); | ||
@@ -341,3 +455,3 @@ } | ||
key: 'getPossibleTypes', | ||
value: function getPossibleTypes() { | ||
value: function getPossibleTypes() /*: Array<GraphQLObjectType>*/ { | ||
return this._implementations; | ||
@@ -347,3 +461,3 @@ } | ||
key: 'isPossibleType', | ||
value: function isPossibleType(type) { | ||
value: function isPossibleType(type /*: GraphQLObjectType*/) /*: boolean*/ { | ||
var possibleTypeNames = this._possibleTypeNames; | ||
@@ -359,3 +473,3 @@ if (!possibleTypeNames) { | ||
key: 'resolveType', | ||
value: function resolveType(value) { | ||
value: function resolveType(value /*: any*/) /*: ?GraphQLObjectType*/ { | ||
var resolver = this._typeConfig.resolveType; | ||
@@ -366,3 +480,3 @@ return resolver ? resolver(value) : getTypeOf(value, this); | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return this.name; | ||
@@ -377,3 +491,3 @@ } | ||
function getTypeOf(value, abstractType) { | ||
function getTypeOf(value /*: any*/, abstractType /*: GraphQLAbstractType*/) /*: ?GraphQLObjectType*/ { | ||
var possibleTypes = abstractType.getPossibleTypes(); | ||
@@ -417,11 +531,21 @@ for (var i = 0; i < possibleTypes.length; i++) { | ||
*/ | ||
/*:: export type GraphQLInterfaceTypeConfig = { | ||
name: string, | ||
fields: GraphQLFieldConfigMapThunk | GraphQLFieldConfigMap, | ||
/** | ||
* Optionally provide a custom type resolver function. If one is not provided, | ||
* the default implemenation will call `isTypeOf` on each implementing | ||
* Object type. | ||
*-/ | ||
resolveType?: (value: any) => ?GraphQLObjectType, | ||
description?: ?string | ||
};*/ | ||
var GraphQLUnionType = (function () { | ||
function GraphQLUnionType(config) { | ||
function GraphQLUnionType(config /*: GraphQLUnionTypeConfig*/) { | ||
_classCallCheck(this, GraphQLUnionType); | ||
(0, _utilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
(0, _jsutilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
this.name = config.name; | ||
this.description = config.description; | ||
(0, _utilsInvariant2['default'])(config.types && config.types.length, 'Must provide types for Union ' + config.name + '.'); | ||
(0, _jsutilsInvariant2['default'])(config.types && config.types.length, 'Must provide types for Union ' + config.name + '.'); | ||
if (!config.types.every(function (x) { | ||
@@ -441,3 +565,3 @@ return x instanceof GraphQLObjectType; | ||
key: 'getPossibleTypes', | ||
value: function getPossibleTypes() { | ||
value: function getPossibleTypes() /*: Array<GraphQLObjectType>*/ { | ||
return this._types; | ||
@@ -447,3 +571,3 @@ } | ||
key: 'isPossibleType', | ||
value: function isPossibleType(type) { | ||
value: function isPossibleType(type /*: GraphQLObjectType*/) /*: boolean*/ { | ||
var possibleTypeNames = this._possibleTypeNames; | ||
@@ -459,3 +583,3 @@ if (!possibleTypeNames) { | ||
key: 'resolveType', | ||
value: function resolveType(value) { | ||
value: function resolveType(value /*: any*/) /*: ?GraphQLObjectType*/ { | ||
var resolver = this._typeConfig.resolveType; | ||
@@ -466,3 +590,3 @@ return resolver ? resolver(value) : getTypeOf(value, this); | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return this.name; | ||
@@ -498,5 +622,15 @@ } | ||
*/ | ||
/*:: export type GraphQLUnionTypeConfig = { | ||
name: string, | ||
types: Array<GraphQLObjectType>, | ||
/** | ||
* Optionally provide a custom type resolver function. If one is not provided, | ||
* the default implemenation will call `isTypeOf` on each implementing | ||
* Object type. | ||
*-/ | ||
resolveType?: (value: any) => ?GraphQLObjectType; | ||
description?: ?string; | ||
};*/ | ||
var GraphQLEnumType /*<T>*/ = (function () { | ||
function GraphQLEnumType(config /*<T>*/) { | ||
function GraphQLEnumType(config /*: GraphQLEnumTypeConfig*/ /*<T>*/) { | ||
_classCallCheck(this, GraphQLEnumType); | ||
@@ -511,3 +645,3 @@ | ||
key: 'getValues', | ||
value: function getValues() /*<T>*/{ | ||
value: function getValues() /*<T>*/ /*: GraphQLEnumValueDefinitionMap*/ { | ||
return this._values || (this._values = this._defineValueMap()); | ||
@@ -517,4 +651,4 @@ } | ||
key: 'coerce', | ||
value: function coerce(value /*T*/) { | ||
var enumValue = this._getValueLookup().get(value); | ||
value: function coerce(value /*: any*/ /*T*/) /*: ?string*/ { | ||
var enumValue = this._getValueLookup().get((value /*: any*/)); | ||
return enumValue ? enumValue.name : null; | ||
@@ -524,3 +658,3 @@ } | ||
key: 'coerceLiteral', | ||
value: function coerceLiteral(value) /*T*/{ | ||
value: function coerceLiteral(value /*: Value*/) /*T*/ /*: ?any*/ { | ||
if (value.kind === _languageKinds.ENUM) { | ||
@@ -535,4 +669,4 @@ var enumValue = this._getNameLookup().get(value.value); | ||
key: '_defineValueMap', | ||
value: function _defineValueMap() /*<T>*/{ | ||
var valueMap = this._enumConfig.values; | ||
value: function _defineValueMap() /*<T>*/ /*: GraphQLEnumValueDefinitionMap*/ { | ||
var valueMap = (this._enumConfig.values /*: any*/); | ||
_Object$keys(valueMap).forEach(function (valueName) { | ||
@@ -549,3 +683,3 @@ var value = valueMap[valueName]; | ||
key: '_getValueLookup', | ||
value: function _getValueLookup() { | ||
value: function _getValueLookup() /*: Map<any/*T*-/, GraphQLEnumValueDefinition>*/ { | ||
if (!this._valueLookup) { | ||
@@ -564,3 +698,3 @@ var lookup = new _Map(); | ||
key: '_getNameLookup', | ||
value: function _getNameLookup() { | ||
value: function _getNameLookup() /*: Map<string, GraphQLEnumValueDefinition>*/ { | ||
if (!this._nameLookup) { | ||
@@ -579,3 +713,3 @@ var lookup = new _Map(); | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return this.name; | ||
@@ -589,4 +723,20 @@ } | ||
exports.GraphQLEnumType = GraphQLEnumType; | ||
/*<T>*/ /*<T>*/ | ||
/*:: export type GraphQLEnumTypeConfig/*<T>*-/ = { | ||
name: string; | ||
values: GraphQLEnumValueConfigMap/*<T>*-/; | ||
description?: ?string; | ||
}*/ | ||
/*:: export type GraphQLEnumValueConfigMap/*<T>*-/ = { | ||
[valueName: string]: GraphQLEnumValueConfig/*<T>*-/; | ||
};*/ /*<T>*/ | ||
/*:: export type GraphQLEnumValueConfig/*<T>*-/ = { | ||
value?: any/*T*-/; | ||
deprecationReason?: string; | ||
description?: ?string; | ||
}*/ | ||
/*:: export type GraphQLEnumValueDefinitionMap/*<T>*-/ = { | ||
[valueName: string]: GraphQLEnumValueDefinition/*<T>*-/; | ||
};*/ /*<T>*/ | ||
/** | ||
@@ -612,8 +762,13 @@ * Input Object Type Definition | ||
*/ | ||
/*:: export type GraphQLEnumValueDefinition/*<T>*-/ = { | ||
name: string; | ||
value?: any/*T*-/; | ||
deprecationReason?: string; | ||
description?: ?string; | ||
}*/ | ||
var GraphQLInputObjectType = (function () { | ||
function GraphQLInputObjectType(config) { | ||
function GraphQLInputObjectType(config /*: InputObjectConfig*/) { | ||
_classCallCheck(this, GraphQLInputObjectType); | ||
(0, _utilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
(0, _jsutilsInvariant2['default'])(config.name, 'Type must be named.'); | ||
this.name = config.name; | ||
@@ -626,3 +781,3 @@ this.description = config.description; | ||
key: 'getFields', | ||
value: function getFields() { | ||
value: function getFields() /*: InputObjectFieldMap*/ { | ||
return this._fields || (this._fields = this._defineFieldMap()); | ||
@@ -632,5 +787,5 @@ } | ||
key: '_defineFieldMap', | ||
value: function _defineFieldMap() { | ||
value: function _defineFieldMap() /*: InputObjectFieldMap*/ { | ||
var fields = this._typeConfig.fields; | ||
var fieldMap = typeof fields === 'function' ? fields() : fields; | ||
var fieldMap /*: any*/ = typeof fields === 'function' ? fields() : fields; | ||
_Object$keys(fieldMap).forEach(function (fieldName) { | ||
@@ -644,3 +799,3 @@ var field = fieldMap[fieldName]; | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return this.name; | ||
@@ -655,2 +810,23 @@ } | ||
/*:: export type InputObjectConfig = { | ||
name: string; | ||
fields: InputObjectConfigFieldMapThunk | InputObjectConfigFieldMap; | ||
description?: ?string; | ||
}*/ | ||
/*:: type InputObjectConfigFieldMapThunk = () => InputObjectConfigFieldMap;*/ | ||
/*:: export type InputObjectFieldConfig = { | ||
type: GraphQLInputType; | ||
defaultValue?: any; | ||
description?: ?string; | ||
}*/ | ||
/*:: export type InputObjectConfigFieldMap = { | ||
[fieldName: string]: InputObjectFieldConfig; | ||
};*/ | ||
/*:: export type InputObjectField = { | ||
name: string; | ||
type: GraphQLInputType; | ||
defaultValue?: any; | ||
description?: ?string; | ||
}*/ | ||
/** | ||
@@ -674,5 +850,7 @@ * List Modifier | ||
*/ | ||
/*:: export type InputObjectFieldMap = { | ||
[fieldName: string]: InputObjectField; | ||
};*/ | ||
var GraphQLList = (function () { | ||
function GraphQLList(type) { | ||
function GraphQLList(type /*: GraphQLType*/) { | ||
_classCallCheck(this, GraphQLList); | ||
@@ -685,3 +863,3 @@ | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return '[' + this.ofType.toString() + ']'; | ||
@@ -719,6 +897,6 @@ } | ||
var GraphQLNonNull = (function () { | ||
function GraphQLNonNull(type) { | ||
function GraphQLNonNull(type /*: GraphQLType*/) { | ||
_classCallCheck(this, GraphQLNonNull); | ||
(0, _utilsInvariant2['default'])(!(type instanceof GraphQLNonNull), 'Cannot nest NonNull inside NonNull.'); | ||
(0, _jsutilsInvariant2['default'])(!(type instanceof GraphQLNonNull), 'Cannot nest NonNull inside NonNull.'); | ||
this.ofType = type; | ||
@@ -729,3 +907,3 @@ } | ||
key: 'toString', | ||
value: function toString() { | ||
value: function toString() /*: string*/ { | ||
return this.ofType.toString() + '!'; | ||
@@ -732,0 +910,0 @@ } |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -28,3 +28,4 @@ * Copyright (c) 2015, Facebook, Inc. | ||
var GraphQLDirective = function GraphQLDirective(config) { | ||
/*:: import type { GraphQLArgument } from './definition';*/ | ||
var GraphQLDirective = function GraphQLDirective(config /*: GraphQLDirectiveConfig*/) { | ||
_classCallCheck(this, GraphQLDirective); | ||
@@ -45,3 +46,10 @@ | ||
*/ | ||
var GraphQLIncludeDirective = new GraphQLDirective({ | ||
/*:: type GraphQLDirectiveConfig = { | ||
name: string; | ||
description?: string; | ||
args: Array<GraphQLArgument>; | ||
onOperation: boolean; | ||
onFragment: boolean; | ||
onField: boolean; | ||
}*/var GraphQLIncludeDirective = new GraphQLDirective({ | ||
name: 'include', | ||
@@ -48,0 +56,0 @@ description: 'Directs the executor to include this field or fragment only when ' + 'the `if` argument is true.', |
@@ -0,1 +1,2 @@ | ||
/*@flow*/ | ||
/** | ||
@@ -10,2 +11,3 @@ * Copyright (c) 2015, Facebook, Inc. | ||
// GraphQL Schema definition | ||
'use strict'; | ||
@@ -28,2 +30,45 @@ | ||
// Common built-in scalar instances. | ||
Object.defineProperty(exports, 'isInputType', { | ||
enumerable: true, | ||
get: function get() { | ||
return _definition.isInputType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'isOutputType', { | ||
enumerable: true, | ||
get: function get() { | ||
return _definition.isOutputType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'isLeafType', { | ||
enumerable: true, | ||
get: function get() { | ||
return _definition.isLeafType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'isCompositeType', { | ||
enumerable: true, | ||
get: function get() { | ||
return _definition.isCompositeType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'isAbstractType', { | ||
enumerable: true, | ||
get: function get() { | ||
return _definition.isAbstractType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'getNullableType', { | ||
enumerable: true, | ||
get: function get() { | ||
return _definition.getNullableType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'getNamedType', { | ||
enumerable: true, | ||
get: function get() { | ||
return _definition.getNamedType; | ||
} | ||
}); | ||
Object.defineProperty(exports, 'GraphQLScalarType', { | ||
@@ -80,2 +125,9 @@ enumerable: true, | ||
// Export flow types. | ||
// Note: a future version of flow may support `export type {} from ''`, but | ||
// until then, this is a viable workaround. | ||
// These are unions of the various GraphQL type definitions that are useful | ||
// annotation alongside the GraphQL type predicates. | ||
Object.defineProperty(exports, 'GraphQLInt', { | ||
@@ -110,2 +162,26 @@ enumerable: true, | ||
} | ||
}); | ||
}); | ||
/*:: import type { | ||
GraphQLType, | ||
GraphQLInputType, | ||
GraphQLOutputType, | ||
GraphQLLeafType, | ||
GraphQLCompositeType, | ||
GraphQLAbstractType, | ||
GraphQLNullableType, | ||
GraphQLNamedType, | ||
} from './definition';*/ | ||
/*:: export type GraphQLType = GraphQLType;*/ | ||
/*:: export type GraphQLInputType = GraphQLInputType;*/ | ||
/*:: export type GraphQLOutputType = GraphQLOutputType;*/ | ||
/*:: export type GraphQLLeafType = GraphQLLeafType;*/ | ||
/*:: export type GraphQLCompositeType = GraphQLCompositeType;*/ | ||
/*:: export type GraphQLAbstractType = GraphQLAbstractType;*/ | ||
/*:: export type GraphQLNullableType = GraphQLNullableType;*/ | ||
/*:: export type GraphQLNamedType = GraphQLNamedType;*/ | ||
// Predicates | ||
// Un-modifiers | ||
// Definitions |
@@ -1,2 +0,2 @@ | ||
/* weak */ | ||
/* @flow weak */ | ||
/** | ||
@@ -19,2 +19,6 @@ * Copyright (c) 2015, Facebook, Inc. | ||
var _utilitiesAstFromValue = require('../utilities/astFromValue'); | ||
var _languagePrinter = require('../language/printer'); | ||
var _definition = require('./definition'); | ||
@@ -24,3 +28,3 @@ | ||
var __Schema = new _definition.GraphQLObjectType({ | ||
/*:: import type { GraphQLFieldDefinition } from './definition';*/var __Schema = new _definition.GraphQLObjectType({ | ||
name: '__Schema', | ||
@@ -228,3 +232,3 @@ description: 'A GraphQL Schema defines the capabilities of a GraphQL ' + 'server. It exposes all available types and directives on ' + 'the server, as well as the entry points for query and ' + 'mutation operations.', | ||
resolve: function resolve(inputVal) { | ||
return inputVal.defaultValue == null ? null : JSON.stringify(inputVal.defaultValue); | ||
return inputVal.defaultValue == null ? null : (0, _languagePrinter.print)((0, _utilitiesAstFromValue.astFromValue)(inputVal.defaultValue, inputVal)); | ||
} | ||
@@ -254,12 +258,13 @@ } | ||
var TypeKind = { | ||
SCALAR: 0, | ||
OBJECT: 1, | ||
INTERFACE: 2, | ||
UNION: 3, | ||
ENUM: 4, | ||
INPUT_OBJECT: 5, | ||
LIST: 6, | ||
NON_NULL: 7 | ||
SCALAR: 'SCALAR', | ||
OBJECT: 'OBJECT', | ||
INTERFACE: 'INTERFACE', | ||
UNION: 'UNION', | ||
ENUM: 'ENUM', | ||
INPUT_OBJECT: 'INPUT_OBJECT', | ||
LIST: 'LIST', | ||
NON_NULL: 'NON_NULL' | ||
}; | ||
exports.TypeKind = TypeKind; | ||
var __TypeKind = new _definition.GraphQLEnumType({ | ||
@@ -309,3 +314,3 @@ name: '__TypeKind', | ||
var SchemaMetaFieldDef = { | ||
var SchemaMetaFieldDef /*: GraphQLFieldDefinition*/ = { | ||
name: '__schema', | ||
@@ -321,3 +326,3 @@ type: new _definition.GraphQLNonNull(__Schema), | ||
exports.SchemaMetaFieldDef = SchemaMetaFieldDef; | ||
var TypeMetaFieldDef = { | ||
var TypeMetaFieldDef /*: GraphQLFieldDefinition*/ = { | ||
name: '__type', | ||
@@ -334,3 +339,3 @@ type: __Type, | ||
exports.TypeMetaFieldDef = TypeMetaFieldDef; | ||
var TypeNameMetaFieldDef = { | ||
var TypeNameMetaFieldDef /*: GraphQLFieldDefinition*/ = { | ||
name: '__typename', | ||
@@ -337,0 +342,0 @@ type: new _definition.GraphQLNonNull(_scalars.GraphQLString), |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -24,3 +24,4 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function InterfacePossibleTypesMustImplementTheInterface(context) { | ||
/*:: import type { ValidationContext } from '../validator';*/ | ||
function InterfacePossibleTypesMustImplementTheInterface(context /*: ValidationContext*/) /*: ?Array<GraphQLError>*/ { | ||
var schema = context.getSchema(); | ||
@@ -27,0 +28,0 @@ var typeMap = schema.getTypeMap(); |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -26,3 +26,5 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function NoInputTypesAsOutputFields(context) { | ||
/*:: import type { ValidationContext } from '../validator';*/ | ||
/*:: import type { GraphQLType } from '../definition';*/ | ||
function NoInputTypesAsOutputFields(context /*: ValidationContext*/) /*: ?Array<GraphQLError>*/ { | ||
var schema = context.getSchema(); | ||
@@ -71,3 +73,3 @@ var typeMap = schema.getTypeMap(); | ||
function operationMayNotBeInputType(type, operation) { | ||
function operationMayNotBeInputType(type /*: GraphQLType*/, operation /*: 'query' | 'mutation'*/) { | ||
if (!(0, _definition.isOutputType)(type)) { | ||
@@ -74,0 +76,0 @@ return new _error.GraphQLError('Schema ' + operation + ' type ' + type + ' must be an object type!'); |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -24,3 +24,4 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function NoOutputTypesAsInputArgs(context) { | ||
/*:: import type { ValidationContext } from '../validator';*/ | ||
function NoOutputTypesAsInputArgs(context /*: ValidationContext*/) /*: ?Array<GraphQLError>*/ { | ||
var schema = context.getSchema(); | ||
@@ -27,0 +28,0 @@ var typeMap = schema.getTypeMap(); |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -24,3 +24,4 @@ * Copyright (c) 2015, Facebook, Inc. | ||
function TypesInterfacesMustShowThemAsPossible(context) { | ||
/*:: import type { ValidationContext } from '../validator';*/ | ||
function TypesInterfacesMustShowThemAsPossible(context /*: ValidationContext*/) /*: ?Array<GraphQLError>*/ { | ||
var schema = context.getSchema(); | ||
@@ -27,0 +28,0 @@ var typeMap = schema.getTypeMap(); |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -3,0 +3,0 @@ * Copyright (c) 2015, Facebook, Inc. |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -24,3 +24,2 @@ * Copyright (c) 2015, Facebook, Inc. | ||
}); | ||
exports.typeMapReducer = typeMapReducer; | ||
@@ -33,3 +32,3 @@ var _definition = require('./definition'); | ||
var _utilsFind = require('../utils/find'); | ||
var _jsutilsFind = require('../jsutils/find'); | ||
@@ -52,6 +51,8 @@ /** | ||
var _utilsFind2 = _interopRequireDefault(_utilsFind); | ||
var _jsutilsFind2 = _interopRequireDefault(_jsutilsFind); | ||
/*:: import type { GraphQLType } from './definition';*/ | ||
/*:: import type { GraphQLDirective } from './directives';*/ | ||
var GraphQLSchema = (function () { | ||
function GraphQLSchema(config) { | ||
function GraphQLSchema(config /*: GraphQLSchemaConfig*/) { | ||
_classCallCheck(this, GraphQLSchema); | ||
@@ -64,3 +65,3 @@ | ||
key: 'getQueryType', | ||
value: function getQueryType() { | ||
value: function getQueryType() /*: GraphQLObjectType*/ { | ||
return this._schemaConfig.query; | ||
@@ -70,3 +71,3 @@ } | ||
key: 'getMutationType', | ||
value: function getMutationType() { | ||
value: function getMutationType() /*: ?GraphQLObjectType*/ { | ||
return this._schemaConfig.mutation; | ||
@@ -76,3 +77,3 @@ } | ||
key: 'getTypeMap', | ||
value: function getTypeMap() { | ||
value: function getTypeMap() /*: TypeMap*/ { | ||
return this._typeMap || (this._typeMap = [this.getQueryType(), this.getMutationType(), _introspection.__Schema].reduce(typeMapReducer, {})); | ||
@@ -82,3 +83,3 @@ } | ||
key: 'getType', | ||
value: function getType(name) { | ||
value: function getType(name /*: string*/) /*: ?GraphQLType*/ { | ||
return this.getTypeMap()[name]; | ||
@@ -88,3 +89,3 @@ } | ||
key: 'getDirectives', | ||
value: function getDirectives() { | ||
value: function getDirectives() /*: Array<GraphQLDirective>*/ { | ||
return this._directives || (this._directives = [_directives.GraphQLIncludeDirective, _directives.GraphQLSkipDirective]); | ||
@@ -94,4 +95,4 @@ } | ||
key: 'getDirective', | ||
value: function getDirective(name) { | ||
return (0, _utilsFind2['default'])(this.getDirectives(), function (directive) { | ||
value: function getDirective(name /*: string*/) /*: ?GraphQLDirective*/ { | ||
return (0, _jsutilsFind2['default'])(this.getDirectives(), function (directive) { | ||
return directive.name === name; | ||
@@ -107,8 +108,14 @@ }); | ||
function typeMapReducer(_x, _x2) { | ||
/*:: type TypeMap = { [typeName: string]: GraphQLType }*/ | ||
/*:: type GraphQLSchemaConfig = { | ||
query: GraphQLObjectType; | ||
mutation?: ?GraphQLObjectType; | ||
}*/ | ||
function typeMapReducer(_x, _x2) /*: TypeMap*/ { | ||
var _again = true; | ||
_function: while (_again) { | ||
var map = _x, | ||
type = _x2; | ||
var map /*: TypeMap*/ = _x, | ||
type /*: ?GraphQLType*/ = _x2; | ||
reducedMap = fieldMap = undefined; | ||
@@ -115,0 +122,0 @@ _again = false; |
@@ -1,2 +0,2 @@ | ||
/* @flow */ | ||
/** | ||
@@ -24,5 +24,5 @@ * Copyright (c) 2015, Facebook, Inc. | ||
var _utilsInvariant = require('../utils/invariant'); | ||
var _jsutilsInvariant = require('../jsutils/invariant'); | ||
var _utilsInvariant2 = _interopRequireDefault(_utilsInvariant); | ||
var _jsutilsInvariant2 = _interopRequireDefault(_jsutilsInvariant); | ||
@@ -41,4 +41,5 @@ var _schema = require('./schema'); | ||
function validateSchema(schema, argRules) { | ||
(0, _utilsInvariant2['default'])(schema, 'Must provide schema'); | ||
/*:: import type { GraphQLError } from '../error/GraphQLError';*/ | ||
function validateSchema(schema /*: GraphQLSchema*/, argRules /*: ?Array<(context: ValidationContext) => ?Array<GraphQLError>>*/) /*: Array<GraphQLError>*/ { | ||
(0, _jsutilsInvariant2['default'])(schema, 'Must provide schema'); | ||
var context = new ValidationContext(schema); | ||
@@ -59,3 +60,3 @@ var errors = []; | ||
var ValidationContext = (function () { | ||
function ValidationContext(schema) { | ||
function ValidationContext(schema /*: GraphQLSchema*/) { | ||
_classCallCheck(this, ValidationContext); | ||
@@ -68,3 +69,3 @@ | ||
key: 'getSchema', | ||
value: function getSchema() { | ||
value: function getSchema() /*: GraphQLSchema*/ { | ||
return this._schema; | ||
@@ -71,0 +72,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
319823
81
8482
136