Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

apollo-codegen

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

apollo-codegen - npm Package Compare versions

Comparing version 0.10.1 to 0.10.2

88

lib/cli.js
#!/usr/bin/env node
'use strict';
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');

@@ -16,6 +12,2 @@

var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _process = require('process');

@@ -42,3 +34,3 @@

// Make sure unhandled errors in async code are propagated correctly
_process2.default.on('unhandledRejection', function (error) {
_process2.default.on('unhandledRejection', error => {
throw error;

@@ -66,66 +58,30 @@ });

type: 'array',
coerce: function coerce(arg) {
var additionalHeaders = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
coerce: arg => {
let additionalHeaders = {};
for (const header of arg) {
var _header$split = header.split(/\s*:\s*/),
_header$split2 = (0, _slicedToArray3.default)(_header$split, 2);
try {
for (var _iterator = (0, _getIterator3.default)(arg), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var header = _step.value;
const name = _header$split2[0],
value = _header$split2[1];
var _header$split = header.split(/\s*:\s*/);
var _header$split2 = (0, _slicedToArray3.default)(_header$split, 2);
var name = _header$split2[0];
var value = _header$split2[1];
if (!(name && value)) {
throw new _errors.ToolError('Headers should be specified as "Name: Value"');
}
additionalHeaders[name] = value;
if (!(name && value)) {
throw new _errors.ToolError('Headers should be specified as "Name: Value"');
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
additionalHeaders[name] = value;
}
return additionalHeaders;
}
}
}, function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(argv) {
var outputPath, additionalHeaders;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
outputPath = _path2.default.resolve(argv.output);
additionalHeaders = argv.header;
_context.next = 4;
return (0, _.downloadSchema)(argv.server, outputPath, additionalHeaders);
}, (() => {
var _ref = (0, _asyncToGenerator3.default)(function* (argv) {
const outputPath = _path2.default.resolve(argv.output);
const additionalHeaders = argv.header;
yield (0, _.downloadSchema)(argv.server, outputPath, additionalHeaders);
});
case 4:
case 'end':
return _context.stop();
}
}
}, _callee, undefined);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}()).command('generate [input...]', 'Generate code from a GraphQL schema and query documents', {
})()).command('generate [input...]', 'Generate code from a GraphQL schema and query documents', {
schema: {

@@ -154,7 +110,5 @@ demand: true,

}
}, function (argv) {
var inputPaths = argv.input.map(function (input) {
return _path2.default.resolve(input);
});
var options = { passthroughCustomScalars: argv["passthrough-custom-scalars"] };
}, argv => {
const inputPaths = argv.input.map(input => _path2.default.resolve(input));
const options = { passthroughCustomScalars: argv["passthrough-custom-scalars"] };
(0, _.generate)(inputPaths, argv.schema, argv.output, argv.target, options);

@@ -161,0 +115,0 @@ }).fail(function (message, error) {

@@ -12,10 +12,6 @@ 'use strict';

var _from = require('babel-runtime/core-js/array/from');
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _from2 = _interopRequireDefault(_from);
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _entries = require('babel-runtime/core-js/object/entries');
var _entries2 = _interopRequireDefault(_entries);
var _assign = require('babel-runtime/core-js/object/assign');

@@ -25,5 +21,5 @@

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _entries = require('babel-runtime/core-js/object/entries');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _entries2 = _interopRequireDefault(_entries);

@@ -42,2 +38,6 @@ var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');

var _from = require('babel-runtime/core-js/array/from');
var _from2 = _interopRequireDefault(_from);
var _values = require('babel-runtime/core-js/object/values');

@@ -47,5 +47,5 @@

var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _create = require('babel-runtime/core-js/object/create');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _create2 = _interopRequireDefault(_create);

@@ -56,14 +56,2 @@ var _set = require('babel-runtime/core-js/set');

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _create = require('babel-runtime/core-js/object/create');
var _create2 = _interopRequireDefault(_create);
exports.compileToIR = compileToIR;

@@ -80,20 +68,26 @@ exports.printIR = printIR;

const builtInScalarTypes = new _set2.default([_graphql.GraphQLString, _graphql.GraphQLInt, _graphql.GraphQLFloat, _graphql.GraphQLBoolean, _graphql.GraphQLID]);
function isBuiltInScalarType(type) {
return builtInScalarTypes.has(type);
}
// Parts of this code are adapted from graphql-js
function compileToIR(schema, document) {
var compiler = new Compiler(schema, document);
const compiler = new Compiler(schema, document);
var operations = (0, _create2.default)(null);
const operations = (0, _create2.default)(null);
compiler.operations.forEach(function (operation) {
compiler.operations.forEach(operation => {
operations[operation.name.value] = compiler.compileOperation(operation);
});
var fragments = (0, _create2.default)(null);
const fragments = (0, _create2.default)(null);
compiler.fragments.forEach(function (fragment) {
compiler.fragments.forEach(fragment => {
fragments[fragment.name.value] = compiler.compileFragment(fragment);
});
var typesUsed = compiler.typesUsed;
const typesUsed = compiler.typesUsed;

@@ -103,6 +97,4 @@ return { schema: schema, operations: operations, fragments: fragments, typesUsed: typesUsed };

var Compiler = exports.Compiler = function () {
function Compiler(schema, document) {
(0, _classCallCheck3.default)(this, Compiler);
class Compiler {
constructor(schema, document) {
this.schema = schema;

@@ -115,32 +107,11 @@

var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(document.definitions), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var definition = _step.value;
switch (definition.kind) {
case _graphql.Kind.OPERATION_DEFINITION:
this.operations.push(definition);
break;
case _graphql.Kind.FRAGMENT_DEFINITION:
this.fragmentMap[definition.name.value] = definition;
break;
}
for (const definition of document.definitions) {
switch (definition.kind) {
case _graphql.Kind.OPERATION_DEFINITION:
this.operations.push(definition);
break;
case _graphql.Kind.FRAGMENT_DEFINITION:
this.fragmentMap[definition.name.value] = definition;
break;
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}

@@ -151,580 +122,338 @@

(0, _createClass3.default)(Compiler, [{
key: 'addTypeUsed',
value: function addTypeUsed(type) {
if (type instanceof _graphql.GraphQLEnumType || type instanceof _graphql.GraphQLInputObjectType) {
this.typesUsedSet.add(type);
addTypeUsed(type) {
if (type instanceof _graphql.GraphQLEnumType || type instanceof _graphql.GraphQLInputObjectType || type instanceof _graphql.GraphQLScalarType && !isBuiltInScalarType(type)) {
this.typesUsedSet.add(type);
}
if (type instanceof _graphql.GraphQLInputObjectType) {
for (const field of (0, _values2.default)(type.getFields())) {
this.addTypeUsed((0, _graphql.getNamedType)(field.type));
}
if (type instanceof _graphql.GraphQLInputObjectType) {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
}
}
try {
for (var _iterator2 = (0, _getIterator3.default)((0, _values2.default)(type.getFields())), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var field = _step2.value;
get typesUsed() {
return (0, _from2.default)(this.typesUsedSet);
}
this.addTypeUsed((0, _graphql.getNamedType)(field.type));
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
}
}, {
key: 'fragmentNamed',
value: function fragmentNamed(fragmentName) {
return this.fragmentMap[fragmentName];
}
}, {
key: 'compileOperation',
value: function compileOperation(operationDefinition) {
var _this = this;
fragmentNamed(fragmentName) {
return this.fragmentMap[fragmentName];
}
var filePath = (0, _graphql2.filePathForNode)(operationDefinition);
var operationName = operationDefinition.name.value;
var operationType = operationDefinition.operation;
get fragments() {
return (0, _values2.default)(this.fragmentMap);
}
var variables = operationDefinition.variableDefinitions.map(function (node) {
var name = node.variable.name.value;
var type = (0, _graphql.typeFromAST)(_this.schema, node.type);
_this.addTypeUsed((0, _graphql.getNamedType)(type));
return { name: name, type: type };
});
compileOperation(operationDefinition) {
const filePath = (0, _graphql2.filePathForNode)(operationDefinition);
const operationName = operationDefinition.name.value;
const operationType = operationDefinition.operation;
var source = (0, _graphql.print)(withTypenameFieldAddedWhereNeeded(this.schema, operationDefinition));
const variables = operationDefinition.variableDefinitions.map(node => {
const name = node.variable.name.value;
const type = (0, _graphql.typeFromAST)(this.schema, node.type);
this.addTypeUsed((0, _graphql.getNamedType)(type));
return { name: name, type: type };
});
var rootType = (0, _graphql2.getOperationRootType)(this.schema, operationDefinition);
const source = (0, _graphql.print)(withTypenameFieldAddedWhereNeeded(this.schema, operationDefinition));
var groupedVisitedFragmentSet = new _map2.default();
var groupedFieldSet = this.collectFields(rootType, operationDefinition.selectionSet, undefined, groupedVisitedFragmentSet);
const rootType = (0, _graphql2.getOperationRootType)(this.schema, operationDefinition);
var fragmentsReferencedSet = (0, _create2.default)(null);
const groupedVisitedFragmentSet = new _map2.default();
const groupedFieldSet = this.collectFields(rootType, operationDefinition.selectionSet, undefined, groupedVisitedFragmentSet);
var _resolveFields = this.resolveFields(rootType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
const fragmentsReferencedSet = (0, _create2.default)(null);
var fields = _resolveFields.fields;
var _resolveFields = this.resolveFields(rootType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
var fragmentsReferenced = (0, _keys2.default)(fragmentsReferencedSet);
const fields = _resolveFields.fields;
return { filePath: filePath, operationName: operationName, operationType: operationType, variables: variables, source: source, fields: fields, fragmentsReferenced: fragmentsReferenced };
}
}, {
key: 'compileFragment',
value: function compileFragment(fragmentDefinition) {
var filePath = (0, _graphql2.filePathForNode)(fragmentDefinition);
var fragmentName = fragmentDefinition.name.value;
const fragmentsReferenced = (0, _keys2.default)(fragmentsReferencedSet);
var source = (0, _graphql.print)(withTypenameFieldAddedWhereNeeded(this.schema, fragmentDefinition));
return { filePath: filePath, operationName: operationName, operationType: operationType, variables: variables, source: source, fields: fields, fragmentsReferenced: fragmentsReferenced };
}
var typeCondition = (0, _graphql.typeFromAST)(this.schema, fragmentDefinition.typeCondition);
compileFragment(fragmentDefinition) {
const filePath = (0, _graphql2.filePathForNode)(fragmentDefinition);
const fragmentName = fragmentDefinition.name.value;
var groupedVisitedFragmentSet = new _map2.default();
var groupedFieldSet = this.collectFields(typeCondition, fragmentDefinition.selectionSet, undefined, groupedVisitedFragmentSet);
const source = (0, _graphql.print)(withTypenameFieldAddedWhereNeeded(this.schema, fragmentDefinition));
var fragmentsReferencedSet = (0, _create2.default)(null);
const typeCondition = (0, _graphql.typeFromAST)(this.schema, fragmentDefinition.typeCondition);
var _resolveFields2 = this.resolveFields(typeCondition, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
const groupedVisitedFragmentSet = new _map2.default();
const groupedFieldSet = this.collectFields(typeCondition, fragmentDefinition.selectionSet, undefined, groupedVisitedFragmentSet);
var fields = _resolveFields2.fields;
var fragmentSpreads = _resolveFields2.fragmentSpreads;
var inlineFragments = _resolveFields2.inlineFragments;
const fragmentsReferencedSet = (0, _create2.default)(null);
var fragmentsReferenced = (0, _keys2.default)(fragmentsReferencedSet);
var _resolveFields2 = this.resolveFields(typeCondition, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
return { filePath: filePath, fragmentName: fragmentName, source: source, typeCondition: typeCondition, fields: fields, fragmentSpreads: fragmentSpreads, inlineFragments: inlineFragments, fragmentsReferenced: fragmentsReferenced };
}
}, {
key: 'collectFields',
value: function collectFields(parentType, selectionSet) {
var groupedFieldSet = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, _create2.default)(null);
var groupedVisitedFragmentSet = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new _map2.default();
const fields = _resolveFields2.fields,
fragmentSpreads = _resolveFields2.fragmentSpreads,
inlineFragments = _resolveFields2.inlineFragments;
if (!(0, _graphql.isCompositeType)(parentType)) {
throw new Error('parentType should be a composite type, but is "' + String(parentType) + '"');
}
const fragmentsReferenced = (0, _keys2.default)(fragmentsReferencedSet);
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
return { filePath: filePath, fragmentName: fragmentName, source: source, typeCondition: typeCondition, fields: fields, fragmentSpreads: fragmentSpreads, inlineFragments: inlineFragments, fragmentsReferenced: fragmentsReferenced };
}
try {
for (var _iterator3 = (0, _getIterator3.default)(selectionSet.selections), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var selection = _step3.value;
collectFields(parentType, selectionSet) {
let groupedFieldSet = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : (0, _create2.default)(null);
let groupedVisitedFragmentSet = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : new _map2.default();
switch (selection.kind) {
case _graphql.Kind.FIELD:
{
var fieldName = selection.name.value;
var responseName = selection.alias ? selection.alias.value : fieldName;
if (!(0, _graphql.isCompositeType)(parentType)) {
throw new Error(`parentType should be a composite type, but is "${String(parentType)}"`);
}
var field = (0, _graphql2.getFieldDef)(this.schema, parentType, selection);
if (!field) {
throw new _graphql.GraphQLError('Cannot query field "' + fieldName + '" on type "' + String(parentType) + '"', [selection]);
}
for (const selection of selectionSet.selections) {
switch (selection.kind) {
case _graphql.Kind.FIELD:
{
const fieldName = selection.name.value;
const responseName = selection.alias ? selection.alias.value : fieldName;
if (groupedFieldSet) {
if (!groupedFieldSet[responseName]) {
groupedFieldSet[responseName] = [];
}
const field = (0, _graphql2.getFieldDef)(this.schema, parentType, selection);
if (!field) {
throw new _graphql.GraphQLError(`Cannot query field "${fieldName}" on type "${String(parentType)}"`, [selection]);
}
groupedFieldSet[responseName].push([parentType, {
responseName: responseName,
fieldName: fieldName,
args: argumentsFromAST(selection.arguments),
type: field.type,
directives: selection.directives,
selectionSet: selection.selectionSet
}]);
}
break;
if (groupedFieldSet) {
if (!groupedFieldSet[responseName]) {
groupedFieldSet[responseName] = [];
}
case _graphql.Kind.INLINE_FRAGMENT:
{
var typeCondition = selection.typeCondition;
var inlineFragmentType = typeCondition ? (0, _graphql.typeFromAST)(this.schema, typeCondition) : parentType;
var effectiveType = parentType instanceof _graphql.GraphQLObjectType ? parentType : inlineFragmentType;
groupedFieldSet[responseName].push([parentType, {
responseName: responseName,
fieldName: fieldName,
args: argumentsFromAST(selection.arguments),
type: field.type,
directives: selection.directives,
selectionSet: selection.selectionSet
}]);
}
break;
}
case _graphql.Kind.INLINE_FRAGMENT:
{
const typeCondition = selection.typeCondition;
const inlineFragmentType = typeCondition ? (0, _graphql.typeFromAST)(this.schema, typeCondition) : parentType;
this.collectFields(effectiveType, selection.selectionSet, groupedFieldSet, groupedVisitedFragmentSet);
break;
}
case _graphql.Kind.FRAGMENT_SPREAD:
{
var fragmentName = selection.name.value;
const effectiveType = parentType instanceof _graphql.GraphQLObjectType ? parentType : inlineFragmentType;
var fragment = this.fragmentNamed(fragmentName);
if (!fragment) throw new _graphql.GraphQLError('Cannot find fragment "' + fragmentName + '"');
this.collectFields(effectiveType, selection.selectionSet, groupedFieldSet, groupedVisitedFragmentSet);
break;
}
case _graphql.Kind.FRAGMENT_SPREAD:
{
const fragmentName = selection.name.value;
var _typeCondition = fragment.typeCondition;
var fragmentType = (0, _graphql.typeFromAST)(this.schema, _typeCondition);
const fragment = this.fragmentNamed(fragmentName);
if (!fragment) throw new _graphql.GraphQLError(`Cannot find fragment "${fragmentName}"`);
if (groupedVisitedFragmentSet) {
var visitedFragmentSet = groupedVisitedFragmentSet.get(parentType);
if (!visitedFragmentSet) {
visitedFragmentSet = {};
groupedVisitedFragmentSet.set(parentType, visitedFragmentSet);
}
const typeCondition = fragment.typeCondition;
const fragmentType = (0, _graphql.typeFromAST)(this.schema, typeCondition);
if (visitedFragmentSet[fragmentName]) continue;
visitedFragmentSet[fragmentName] = true;
}
if (groupedVisitedFragmentSet) {
let visitedFragmentSet = groupedVisitedFragmentSet.get(parentType);
if (!visitedFragmentSet) {
visitedFragmentSet = {};
groupedVisitedFragmentSet.set(parentType, visitedFragmentSet);
}
var _effectiveType = parentType instanceof _graphql.GraphQLObjectType ? parentType : fragmentType;
if (visitedFragmentSet[fragmentName]) continue;
visitedFragmentSet[fragmentName] = true;
}
this.collectFields(_effectiveType, fragment.selectionSet, null, groupedVisitedFragmentSet);
break;
}
const effectiveType = parentType instanceof _graphql.GraphQLObjectType ? parentType : fragmentType;
this.collectFields(effectiveType, fragment.selectionSet, null, groupedVisitedFragmentSet);
break;
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
return groupedFieldSet;
}
}, {
key: 'mergeSelectionSets',
value: function mergeSelectionSets(parentType, fieldSet, groupedVisitedFragmentSet) {
var groupedFieldSet = (0, _create2.default)(null);
var _iteratorNormalCompletion4 = true;
var _didIteratorError4 = false;
var _iteratorError4 = undefined;
return groupedFieldSet;
}
try {
for (var _iterator4 = (0, _getIterator3.default)(fieldSet), _step4; !(_iteratorNormalCompletion4 = (_step4 = _iterator4.next()).done); _iteratorNormalCompletion4 = true) {
var _step4$value = (0, _slicedToArray3.default)(_step4.value, 2);
mergeSelectionSets(parentType, fieldSet, groupedVisitedFragmentSet) {
const groupedFieldSet = (0, _create2.default)(null);
var field = _step4$value[1];
for (const _ref of fieldSet) {
var _ref2 = (0, _slicedToArray3.default)(_ref, 2);
var selectionSet = field.selectionSet;
const field = _ref2[1];
if (selectionSet) {
this.collectFields(parentType, selectionSet, groupedFieldSet, groupedVisitedFragmentSet);
}
}
} catch (err) {
_didIteratorError4 = true;
_iteratorError4 = err;
} finally {
try {
if (!_iteratorNormalCompletion4 && _iterator4.return) {
_iterator4.return();
}
} finally {
if (_didIteratorError4) {
throw _iteratorError4;
}
}
const selectionSet = field.selectionSet;
if (selectionSet) {
this.collectFields(parentType, selectionSet, groupedFieldSet, groupedVisitedFragmentSet);
}
return groupedFieldSet;
}
}, {
key: 'resolveFields',
value: function resolveFields(parentType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet) {
var _this2 = this;
var fields = [];
return groupedFieldSet;
}
var _iteratorNormalCompletion5 = true;
var _didIteratorError5 = false;
var _iteratorError5 = undefined;
resolveFields(parentType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet) {
const fields = [];
try {
for (var _iterator5 = (0, _getIterator3.default)((0, _entries2.default)(groupedFieldSet)), _step5; !(_iteratorNormalCompletion5 = (_step5 = _iterator5.next()).done); _iteratorNormalCompletion5 = true) {
var _step5$value = (0, _slicedToArray3.default)(_step5.value, 2);
for (let _ref3 of (0, _entries2.default)(groupedFieldSet)) {
var _ref4 = (0, _slicedToArray3.default)(_ref3, 2);
var responseName = _step5$value[0];
var fieldSet = _step5$value[1];
let responseName = _ref4[0];
let fieldSet = _ref4[1];
fieldSet = fieldSet.filter(function (_ref) {
var _ref2 = (0, _slicedToArray3.default)(_ref, 1);
fieldSet = fieldSet.filter((_ref5) => {
var _ref6 = (0, _slicedToArray3.default)(_ref5, 1);
var typeCondition = _ref2[0];
return (0, _graphql.isTypeSubTypeOf)(_this2.schema, parentType, typeCondition);
});
if (fieldSet.length < 1) continue;
let typeCondition = _ref6[0];
return (0, _graphql.isTypeSubTypeOf)(this.schema, parentType, typeCondition);
});
if (fieldSet.length < 1) continue;
var _fieldSet$ = (0, _slicedToArray3.default)(fieldSet[0], 2);
var _fieldSet$ = (0, _slicedToArray3.default)(fieldSet[0], 2);
var firstField = _fieldSet$[1];
const firstField = _fieldSet$[1];
var fieldName = firstField.fieldName;
var args = firstField.args;
var type = firstField.type;
const fieldName = firstField.fieldName;
const args = firstField.args;
const type = firstField.type;
var field = { responseName: responseName, fieldName: fieldName, type: type };
let field = { responseName: responseName, fieldName: fieldName, type: type };
if (args && args.length > 0) {
field.args = args;
}
if (args && args.length > 0) {
field.args = args;
}
var isConditional = fieldSet.some(function (_ref3) {
var _ref4 = (0, _slicedToArray3.default)(_ref3, 2);
const isConditional = fieldSet.some((_ref7) => {
var _ref8 = (0, _slicedToArray3.default)(_ref7, 2);
var field = _ref4[1];
let field = _ref8[1];
return field.directives && field.directives.some(function (directive) {
var directiveName = directive.name.value;
return directiveName == 'skip' || directiveName == 'include';
});
});
return field.directives && field.directives.some(directive => {
const directiveName = directive.name.value;
return directiveName == 'skip' || directiveName == 'include';
});
});
if (isConditional) {
field.isConditional = true;
}
if (isConditional) {
field.isConditional = true;
}
var bareType = (0, _graphql.getNamedType)(type);
const bareType = (0, _graphql.getNamedType)(type);
this.addTypeUsed(bareType);
this.addTypeUsed(bareType);
if ((0, _graphql.isCompositeType)(bareType)) {
var subSelectionGroupedVisitedFragmentSet = new _map2.default();
var subSelectionGroupedFieldSet = this.mergeSelectionSets(bareType, fieldSet, subSelectionGroupedVisitedFragmentSet);
if ((0, _graphql.isCompositeType)(bareType)) {
const subSelectionGroupedVisitedFragmentSet = new _map2.default();
const subSelectionGroupedFieldSet = this.mergeSelectionSets(bareType, fieldSet, subSelectionGroupedVisitedFragmentSet);
var _resolveFields3 = this.resolveFields(bareType, subSelectionGroupedFieldSet, subSelectionGroupedVisitedFragmentSet, fragmentsReferencedSet);
var _resolveFields3 = this.resolveFields(bareType, subSelectionGroupedFieldSet, subSelectionGroupedVisitedFragmentSet, fragmentsReferencedSet);
var _fields = _resolveFields3.fields;
var _fragmentSpreads = _resolveFields3.fragmentSpreads;
var _inlineFragments = _resolveFields3.inlineFragments;
const fields = _resolveFields3.fields,
fragmentSpreads = _resolveFields3.fragmentSpreads,
inlineFragments = _resolveFields3.inlineFragments;
(0, _assign2.default)(field, { fields: _fields, fragmentSpreads: _fragmentSpreads, inlineFragments: _inlineFragments });
}
fields.push(field);
}
} catch (err) {
_didIteratorError5 = true;
_iteratorError5 = err;
} finally {
try {
if (!_iteratorNormalCompletion5 && _iterator5.return) {
_iterator5.return();
}
} finally {
if (_didIteratorError5) {
throw _iteratorError5;
}
}
(0, _assign2.default)(field, { fields: fields, fragmentSpreads: fragmentSpreads, inlineFragments: inlineFragments });
}
var fragmentSpreads = this.fragmentSpreadsForParentType(parentType, groupedVisitedFragmentSet);
var inlineFragments = this.resolveInlineFragments(parentType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
fields.push(field);
}
if (fragmentsReferencedSet) {
_assign2.default.apply(Object, [fragmentsReferencedSet].concat((0, _toConsumableArray3.default)(groupedVisitedFragmentSet.values())));
const fragmentSpreads = this.fragmentSpreadsForParentType(parentType, groupedVisitedFragmentSet);
const inlineFragments = this.resolveInlineFragments(parentType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
// TODO: This is a really inefficient way of keeping track of fragments referenced by other fragments
// We need to either cache compiled fragments or find a way to make resolveFields smarter
var _iteratorNormalCompletion6 = true;
var _didIteratorError6 = false;
var _iteratorError6 = undefined;
if (fragmentsReferencedSet) {
_assign2.default.apply(Object, [fragmentsReferencedSet].concat((0, _toConsumableArray3.default)(groupedVisitedFragmentSet.values())));
try {
for (var _iterator6 = (0, _getIterator3.default)(fragmentSpreads), _step6; !(_iteratorNormalCompletion6 = (_step6 = _iterator6.next()).done); _iteratorNormalCompletion6 = true) {
var fragmentName = _step6.value;
// TODO: This is a really inefficient way of keeping track of fragments referenced by other fragments
// We need to either cache compiled fragments or find a way to make resolveFields smarter
for (let fragmentName of fragmentSpreads) {
const fragment = this.fragmentNamed(fragmentName);
if (!fragment) throw new _graphql.GraphQLError(`Cannot find fragment "${fragmentName}"`);
var fragment = this.fragmentNamed(fragmentName);
if (!fragment) throw new _graphql.GraphQLError('Cannot find fragment "' + fragmentName + '"');
var _compileFragment = this.compileFragment(fragment);
var _compileFragment = this.compileFragment(fragment);
const fragmentsReferencedFromFragment = _compileFragment.fragmentsReferenced;
var fragmentsReferencedFromFragment = _compileFragment.fragmentsReferenced;
var _iteratorNormalCompletion7 = true;
var _didIteratorError7 = false;
var _iteratorError7 = undefined;
try {
for (var _iterator7 = (0, _getIterator3.default)(fragmentsReferencedFromFragment), _step7; !(_iteratorNormalCompletion7 = (_step7 = _iterator7.next()).done); _iteratorNormalCompletion7 = true) {
var fragmentReferenced = _step7.value;
fragmentsReferencedSet[fragmentReferenced] = true;
}
} catch (err) {
_didIteratorError7 = true;
_iteratorError7 = err;
} finally {
try {
if (!_iteratorNormalCompletion7 && _iterator7.return) {
_iterator7.return();
}
} finally {
if (_didIteratorError7) {
throw _iteratorError7;
}
}
}
}
} catch (err) {
_didIteratorError6 = true;
_iteratorError6 = err;
} finally {
try {
if (!_iteratorNormalCompletion6 && _iterator6.return) {
_iterator6.return();
}
} finally {
if (_didIteratorError6) {
throw _iteratorError6;
}
}
for (let fragmentReferenced of fragmentsReferencedFromFragment) {
fragmentsReferencedSet[fragmentReferenced] = true;
}
}
return { fields: fields, fragmentSpreads: fragmentSpreads, inlineFragments: inlineFragments };
}
}, {
key: 'resolveInlineFragments',
value: function resolveInlineFragments(parentType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet) {
var _this3 = this;
return this.collectPossibleTypes(parentType, groupedFieldSet, groupedVisitedFragmentSet).map(function (typeCondition) {
var _resolveFields4 = _this3.resolveFields(typeCondition, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
return { fields: fields, fragmentSpreads: fragmentSpreads, inlineFragments: inlineFragments };
}
var fields = _resolveFields4.fields;
var fragmentSpreads = _resolveFields4.fragmentSpreads;
resolveInlineFragments(parentType, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet) {
return this.collectPossibleTypes(parentType, groupedFieldSet, groupedVisitedFragmentSet).map(typeCondition => {
var _resolveFields4 = this.resolveFields(typeCondition, groupedFieldSet, groupedVisitedFragmentSet, fragmentsReferencedSet);
return { typeCondition: typeCondition, fields: fields, fragmentSpreads: fragmentSpreads };
});
}
}, {
key: 'collectPossibleTypes',
value: function collectPossibleTypes(parentType, groupedFieldSet, groupedVisitedFragmentSet) {
if (!(0, _graphql.isAbstractType)(parentType)) return [];
const fields = _resolveFields4.fields,
fragmentSpreads = _resolveFields4.fragmentSpreads;
var possibleTypes = new _set2.default();
return { typeCondition: typeCondition, fields: fields, fragmentSpreads: fragmentSpreads };
});
}
var _iteratorNormalCompletion8 = true;
var _didIteratorError8 = false;
var _iteratorError8 = undefined;
collectPossibleTypes(parentType, groupedFieldSet, groupedVisitedFragmentSet) {
if (!(0, _graphql.isAbstractType)(parentType)) return [];
try {
for (var _iterator8 = (0, _getIterator3.default)((0, _values2.default)(groupedFieldSet)), _step8; !(_iteratorNormalCompletion8 = (_step8 = _iterator8.next()).done); _iteratorNormalCompletion8 = true) {
var fieldSet = _step8.value;
var _iteratorNormalCompletion10 = true;
var _didIteratorError10 = false;
var _iteratorError10 = undefined;
const possibleTypes = new _set2.default();
try {
for (var _iterator10 = (0, _getIterator3.default)(fieldSet), _step10; !(_iteratorNormalCompletion10 = (_step10 = _iterator10.next()).done); _iteratorNormalCompletion10 = true) {
var _step10$value = (0, _slicedToArray3.default)(_step10.value, 1);
for (const fieldSet of (0, _values2.default)(groupedFieldSet)) {
for (const _ref9 of fieldSet) {
var _ref10 = (0, _slicedToArray3.default)(_ref9, 1);
var typeCondition = _step10$value[0];
const typeCondition = _ref10[0];
if (this.schema.isPossibleType(parentType, typeCondition)) {
possibleTypes.add(typeCondition);
}
}
} catch (err) {
_didIteratorError10 = true;
_iteratorError10 = err;
} finally {
try {
if (!_iteratorNormalCompletion10 && _iterator10.return) {
_iterator10.return();
}
} finally {
if (_didIteratorError10) {
throw _iteratorError10;
}
}
}
if (this.schema.isPossibleType(parentType, typeCondition)) {
possibleTypes.add(typeCondition);
}
// Also include type conditions for fragment spreads
} catch (err) {
_didIteratorError8 = true;
_iteratorError8 = err;
} finally {
try {
if (!_iteratorNormalCompletion8 && _iterator8.return) {
_iterator8.return();
}
} finally {
if (_didIteratorError8) {
throw _iteratorError8;
}
}
}
}
if (groupedVisitedFragmentSet) {
var _iteratorNormalCompletion9 = true;
var _didIteratorError9 = false;
var _iteratorError9 = undefined;
try {
for (var _iterator9 = (0, _getIterator3.default)(groupedVisitedFragmentSet.keys()), _step9; !(_iteratorNormalCompletion9 = (_step9 = _iterator9.next()).done); _iteratorNormalCompletion9 = true) {
var effectiveType = _step9.value;
if (this.schema.isPossibleType(parentType, effectiveType)) {
possibleTypes.add(effectiveType);
}
}
} catch (err) {
_didIteratorError9 = true;
_iteratorError9 = err;
} finally {
try {
if (!_iteratorNormalCompletion9 && _iterator9.return) {
_iterator9.return();
}
} finally {
if (_didIteratorError9) {
throw _iteratorError9;
}
}
// Also include type conditions for fragment spreads
if (groupedVisitedFragmentSet) {
for (const effectiveType of groupedVisitedFragmentSet.keys()) {
if (this.schema.isPossibleType(parentType, effectiveType)) {
possibleTypes.add(effectiveType);
}
}
return (0, _from2.default)(possibleTypes);
}
}, {
key: 'fragmentSpreadsForParentType',
value: function fragmentSpreadsForParentType(parentType, groupedVisitedFragmentSet) {
if (!groupedVisitedFragmentSet) return [];
var fragmentSpreads = new _set2.default();
return (0, _from2.default)(possibleTypes);
}
var _iteratorNormalCompletion11 = true;
var _didIteratorError11 = false;
var _iteratorError11 = undefined;
fragmentSpreadsForParentType(parentType, groupedVisitedFragmentSet) {
if (!groupedVisitedFragmentSet) return [];
try {
for (var _iterator11 = (0, _getIterator3.default)(groupedVisitedFragmentSet), _step11; !(_iteratorNormalCompletion11 = (_step11 = _iterator11.next()).done); _iteratorNormalCompletion11 = true) {
var _step11$value = (0, _slicedToArray3.default)(_step11.value, 2);
let fragmentSpreads = new _set2.default();
var effectiveType = _step11$value[0];
var visitedFragmentSet = _step11$value[1];
for (const _ref11 of groupedVisitedFragmentSet) {
var _ref12 = (0, _slicedToArray3.default)(_ref11, 2);
if (!(0, _graphql2.isTypeProperSuperTypeOf)(this.schema, effectiveType, parentType)) continue;
const effectiveType = _ref12[0];
const visitedFragmentSet = _ref12[1];
var _iteratorNormalCompletion12 = true;
var _didIteratorError12 = false;
var _iteratorError12 = undefined;
if (!(0, _graphql2.isTypeProperSuperTypeOf)(this.schema, effectiveType, parentType)) continue;
try {
for (var _iterator12 = (0, _getIterator3.default)((0, _keys2.default)(visitedFragmentSet)), _step12; !(_iteratorNormalCompletion12 = (_step12 = _iterator12.next()).done); _iteratorNormalCompletion12 = true) {
var fragmentName = _step12.value;
fragmentSpreads.add(fragmentName);
}
} catch (err) {
_didIteratorError12 = true;
_iteratorError12 = err;
} finally {
try {
if (!_iteratorNormalCompletion12 && _iterator12.return) {
_iterator12.return();
}
} finally {
if (_didIteratorError12) {
throw _iteratorError12;
}
}
}
}
} catch (err) {
_didIteratorError11 = true;
_iteratorError11 = err;
} finally {
try {
if (!_iteratorNormalCompletion11 && _iterator11.return) {
_iterator11.return();
}
} finally {
if (_didIteratorError11) {
throw _iteratorError11;
}
}
for (const fragmentName of (0, _keys2.default)(visitedFragmentSet)) {
fragmentSpreads.add(fragmentName);
}
return (0, _from2.default)(fragmentSpreads);
}
}, {
key: 'typesUsed',
get: function get() {
return (0, _from2.default)(this.typesUsedSet);
}
}, {
key: 'fragments',
get: function get() {
return (0, _values2.default)(this.fragmentMap);
}
}]);
return Compiler;
}();
var typenameField = { kind: _graphql.Kind.FIELD, name: { kind: _graphql.Kind.NAME, value: '__typename' } };
return (0, _from2.default)(fragmentSpreads);
}
}
exports.Compiler = Compiler;
const typenameField = { kind: _graphql.Kind.FIELD, name: { kind: _graphql.Kind.NAME, value: '__typename' } };
function withTypenameFieldAddedWhereNeeded(schema, ast) {
var typeInfo = new _graphql.TypeInfo(schema);
const typeInfo = new _graphql.TypeInfo(schema);
return (0, _graphql.visit)(ast, (0, _graphql.visitWithTypeInfo)(typeInfo, {
leave: {
SelectionSet: function SelectionSet(node) {
var parentType = typeInfo.getParentType();
SelectionSet: node => {
const parentType = typeInfo.getParentType();

@@ -744,4 +473,4 @@ if ((0, _graphql.isAbstractType)(parentType)) {

function argumentsFromAST(args) {
return args.map(function (arg) {
var kind = arg.value.kind;
return args.map(arg => {
const kind = arg.value.kind;
if (kind === 'Variable') {

@@ -762,13 +491,9 @@ return {

function printIR(_ref5) {
var fields = _ref5.fields;
var inlineFragments = _ref5.inlineFragments;
var fragmentSpreads = _ref5.fragmentSpreads;
function printIR(_ref13) {
let fields = _ref13.fields,
inlineFragments = _ref13.inlineFragments,
fragmentSpreads = _ref13.fragmentSpreads;
return fields && (0, _printing.wrap)('<', (0, _printing.join)(fragmentSpreads, ', '), '> ') + (0, _printing.block)(fields.map(function (field) {
return field.name + ': ' + String(field.type) + (0, _printing.wrap)(' ', printIR(field));
}).concat(inlineFragments && inlineFragments.map(function (inlineFragment) {
return '' + String(inlineFragment.typeCondition) + (0, _printing.wrap)(' ', printIR(inlineFragment));
})));
return fields && (0, _printing.wrap)('<', (0, _printing.join)(fragmentSpreads, ', '), '> ') + (0, _printing.block)(fields.map(field => `${field.name}: ${String(field.type)}` + (0, _printing.wrap)(' ', printIR(field))).concat(inlineFragments && inlineFragments.map(inlineFragment => `${String(inlineFragment.typeCondition)}` + (0, _printing.wrap)(' ', printIR(inlineFragment)))));
}
//# sourceMappingURL=compilation.js.map

@@ -7,6 +7,2 @@ 'use strict';

var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
var _stringify = require('babel-runtime/core-js/json/stringify');

@@ -42,3 +38,3 @@

var defaultHeaders = {
const defaultHeaders = {
'Accept': 'application/json',

@@ -48,64 +44,31 @@ 'Content-Type': 'application/json'

exports.default = function () {
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(url, outputPath, additionalHeaders) {
var headers, result, response, schemaData;
return _regenerator2.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
headers = (0, _assign2.default)(defaultHeaders, additionalHeaders);
result = void 0;
_context.prev = 2;
_context.next = 5;
return (0, _nodeFetch2.default)(url, {
method: 'POST',
headers: headers,
body: (0, _stringify2.default)({ 'query': _utilities.introspectionQuery })
});
exports.default = (() => {
var _ref = (0, _asyncToGenerator3.default)(function* (url, outputPath, additionalHeaders) {
const headers = (0, _assign2.default)(defaultHeaders, additionalHeaders);
case 5:
response = _context.sent;
_context.next = 8;
return response.json();
let result;
try {
const response = yield (0, _nodeFetch2.default)(url, {
method: 'POST',
headers: headers,
body: (0, _stringify2.default)({ 'query': _utilities.introspectionQuery })
});
case 8:
result = _context.sent;
_context.next = 14;
break;
result = yield response.json();
} catch (error) {
throw new _errors.ToolError(`Error while fetching introspection query result: ${error.message}`);
}
case 11:
_context.prev = 11;
_context.t0 = _context['catch'](2);
throw new _errors.ToolError('Error while fetching introspection query result: ' + _context.t0.message);
if (result.errors) {
throw new _errors.ToolError(`Errors in introspection query result: ${result.errors}`);
}
case 14:
if (!result.errors) {
_context.next = 16;
break;
}
const schemaData = result;
if (!schemaData.data) {
throw new _errors.ToolError(`No introspection query result data found, server responded with: ${(0, _stringify2.default)(result)}`);
}
throw new _errors.ToolError('Errors in introspection query result: ' + result.errors);
_fs2.default.writeFileSync(outputPath, (0, _stringify2.default)(schemaData, null, 2));
});
case 16:
schemaData = result;
if (schemaData.data) {
_context.next = 19;
break;
}
throw new _errors.ToolError('No introspection query result data found, server responded with: ' + (0, _stringify2.default)(result));
case 19:
_fs2.default.writeFileSync(outputPath, (0, _stringify2.default)(schemaData, null, 2));
case 20:
case 'end':
return _context.stop();
}
}
}, _callee, this, [[2, 11]]);
}));
function downloadSchema(_x, _x2, _x3) {

@@ -116,3 +79,3 @@ return _ref.apply(this, arguments);

return downloadSchema;
}();
})();
//# sourceMappingURL=downloadSchema.js.map

@@ -7,6 +7,2 @@ 'use strict';

var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _create = require('babel-runtime/core-js/object/create');

@@ -36,3 +32,3 @@

var isRunningFromXcodeScript = process.env.XCODE_VERSION_ACTUAL;
const isRunningFromXcodeScript = process.env.XCODE_VERSION_ACTUAL;

@@ -43,27 +39,6 @@ function logError(error) {

} else if (error instanceof _graphql.GraphQLError) {
var fileName = error.source && error.source.name;
const fileName = error.source && error.source.name;
if (error.locations) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(error.locations), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var location = _step.value;
logErrorMessage(error.message, fileName, location.line);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
for (const location of error.locations) {
logErrorMessage(error.message, fileName, location.line);
}

@@ -83,6 +58,6 @@ } else {

// so Xcode will associate it with the right file and display the error inline
console.log(fileName + ':' + lineNumber + ': error: ' + message);
console.log(`${fileName}:${lineNumber}: error: ${message}`);
} else {
// Prefixing error output with 'error: ', so Xcode will display it as an error
console.log('error: ' + message);
console.log(`error: ${message}`);
}

@@ -89,0 +64,0 @@ } else {

@@ -51,16 +51,12 @@ 'use strict';

function generateSource(context) {
var generator = new _CodeGenerator2.default(context);
const generator = new _CodeGenerator2.default(context);
generator.printOnNewline('/* @flow */');
generator.printOnNewline('// This file was automatically generated and should not be edited.');
typeDeclarationForGraphQLType(context.typesUsed.forEach(function (type) {
return typeDeclarationForGraphQLType(generator, type);
}));
(0, _values2.default)(context.operations).forEach(function (operation) {
typeDeclarationForGraphQLType(context.typesUsed.forEach(type => typeDeclarationForGraphQLType(generator, type)));
(0, _values2.default)(context.operations).forEach(operation => {
interfaceVariablesDeclarationForOperation(generator, operation);
typeDeclarationForOperation(generator, operation);
});
(0, _values2.default)(context.fragments).forEach(function (operation) {
return typeDeclarationForFragment(generator, operation);
});
(0, _values2.default)(context.fragments).forEach(operation => typeDeclarationForFragment(generator, operation));

@@ -79,14 +75,12 @@ return generator.output;

function enumerationDeclaration(generator, type) {
var name = type.name;
var description = type.description;
const name = type.name,
description = type.description;
var values = type.getValues();
const values = type.getValues();
generator.printNewlineIfNeeded();
generator.printOnNewline(description && '// ' + description);
generator.printOnNewline('export type ' + name + ' =');
var nValues = values.length;
values.forEach(function (value, i) {
return generator.printOnNewline(' "' + value.value + '"' + (i === nValues - 1 ? ';' : ' |') + (0, _printing.wrap)(' // ', value.description));
});
generator.printOnNewline(description && `// ${description}`);
generator.printOnNewline(`export type ${name} =`);
const nValues = values.length;
values.forEach((value, i) => generator.printOnNewline(` "${value.value}"${i === nValues - 1 ? ';' : ' |'}${(0, _printing.wrap)(' // ', value.description)}`));
generator.printNewline();

@@ -96,7 +90,7 @@ }

function structDeclarationForInputObjectType(generator, type) {
var interfaceName = (0, _changeCase.pascalCase)(type.name);
const interfaceName = (0, _changeCase.pascalCase)(type.name);
(0, _language.typeDeclaration)(generator, {
interfaceName: interfaceName
}, function () {
var properties = propertiesFromFields(generator.context, (0, _values2.default)(type.getFields()));
}, () => {
const properties = propertiesFromFields(generator.context, (0, _values2.default)(type.getFields()));
propertyDeclarations(generator, properties, true);

@@ -107,17 +101,17 @@ });

function interfaceNameFromOperation(_ref) {
var operationName = _ref.operationName;
var operationType = _ref.operationType;
let operationName = _ref.operationName,
operationType = _ref.operationType;
switch (operationType) {
case 'query':
return (0, _changeCase.pascalCase)(operationName) + 'Query';
return `${(0, _changeCase.pascalCase)(operationName)}Query`;
break;
case 'mutation':
return (0, _changeCase.pascalCase)(operationName) + 'Mutation';
return `${(0, _changeCase.pascalCase)(operationName)}Mutation`;
break;
case 'subscription':
return (0, _changeCase.pascalCase)(operationName) + 'Subscription';
return `${(0, _changeCase.pascalCase)(operationName)}Subscription`;
break;
default:
throw new _graphql.GraphQLError('Unsupported operation type "' + operationType + '"');
throw new _graphql.GraphQLError(`Unsupported operation type "${operationType}"`);
}

@@ -127,8 +121,8 @@ }

function interfaceVariablesDeclarationForOperation(generator, _ref2) {
var operationName = _ref2.operationName;
var operationType = _ref2.operationType;
var variables = _ref2.variables;
var fields = _ref2.fields;
var fragmentsReferenced = _ref2.fragmentsReferenced;
var source = _ref2.source;
let operationName = _ref2.operationName,
operationType = _ref2.operationType,
variables = _ref2.variables,
fields = _ref2.fields,
fragmentsReferenced = _ref2.fragmentsReferenced,
source = _ref2.source;

@@ -138,8 +132,8 @@ if (!variables || variables.length < 1) {

}
var interfaceName = interfaceNameFromOperation({ operationName: operationName, operationType: operationType }) + 'Variables';
const interfaceName = `${interfaceNameFromOperation({ operationName: operationName, operationType: operationType })}Variables`;
(0, _language.typeDeclaration)(generator, {
interfaceName: interfaceName
}, function () {
var properties = propertiesFromFields(generator.context, variables);
}, () => {
const properties = propertiesFromFields(generator.context, variables);
propertyDeclarations(generator, properties, true);

@@ -150,18 +144,16 @@ });

function typeDeclarationForOperation(generator, _ref3) {
var operationName = _ref3.operationName;
var operationType = _ref3.operationType;
var variables = _ref3.variables;
var fields = _ref3.fields;
var fragmentSpreads = _ref3.fragmentSpreads;
var fragmentsReferenced = _ref3.fragmentsReferenced;
var source = _ref3.source;
let operationName = _ref3.operationName,
operationType = _ref3.operationType,
variables = _ref3.variables,
fields = _ref3.fields,
fragmentSpreads = _ref3.fragmentSpreads,
fragmentsReferenced = _ref3.fragmentsReferenced,
source = _ref3.source;
var interfaceName = interfaceNameFromOperation({ operationName: operationName, operationType: operationType });
const interfaceName = interfaceNameFromOperation({ operationName: operationName, operationType: operationType });
(0, _language.typeDeclaration)(generator, {
interfaceName: interfaceName,
extendTypes: fragmentSpreads ? fragmentSpreads.map(function (f) {
return (0, _changeCase.pascalCase)(f) + 'Fragment';
}) : null
}, function () {
var properties = propertiesFromFields(generator.context, fields);
extendTypes: fragmentSpreads ? fragmentSpreads.map(f => `${(0, _changeCase.pascalCase)(f)}Fragment`) : null
}, () => {
const properties = propertiesFromFields(generator.context, fields);
propertyDeclarations(generator, properties, true);

@@ -172,22 +164,18 @@ });

function typeDeclarationForFragment(generator, _ref4) {
var fragmentName = _ref4.fragmentName;
var typeCondition = _ref4.typeCondition;
var fields = _ref4.fields;
var inlineFragments = _ref4.inlineFragments;
var fragmentSpreads = _ref4.fragmentSpreads;
var source = _ref4.source;
let fragmentName = _ref4.fragmentName,
typeCondition = _ref4.typeCondition,
fields = _ref4.fields,
inlineFragments = _ref4.inlineFragments,
fragmentSpreads = _ref4.fragmentSpreads,
source = _ref4.source;
var interfaceName = (0, _changeCase.pascalCase)(fragmentName) + 'Fragment';
const interfaceName = `${(0, _changeCase.pascalCase)(fragmentName)}Fragment`;
(0, _language.typeDeclaration)(generator, {
interfaceName: interfaceName,
extendTypes: fragmentSpreads ? fragmentSpreads.map(function (f) {
return (0, _changeCase.pascalCase)(f) + 'Fragment';
}) : null
}, function () {
extendTypes: fragmentSpreads ? fragmentSpreads.map(f => `${(0, _changeCase.pascalCase)(f)}Fragment`) : null
}, () => {
var _propertiesFromFields;
var properties = (_propertiesFromFields = propertiesFromFields(generator.context, fields)).concat.apply(_propertiesFromFields, (0, _toConsumableArray3.default)((inlineFragments || []).map(function (fragment) {
return propertiesFromFields(generator.context, fragment.fields, true);
})));
const properties = (_propertiesFromFields = propertiesFromFields(generator.context, fields)).concat.apply(_propertiesFromFields, (0, _toConsumableArray3.default)((inlineFragments || []).map(fragment => propertiesFromFields(generator.context, fragment.fields, true))));

@@ -199,30 +187,28 @@ propertyDeclarations(generator, properties, true);

function propertiesFromFields(context, fields, forceNullable) {
return fields.map(function (field) {
return propertyFromField(context, field, forceNullable);
});
return fields.map(field => propertyFromField(context, field, forceNullable));
}
function propertyFromField(context, field, forceNullable) {
var fieldName = field.name;
var fieldType = field.type;
var description = field.description;
var fragmentSpreads = field.fragmentSpreads;
var inlineFragments = field.inlineFragments;
let fieldName = field.name,
fieldType = field.type,
description = field.description,
fragmentSpreads = field.fragmentSpreads,
inlineFragments = field.inlineFragments;
fieldName = fieldName || field.responseName;
var propertyName = fieldName;
const propertyName = fieldName;
var property = { fieldName: fieldName, fieldType: fieldType, propertyName: propertyName, description: description };
let property = { fieldName: fieldName, fieldType: fieldType, propertyName: propertyName, description: description };
var namedType = (0, _graphql.getNamedType)(fieldType);
const namedType = (0, _graphql.getNamedType)(fieldType);
if ((0, _graphql.isCompositeType)(namedType)) {
var bareTypeName = (0, _changeCase.pascalCase)(_inflected2.default.singularize(propertyName));
var typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType, bareTypeName);
var isArray = false;
const bareTypeName = (0, _changeCase.pascalCase)(_inflected2.default.singularize(propertyName));
const typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType, bareTypeName);
let isArray = false;
if (fieldType instanceof _graphql.GraphQLList) {
isArray = true;
}
var isNullable = true;
let isNullable = true;
if (fieldType instanceof _graphql.GraphQLNonNull && !forceNullable) {

@@ -236,4 +222,4 @@ isNullable = false;

} else {
var _typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType);
return (0, _extends3.default)({}, property, { typeName: _typeName, isComposite: false, fieldType: fieldType });
const typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType);
return (0, _extends3.default)({}, property, { typeName: typeName, isComposite: false, fieldType: fieldType });
}

@@ -244,10 +230,8 @@ }

if (!properties) return;
properties.forEach(function (property) {
properties.forEach(property => {
if (property.fields && property.fields.length > 0 || property.inlineFragments && property.inlineFragments.length > 0) {
(0, _language.propertyDeclaration)(generator, (0, _extends3.default)({}, property, { inInterface: inInterface }), function () {
(0, _language.propertyDeclaration)(generator, (0, _extends3.default)({}, property, { inInterface: inInterface }), () => {
var _propertiesFromFields2;
var properties = (_propertiesFromFields2 = propertiesFromFields(generator.context, property.fields)).concat.apply(_propertiesFromFields2, (0, _toConsumableArray3.default)((property.inlineFragments || []).map(function (fragment) {
return propertiesFromFields(generator.context, fragment.fields, true);
})));
const properties = (_propertiesFromFields2 = propertiesFromFields(generator.context, property.fields)).concat.apply(_propertiesFromFields2, (0, _toConsumableArray3.default)((property.inlineFragments || []).map(fragment => propertiesFromFields(generator.context, fragment.fields, true))));
propertyDeclarations(generator, properties);

@@ -254,0 +238,0 @@ });

@@ -13,7 +13,7 @@ 'use strict';

function typeDeclaration(generator, _ref, closure) {
var interfaceName = _ref.interfaceName;
let interfaceName = _ref.interfaceName;
generator.printNewlineIfNeeded();
generator.printNewline();
generator.print('export type ' + interfaceName + ' =');
generator.print(`export type ${interfaceName} =`);
generator.pushScope({ typeName: interfaceName });

@@ -26,13 +26,13 @@ generator.withinBlock(closure);

function propertyDeclaration(generator, _ref2, closure) {
var propertyName = _ref2.propertyName;
var typeName = _ref2.typeName;
var description = _ref2.description;
var isArray = _ref2.isArray;
var isNullable = _ref2.isNullable;
var inInterface = _ref2.inInterface;
var fragmentSpreads = _ref2.fragmentSpreads;
let propertyName = _ref2.propertyName,
typeName = _ref2.typeName,
description = _ref2.description,
isArray = _ref2.isArray,
isNullable = _ref2.isNullable,
inInterface = _ref2.inInterface,
fragmentSpreads = _ref2.fragmentSpreads;
generator.printOnNewline(description && '// ' + description);
generator.printOnNewline(description && `// ${description}`);
if (closure) {
generator.printOnNewline(propertyName + ':');
generator.printOnNewline(`${propertyName}:`);
if (isNullable) {

@@ -53,5 +53,3 @@ generator.print(' ?');

}
generator.print(fragmentSpreads.map(function (n) {
return n + 'Fragment';
}).join(' & ') + ' &');
generator.print(`${fragmentSpreads.map(n => `${n}Fragment`).join(' & ')} &`);
}

@@ -68,7 +66,5 @@ generator.pushScope({ typeName: propertyName });

} else if (fragmentSpreads && fragmentSpreads.length > 0) {
generator.printOnNewline(propertyName + ': ' + (isArray ? 'Array<' : '') + fragmentSpreads.map(function (n) {
return n + 'Fragment';
}).join(' & ') + (isArray ? '>' : ''));
generator.printOnNewline(`${propertyName}: ${isArray ? 'Array<' : ''}${fragmentSpreads.map(n => `${n}Fragment`).join(' & ')}${isArray ? '>' : ''}`);
} else {
generator.printOnNewline(propertyName + ': ' + typeName);
generator.printOnNewline(`${propertyName}: ${typeName}`);
}

@@ -80,6 +76,4 @@ generator.print(',');

if (!properties) return;
properties.forEach(function (property) {
return propertyDeclaration(generator, property);
});
properties.forEach(property => propertyDeclaration(generator, property));
}
//# sourceMappingURL=language.js.map

@@ -6,9 +6,2 @@ 'use strict';

});
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _builtInScalarMap;
exports.typeNameFromGraphQLType = typeNameFromGraphQLType;

@@ -22,8 +15,12 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const builtInScalarMap = {
[_graphql.GraphQLString.name]: 'string',
[_graphql.GraphQLInt.name]: 'number',
[_graphql.GraphQLFloat.name]: 'number',
[_graphql.GraphQLBoolean.name]: 'boolean',
[_graphql.GraphQLID.name]: 'string'
};
var builtInScalarMap = (_builtInScalarMap = {}, (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLString.name, 'string'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLInt.name, 'number'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLFloat.name, 'number'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLBoolean.name, 'boolean'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLID.name, 'string'), _builtInScalarMap);
function typeNameFromGraphQLType(context, type, bareTypeName) {
var nullable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
let nullable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;

@@ -34,5 +31,5 @@ if (type instanceof _graphql.GraphQLNonNull) {

var typeName = void 0;
let typeName;
if (type instanceof _graphql.GraphQLList) {
typeName = 'Array< ' + typeNameFromGraphQLType(context, type.ofType, bareTypeName, true) + ' >';
typeName = `Array< ${typeNameFromGraphQLType(context, type.ofType, bareTypeName, true)} >`;
} else if (type instanceof _graphql.GraphQLScalarType) {

@@ -39,0 +36,0 @@ typeName = builtInScalarMap[type.name] || (context.passthroughCustomScalars ? type.name : _graphql.GraphQLString);

@@ -38,12 +38,12 @@ 'use strict';

function generate(inputPaths, schemaPath, outputPath, target, options) {
var schema = (0, _loading.loadSchema)(schemaPath);
const schema = (0, _loading.loadSchema)(schemaPath);
var document = (0, _loading.loadAndMergeQueryDocuments)(inputPaths);
const document = (0, _loading.loadAndMergeQueryDocuments)(inputPaths);
(0, _validation.validateQueryDocument)(schema, document);
var context = (0, _compilation.compileToIR)(schema, document);
const context = (0, _compilation.compileToIR)(schema, document);
(0, _assign2.default)(context, options);
var output = void 0;
let output;
switch (target) {

@@ -50,0 +50,0 @@ case 'json':

@@ -29,5 +29,5 @@ 'use strict';

if (!_fs2.default.existsSync(schemaPath)) {
throw new _errors.ToolError('Cannot find GraphQL schema file: ' + schemaPath);
throw new _errors.ToolError(`Cannot find GraphQL schema file: ${schemaPath}`);
}
var schemaData = require(schemaPath);
const schemaData = require(schemaPath);

@@ -41,4 +41,4 @@ if (!schemaData.data && !schemaData.__schema) {

function loadAndMergeQueryDocuments(inputPaths) {
var sources = inputPaths.map(function (inputPath) {
var body = _fs2.default.readFileSync(inputPath, 'utf8');
const sources = inputPaths.map(inputPath => {
const body = _fs2.default.readFileSync(inputPath, 'utf8');
if (!body) {

@@ -48,10 +48,6 @@ return null;

return new _graphql.Source(body, inputPath);
}).filter(function (source) {
return source;
});
}).filter(source => source);
return (0, _graphql.concatAST)(sources.map(function (source) {
return (0, _graphql.parse)(source);
}));
return (0, _graphql.concatAST)(sources.map(source => (0, _graphql.parse)(source)));
}
//# sourceMappingURL=loading.js.map

@@ -49,2 +49,4 @@ 'use strict';

return serializeInputObjectType(type);
} else if (type instanceof _graphql.GraphQLScalarType) {
return serializeScalarType(type);
}

@@ -54,14 +56,12 @@ }

function serializeEnumType(type) {
var name = type.name;
var description = type.description;
const name = type.name,
description = type.description;
var values = type.getValues();
const values = type.getValues();
return {
kind: "EnumType",
kind: 'EnumType',
name: name,
description: description,
values: values.map(function (value) {
return { name: value.name, description: value.description };
})
values: values.map(value => ({ name: value.name, description: value.description }))
};

@@ -71,9 +71,9 @@ }

function serializeInputObjectType(type) {
var name = type.name;
var description = type.description;
const name = type.name,
description = type.description;
var fields = (0, _values2.default)(type.getFields());
const fields = (0, _values2.default)(type.getFields());
return {
kind: "InputObjectType",
kind: 'InputObjectType',
name: name,

@@ -84,2 +84,14 @@ description: description,

}
function serializeScalarType(type) {
const name = type.name,
description = type.description;
return {
kind: 'ScalarType',
name: name,
description: description
};
}
//# sourceMappingURL=serializeToJSON.js.map

@@ -7,10 +7,2 @@ 'use strict';

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
var _extends2 = require('babel-runtime/helpers/extends');

@@ -27,3 +19,2 @@

exports.initializerDeclarationForProperties = initializerDeclarationForProperties;
exports.mappedProperty = mappedProperty;
exports.structDeclarationForFragment = structDeclarationForFragment;

@@ -64,3 +55,3 @@ exports.structDeclarationForSelectionSet = structDeclarationForSelectionSet;

function generateSource(context) {
var generator = new _CodeGenerator2.default(context);
const generator = new _CodeGenerator2.default(context);

@@ -71,11 +62,11 @@ generator.printOnNewline('// This file was automatically generated and should not be edited.');

context.typesUsed.forEach(function (type) {
context.typesUsed.forEach(type => {
typeDeclarationForGraphQLType(generator, type);
});
(0, _values2.default)(context.operations).forEach(function (operation) {
(0, _values2.default)(context.operations).forEach(operation => {
classDeclarationForOperation(generator, operation);
});
(0, _values2.default)(context.fragments).forEach(function (fragment) {
(0, _values2.default)(context.fragments).forEach(fragment => {
structDeclarationForFragment(generator, fragment);

@@ -88,24 +79,24 @@ });

function classDeclarationForOperation(generator, _ref) {
var operationName = _ref.operationName;
var operationType = _ref.operationType;
var variables = _ref.variables;
var fields = _ref.fields;
var fragmentsReferenced = _ref.fragmentsReferenced;
var source = _ref.source;
let operationName = _ref.operationName,
operationType = _ref.operationType,
variables = _ref.variables,
fields = _ref.fields,
fragmentsReferenced = _ref.fragmentsReferenced,
source = _ref.source;
var className = void 0;
var protocol = void 0;
let className;
let protocol;
switch (operationType) {
case 'query':
className = (0, _changeCase.pascalCase)(operationName) + 'Query';
className = `${(0, _changeCase.pascalCase)(operationName)}Query`;
protocol = 'GraphQLQuery';
break;
case 'mutation':
className = (0, _changeCase.pascalCase)(operationName) + 'Mutation';
className = `${(0, _changeCase.pascalCase)(operationName)}Mutation`;
protocol = 'GraphQLMutation';
break;
default:
throw new _graphql.GraphQLError('Unsupported operation type "' + operationType + '"');
throw new _graphql.GraphQLError(`Unsupported operation type "${operationType}"`);
}

@@ -117,6 +108,6 @@

adoptedProtocols: [protocol]
}, function () {
}, () => {
if (source) {
generator.printOnNewline('public static let operationDefinition =');
generator.withIndent(function () {
generator.withIndent(() => {
(0, _values3.multilineString)(generator, source);

@@ -128,4 +119,4 @@ });

generator.printOnNewline('public static let queryDocument = operationDefinition');
fragmentsReferenced.forEach(function (fragment) {
generator.print('.appending(' + typeNameForFragmentName(fragment) + '.fragmentDefinition)');
fragmentsReferenced.forEach(fragment => {
generator.print(`.appending(${typeNameForFragmentName(fragment)}.fragmentDefinition)`);
});

@@ -135,26 +126,24 @@ }

if (variables && variables.length > 0) {
(function () {
var properties = variables.map(function (_ref2) {
var name = _ref2.name;
var type = _ref2.type;
const properties = variables.map((_ref2) => {
let name = _ref2.name,
type = _ref2.type;
var propertyName = (0, _changeCase.camelCase)(name);
var typeName = (0, _types.typeNameFromGraphQLType)(generator.context, type);
var isOptional = !(type instanceof _graphql.GraphQLNonNull || type.ofType instanceof _graphql.GraphQLNonNull);
return { name: name, propertyName: propertyName, type: type, typeName: typeName, isOptional: isOptional };
});
generator.printNewlineIfNeeded();
(0, _language.propertyDeclarations)(generator, properties);
generator.printNewlineIfNeeded();
initializerDeclarationForProperties(generator, properties);
generator.printNewlineIfNeeded();
generator.printOnNewline('public var variables: GraphQLMap?');
generator.withinBlock(function () {
generator.printOnNewline((0, _printing.wrap)('return [', (0, _printing.join)(properties.map(function (_ref3) {
var name = _ref3.name;
var propertyName = _ref3.propertyName;
return '"' + name + '": ' + propertyName;
}), ', '), ']'));
});
})();
const propertyName = (0, _language.escapeIdentifierIfNeeded)((0, _changeCase.camelCase)(name));
const typeName = (0, _types.typeNameFromGraphQLType)(generator.context, type);
const isOptional = !(type instanceof _graphql.GraphQLNonNull || type.ofType instanceof _graphql.GraphQLNonNull);
return { name: name, propertyName: propertyName, type: type, typeName: typeName, isOptional: isOptional };
});
generator.printNewlineIfNeeded();
(0, _language.propertyDeclarations)(generator, properties);
generator.printNewlineIfNeeded();
initializerDeclarationForProperties(generator, properties);
generator.printNewlineIfNeeded();
generator.printOnNewline(`public var variables: GraphQLMap?`);
generator.withinBlock(() => {
generator.printOnNewline((0, _printing.wrap)(`return [`, (0, _printing.join)(properties.map((_ref3) => {
let name = _ref3.name,
propertyName = _ref3.propertyName;
return `"${name}": ${propertyName}`;
}), ', '), `]`));
});
} else {

@@ -172,18 +161,18 @@ initializerDeclarationForProperties(generator, []);

function initializerDeclarationForProperties(generator, properties) {
generator.printOnNewline('public init');
generator.printOnNewline(`public init`);
generator.print('(');
generator.print((0, _printing.join)(properties.map(function (_ref4) {
var propertyName = _ref4.propertyName;
var type = _ref4.type;
var typeName = _ref4.typeName;
var isOptional = _ref4.isOptional;
return (0, _printing.join)([propertyName + ': ' + typeName, isOptional && ' = nil']);
generator.print((0, _printing.join)(properties.map((_ref4) => {
let propertyName = _ref4.propertyName,
type = _ref4.type,
typeName = _ref4.typeName,
isOptional = _ref4.isOptional;
return (0, _printing.join)([`${propertyName}: ${typeName}`, isOptional && ' = nil']);
}), ', '));
generator.print(')');
generator.withinBlock(function () {
properties.forEach(function (_ref5) {
var propertyName = _ref5.propertyName;
generator.withinBlock(() => {
properties.forEach((_ref5) => {
let propertyName = _ref5.propertyName;
generator.printOnNewline('self.' + propertyName + ' = ' + propertyName);
generator.printOnNewline(`self.${propertyName} = ${propertyName}`);
});

@@ -193,25 +182,12 @@ });

function mappedProperty(generator, _ref6, properties) {
var propertyName = _ref6.propertyName;
var propertyType = _ref6.propertyType;
function structDeclarationForFragment(generator, _ref6) {
let fragmentName = _ref6.fragmentName,
typeCondition = _ref6.typeCondition,
fields = _ref6.fields,
inlineFragments = _ref6.inlineFragments,
fragmentSpreads = _ref6.fragmentSpreads,
source = _ref6.source;
generator.printOnNewline('public var ' + propertyName + ': ' + propertyType);
generator.withinBlock(function () {
generator.printOnNewline((0, _printing.wrap)('return [', (0, _printing.join)(properties.map(function (_ref7) {
var propertyName = _ref7.propertyName;
return '"' + propertyName + '": ' + propertyName;
}), ', '), ']'));
});
}
const structName = (0, _changeCase.pascalCase)(fragmentName);
function structDeclarationForFragment(generator, _ref8) {
var fragmentName = _ref8.fragmentName;
var typeCondition = _ref8.typeCondition;
var fields = _ref8.fields;
var inlineFragments = _ref8.inlineFragments;
var fragmentSpreads = _ref8.fragmentSpreads;
var source = _ref8.source;
var structName = (0, _changeCase.pascalCase)(fragmentName);
structDeclarationForSelectionSet(generator, {

@@ -225,6 +201,6 @@ structName: structName,

inlineFragments: inlineFragments
}, function () {
}, () => {
if (source) {
generator.printOnNewline('public static let fragmentDefinition =');
generator.withIndent(function () {
generator.withIndent(() => {
(0, _values3.multilineString)(generator, source);

@@ -236,13 +212,13 @@ });

function structDeclarationForSelectionSet(generator, _ref9, beforeClosure) {
var structName = _ref9.structName;
var _ref9$adoptedProtocol = _ref9.adoptedProtocols;
var adoptedProtocols = _ref9$adoptedProtocol === undefined ? ['GraphQLMappable'] : _ref9$adoptedProtocol;
var parentType = _ref9.parentType;
var possibleTypes = _ref9.possibleTypes;
var fields = _ref9.fields;
var fragmentSpreads = _ref9.fragmentSpreads;
var inlineFragments = _ref9.inlineFragments;
function structDeclarationForSelectionSet(generator, _ref7, beforeClosure) {
let structName = _ref7.structName;
var _ref7$adoptedProtocol = _ref7.adoptedProtocols;
let adoptedProtocols = _ref7$adoptedProtocol === undefined ? ['GraphQLMappable'] : _ref7$adoptedProtocol,
parentType = _ref7.parentType,
possibleTypes = _ref7.possibleTypes,
fields = _ref7.fields,
fragmentSpreads = _ref7.fragmentSpreads,
inlineFragments = _ref7.inlineFragments;
(0, _language.structDeclaration)(generator, { structName: structName, adoptedProtocols: adoptedProtocols }, function () {
(0, _language.structDeclaration)(generator, { structName: structName, adoptedProtocols: adoptedProtocols }, () => {
if (beforeClosure) {

@@ -255,25 +231,23 @@ beforeClosure();

generator.printOnNewline('public static let possibleTypes = [');
generator.print((0, _printing.join)(possibleTypes.map(function (type) {
return '"' + String(type) + '"';
}), ', '));
generator.print((0, _printing.join)(possibleTypes.map(type => `"${String(type)}"`), ', '));
generator.print(']');
}
var properties = fields && propertiesFromFields(generator.context, fields);
const properties = fields && propertiesFromFields(generator.context, fields);
var fragmentProperties = fragmentSpreads && fragmentSpreads.map(function (fragmentName) {
var fragment = generator.context.fragments[fragmentName];
const fragmentProperties = fragmentSpreads && fragmentSpreads.map(fragmentName => {
const fragment = generator.context.fragments[fragmentName];
if (!fragment) {
throw new _graphql.GraphQLError('Cannot find fragment "' + fragmentName + '"');
throw new _graphql.GraphQLError(`Cannot find fragment "${fragmentName}"`);
}
var propertyName = (0, _changeCase.camelCase)(fragmentName);
var typeName = typeNameForFragmentName(fragmentName);
var isProperSuperType = (0, _graphql2.isTypeProperSuperTypeOf)(generator.context.schema, fragment.typeCondition, parentType);
const propertyName = (0, _changeCase.camelCase)(fragmentName);
const typeName = typeNameForFragmentName(fragmentName);
const isProperSuperType = (0, _graphql2.isTypeProperSuperTypeOf)(generator.context.schema, fragment.typeCondition, parentType);
return { propertyName: propertyName, typeName: typeName, bareTypeName: typeName, isProperSuperType: isProperSuperType };
});
var inlineFragmentProperties = inlineFragments && inlineFragments.map(function (inlineFragment) {
var bareTypeName = 'As' + (0, _changeCase.pascalCase)(String(inlineFragment.typeCondition));
var propertyName = (0, _changeCase.camelCase)(bareTypeName);
var typeName = bareTypeName + '?';
const inlineFragmentProperties = inlineFragments && inlineFragments.map(inlineFragment => {
const bareTypeName = 'As' + (0, _changeCase.pascalCase)(String(inlineFragment.typeCondition));
const propertyName = (0, _changeCase.camelCase)(bareTypeName);
const typeName = bareTypeName + '?';
return (0, _extends3.default)({}, inlineFragment, { propertyName: propertyName, typeName: typeName, bareTypeName: bareTypeName });

@@ -288,5 +262,5 @@ });

if ((0, _graphql.isAbstractType)(parentType)) {
generator.print(': String');
generator.print(`: String`);
} else {
generator.print(' = "' + String(parentType) + '"');
generator.print(` = "${String(parentType)}"`);
}

@@ -309,11 +283,9 @@ }

generator.printOnNewline('public init(reader: GraphQLResultReader) throws');
generator.withinBlock(function () {
generator.withinBlock(() => {
if (parentType && (0, _graphql.isAbstractType)(parentType)) {
generator.printOnNewline('__typename = try reader.value(for: Field(responseName: "__typename"))');
generator.printOnNewline(`__typename = try reader.value(for: Field(responseName: "__typename"))`);
}
if (properties) {
properties.forEach(function (property) {
return initializationForProperty(generator, property);
});
properties.forEach(property => initializationForProperty(generator, property));
}

@@ -323,19 +295,19 @@

generator.printNewlineIfNeeded();
fragmentProperties.forEach(function (_ref10) {
var propertyName = _ref10.propertyName;
var typeName = _ref10.typeName;
var bareTypeName = _ref10.bareTypeName;
var isProperSuperType = _ref10.isProperSuperType;
fragmentProperties.forEach((_ref8) => {
let propertyName = _ref8.propertyName,
typeName = _ref8.typeName,
bareTypeName = _ref8.bareTypeName,
isProperSuperType = _ref8.isProperSuperType;
generator.printOnNewline('let ' + propertyName + ' = try ' + typeName + '(reader: reader');
generator.printOnNewline(`let ${propertyName} = try ${typeName}(reader: reader`);
if (isProperSuperType) {
generator.print(')');
} else {
generator.print(', ifTypeMatches: __typename)');
generator.print(`, ifTypeMatches: __typename)`);
}
});
generator.printOnNewline('fragments = Fragments(');
generator.print((0, _printing.join)(fragmentSpreads.map(function (fragmentName) {
var propertyName = (0, _changeCase.camelCase)(fragmentName);
return propertyName + ': ' + propertyName;
generator.printOnNewline(`fragments = Fragments(`);
generator.print((0, _printing.join)(fragmentSpreads.map(fragmentName => {
const propertyName = (0, _changeCase.camelCase)(fragmentName);
return `${propertyName}: ${propertyName}`;
}), ', '));

@@ -347,8 +319,8 @@ generator.print(')');

generator.printNewlineIfNeeded();
inlineFragmentProperties.forEach(function (_ref11) {
var propertyName = _ref11.propertyName;
var typeName = _ref11.typeName;
var bareTypeName = _ref11.bareTypeName;
inlineFragmentProperties.forEach((_ref9) => {
let propertyName = _ref9.propertyName,
typeName = _ref9.typeName,
bareTypeName = _ref9.bareTypeName;
generator.printOnNewline(propertyName + ' = try ' + bareTypeName + '(reader: reader, ifTypeMatches: __typename)');
generator.printOnNewline(`${propertyName} = try ${bareTypeName}(reader: reader, ifTypeMatches: __typename)`);
});

@@ -361,7 +333,7 @@ }

structName: 'Fragments'
}, function () {
fragmentProperties.forEach(function (_ref12) {
var propertyName = _ref12.propertyName;
var typeName = _ref12.typeName;
var isProperSuperType = _ref12.isProperSuperType;
}, () => {
fragmentProperties.forEach((_ref10) => {
let propertyName = _ref10.propertyName,
typeName = _ref10.typeName,
isProperSuperType = _ref10.isProperSuperType;

@@ -377,3 +349,3 @@ if (!isProperSuperType) {

if (inlineFragmentProperties && inlineFragmentProperties.length > 0) {
inlineFragmentProperties.forEach(function (property) {
inlineFragmentProperties.forEach(property => {
structDeclarationForSelectionSet(generator, {

@@ -391,5 +363,3 @@ structName: property.bareTypeName,

if (properties) {
properties.filter(function (property) {
return property.isComposite;
}).forEach(function (property) {
properties.filter(property => property.isComposite).forEach(property => {
structDeclarationForSelectionSet(generator, {

@@ -407,26 +377,26 @@ structName: structNameForProperty(property),

function initializationForProperty(generator, _ref13) {
var propertyName = _ref13.propertyName;
var responseName = _ref13.responseName;
var fieldName = _ref13.fieldName;
var fieldArgs = _ref13.args;
var type = _ref13.type;
var isOptional = _ref13.isOptional;
function initializationForProperty(generator, _ref11) {
let propertyName = _ref11.propertyName,
responseName = _ref11.responseName,
fieldName = _ref11.fieldName,
fieldArgs = _ref11.args,
type = _ref11.type,
isOptional = _ref11.isOptional;
var isList = type instanceof _graphql.GraphQLList || type.ofType instanceof _graphql.GraphQLList;
const isList = type instanceof _graphql.GraphQLList || type.ofType instanceof _graphql.GraphQLList;
var methodName = isOptional ? isList ? 'optionalList' : 'optionalValue' : isList ? 'list' : 'value';
const methodName = isOptional ? isList ? 'optionalList' : 'optionalValue' : isList ? 'list' : 'value';
var fieldInitArgs = (0, _printing.join)(['responseName: "' + responseName + '"', responseName != fieldName ? 'fieldName: "' + fieldName + '"' : null, fieldArgs && fieldArgs.length && 'arguments: ' + dictionaryFromArguments(fieldArgs)], ', ');
var args = ['for: Field(' + fieldInitArgs + ')'];
const fieldInitArgs = (0, _printing.join)([`responseName: "${responseName}"`, responseName != fieldName ? `fieldName: "${fieldName}"` : null, fieldArgs && fieldArgs.length && `arguments: ${dictionaryFromArguments(fieldArgs)}`], ', ');
const args = [`for: Field(${fieldInitArgs})`];
generator.printOnNewline(propertyName + ' = try reader.' + methodName + '(' + (0, _printing.join)(args, ', ') + ')');
generator.printOnNewline(`${propertyName} = try reader.${methodName}(${(0, _printing.join)(args, ', ')})`);
}
function dictionaryFromArguments(args) {
return (0, _printing.wrap)('[', (0, _printing.join)(args.map(function (arg) {
return (0, _printing.wrap)('[', (0, _printing.join)(args.map(arg => {
if (arg.kind === 'Variable') {
return '"' + arg.name + '": reader.variables["' + arg.variableName + '"]';
return `"${arg.name}": reader.variables["${arg.variableName}"]`;
} else {
return '"' + arg.name + '": ' + (0, _values3.literalFromValue)(arg.value);
return `"${arg.name}": ${(0, _values3.literalFromValue)(arg.value)}`;
}

@@ -437,22 +407,20 @@ }), ', '), ']');

function propertiesFromFields(context, fields) {
return fields.map(function (field) {
return propertyFromField(context, field);
});
return fields.map(field => propertyFromField(context, field));
}
function propertyFromField(context, field) {
var name = field.name || field.responseName;
var propertyName = (0, _changeCase.camelCase)(name);
const name = field.name || field.responseName;
const propertyName = (0, _language.escapeIdentifierIfNeeded)((0, _changeCase.camelCase)(name));
var type = field.type;
var isOptional = field.isConditional || !(type instanceof _graphql.GraphQLNonNull || type.ofType instanceof _graphql.GraphQLNonNull);
var bareType = (0, _graphql.getNamedType)(type);
const type = field.type;
const isOptional = field.isConditional || !(type instanceof _graphql.GraphQLNonNull);
const bareType = (0, _graphql.getNamedType)(type);
if ((0, _graphql.isCompositeType)(bareType)) {
var bareTypeName = (0, _changeCase.pascalCase)(_inflected2.default.singularize(propertyName));
var typeName = (0, _types.typeNameFromGraphQLType)(context, type, bareTypeName, isOptional);
const bareTypeName = (0, _language.escapeIdentifierIfNeeded)((0, _changeCase.pascalCase)(_inflected2.default.singularize(name)));
const typeName = (0, _types.typeNameFromGraphQLType)(context, type, bareTypeName, isOptional);
return (0, _extends3.default)({}, field, { propertyName: propertyName, typeName: typeName, bareTypeName: bareTypeName, isOptional: isOptional, isComposite: true });
} else {
var _typeName = (0, _types.typeNameFromGraphQLType)(context, type, undefined, isOptional);
return (0, _extends3.default)({}, field, { propertyName: propertyName, typeName: _typeName, isOptional: isOptional, isComposite: false });
const typeName = (0, _types.typeNameFromGraphQLType)(context, type, undefined, isOptional);
return (0, _extends3.default)({}, field, { propertyName: propertyName, typeName: typeName, isOptional: isOptional, isComposite: false });
}

@@ -486,85 +454,44 @@ }

function enumerationDeclaration(generator, type) {
var name = type.name;
var description = type.description;
const name = type.name,
description = type.description;
var values = type.getValues();
const values = type.getValues();
generator.printNewlineIfNeeded();
generator.printOnNewline(description && '/// ' + description);
generator.printOnNewline('public enum ' + name + ': String');
generator.withinBlock(function () {
values.forEach(function (value) {
return generator.printOnNewline('case ' + (0, _changeCase.camelCase)(value.name) + ' = "' + value.value + '"' + (0, _printing.wrap)(' /// ', value.description));
});
generator.printOnNewline(description && `/// ${description}`);
generator.printOnNewline(`public enum ${name}: String`);
generator.withinBlock(() => {
values.forEach(value => generator.printOnNewline(`case ${(0, _changeCase.camelCase)(value.name)} = "${value.value}"${(0, _printing.wrap)(' /// ', value.description)}`));
});
generator.printNewline();
generator.printOnNewline('extension ' + name + ': JSONDecodable, JSONEncodable {}');
generator.printOnNewline(`extension ${name}: JSONDecodable, JSONEncodable {}`);
}
function structDeclarationForInputObjectType(generator, type) {
var structName = type.name;
var description = type.description;
const structName = type.name,
description = type.description;
var adoptedProtocols = ['GraphQLMapConvertible'];
var properties = propertiesFromFields(generator.context, (0, _values2.default)(type.getFields()));
const adoptedProtocols = ['GraphQLMapConvertible'];
const properties = propertiesFromFields(generator.context, (0, _values2.default)(type.getFields()));
(0, _language.structDeclaration)(generator, { structName: structName, description: description, adoptedProtocols: adoptedProtocols }, function () {
generator.printOnNewline('public var graphQLMap: GraphQLMap');
(0, _language.structDeclaration)(generator, { structName: structName, description: description, adoptedProtocols: adoptedProtocols }, () => {
generator.printOnNewline(`public var graphQLMap: GraphQLMap`);
// Compute permutations with and without optional properties
var permutations = [[]];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
generator.printNewlineIfNeeded();
generator.printOnNewline(`public init`);
generator.print('(');
generator.print((0, _printing.join)(properties.map((_ref12) => {
let propertyName = _ref12.propertyName,
type = _ref12.type,
typeName = _ref12.typeName,
isOptional = _ref12.isOptional;
return (0, _printing.join)([`${propertyName}: ${typeName}`, isOptional && ' = nil']);
}), ', '));
generator.print(')');
try {
var _loop = function _loop() {
var _ref16;
var property = _step.value;
permutations = (_ref16 = []).concat.apply(_ref16, (0, _toConsumableArray3.default)(permutations.map(function (prefix) {
if (property.isOptional) {
return [prefix, [].concat((0, _toConsumableArray3.default)(prefix), [property])];
} else {
return [[].concat((0, _toConsumableArray3.default)(prefix), [property])];
}
})));
};
for (var _iterator = (0, _getIterator3.default)(properties), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
permutations.forEach(function (properties) {
generator.printNewlineIfNeeded();
generator.printOnNewline('public init');
generator.print('(');
generator.print((0, _printing.join)(properties.map(function (_ref14) {
var propertyName = _ref14.propertyName;
var typeName = _ref14.typeName;
return propertyName + ': ' + typeName;
}), ', '));
generator.print(')');
generator.withinBlock(function () {
generator.printOnNewline((0, _printing.wrap)('graphQLMap = [', (0, _printing.join)(properties.map(function (_ref15) {
var propertyName = _ref15.propertyName;
return '"' + propertyName + '": ' + propertyName;
}), ', ') || ':', ']'));
});
generator.withinBlock(() => {
generator.printOnNewline((0, _printing.wrap)(`graphQLMap = [`, (0, _printing.join)(properties.map((_ref13) => {
let propertyName = _ref13.propertyName;
return `"${propertyName}": ${propertyName}`;
}), ', ') || ':', `]`));
});

@@ -571,0 +498,0 @@ });

@@ -7,2 +7,6 @@ 'use strict';

var _set = require('babel-runtime/core-js/set');
var _set2 = _interopRequireDefault(_set);
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');

@@ -19,2 +23,3 @@

exports.protocolPropertyDeclarations = protocolPropertyDeclarations;
exports.escapeIdentifierIfNeeded = escapeIdentifierIfNeeded;

@@ -26,8 +31,8 @@ var _printing = require('../utilities/printing');

function classDeclaration(generator, _ref, closure) {
var className = _ref.className;
var modifiers = _ref.modifiers;
var superClass = _ref.superClass;
let className = _ref.className,
modifiers = _ref.modifiers,
superClass = _ref.superClass;
var _ref$adoptedProtocols = _ref.adoptedProtocols;
var adoptedProtocols = _ref$adoptedProtocols === undefined ? [] : _ref$adoptedProtocols;
var properties = _ref.properties;
let adoptedProtocols = _ref$adoptedProtocols === undefined ? [] : _ref$adoptedProtocols,
properties = _ref.properties;

@@ -37,3 +42,3 @@ generator.printNewlineIfNeeded();

generator.print((0, _printing.wrap)('', (0, _printing.join)(modifiers, ' '), ' '));
generator.print('class ' + className);
generator.print(`class ${className}`);
generator.print((0, _printing.wrap)(': ', (0, _printing.join)([superClass].concat((0, _toConsumableArray3.default)(adoptedProtocols)), ', ')));

@@ -46,10 +51,10 @@ generator.pushScope({ typeName: className });

function structDeclaration(generator, _ref2, closure) {
var structName = _ref2.structName;
var description = _ref2.description;
let structName = _ref2.structName,
description = _ref2.description;
var _ref2$adoptedProtocol = _ref2.adoptedProtocols;
var adoptedProtocols = _ref2$adoptedProtocol === undefined ? [] : _ref2$adoptedProtocol;
let adoptedProtocols = _ref2$adoptedProtocol === undefined ? [] : _ref2$adoptedProtocol;
generator.printNewlineIfNeeded();
generator.printOnNewline(description && '/// ' + description);
generator.printOnNewline('public struct ' + structName);
generator.printOnNewline(description && `/// ${description}`);
generator.printOnNewline(`public struct ${structName}`);
generator.print((0, _printing.wrap)(': ', (0, _printing.join)(adoptedProtocols, ', ')));

@@ -62,8 +67,8 @@ generator.pushScope({ typeName: structName });

function propertyDeclaration(generator, _ref3) {
var propertyName = _ref3.propertyName;
var typeName = _ref3.typeName;
var description = _ref3.description;
let propertyName = _ref3.propertyName,
typeName = _ref3.typeName,
description = _ref3.description;
generator.printOnNewline('public let ' + propertyName + ': ' + typeName);
generator.print(description && ' /// ' + description);
generator.printOnNewline(`public let ${propertyName}: ${typeName}`);
generator.print(description && ` /// ${description}`);
}

@@ -73,14 +78,12 @@

if (!properties) return;
properties.forEach(function (property) {
return propertyDeclaration(generator, property);
});
properties.forEach(property => propertyDeclaration(generator, property));
}
function protocolDeclaration(generator, _ref4, closure) {
var protocolName = _ref4.protocolName;
var adoptedProtocols = _ref4.adoptedProtocols;
var properties = _ref4.properties;
let protocolName = _ref4.protocolName,
adoptedProtocols = _ref4.adoptedProtocols,
properties = _ref4.properties;
generator.printNewlineIfNeeded();
generator.printOnNewline('public protocol ' + protocolName);
generator.printOnNewline(`public protocol ${protocolName}`);
generator.print((0, _printing.wrap)(': ', (0, _printing.join)(adoptedProtocols, ', ')));

@@ -93,6 +96,6 @@ generator.pushScope({ typeName: protocolName });

function protocolPropertyDeclaration(generator, _ref5) {
var propertyName = _ref5.propertyName;
var typeName = _ref5.typeName;
let propertyName = _ref5.propertyName,
typeName = _ref5.typeName;
generator.printOnNewline('var ' + propertyName + ': ' + typeName + ' { get }');
generator.printOnNewline(`var ${propertyName}: ${typeName} { get }`);
}

@@ -102,6 +105,14 @@

if (!properties) return;
properties.forEach(function (property) {
return protocolPropertyDeclaration(generator, property);
});
properties.forEach(property => protocolPropertyDeclaration(generator, property));
}
const reservedKeywords = new _set2.default(['associatedtype', 'class', 'deinit', 'enum', 'extension', 'fileprivate', 'func', 'import', 'init', 'inout', 'internal', 'let', 'open', 'operator', 'private', 'protocol', 'public', 'static', 'struct', 'subscript', 'typealias', 'var', 'break', 'case', 'continue', 'default', 'defer', 'do', 'else', 'fallthrough', 'for', 'guard', 'if', 'in', 'repeat', 'return', 'switch', 'where', 'while', 'as', 'Any', 'catch', 'false', 'is', 'nil', 'rethrows', 'super', 'self', 'Self', 'throw', 'throws', 'true', 'try', 'associativity', 'convenience', 'dynamic', 'didSet', 'final', 'get', 'infix', 'indirect', 'lazy', 'left', 'mutating', 'none', 'nonmutating', 'optional', 'override', 'postfix', 'precedence', 'prefix', 'Protocol', 'required', 'right', 'set', 'Type', 'unowned', 'weak', 'willSet']);
function escapeIdentifierIfNeeded(identifier) {
if (reservedKeywords.has(identifier)) {
return '`' + identifier + '`';
} else {
return identifier;
}
}
//# sourceMappingURL=language.js.map

@@ -6,9 +6,2 @@ 'use strict';

});
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _builtInScalarMap;
exports.typeNameFromGraphQLType = typeNameFromGraphQLType;

@@ -22,6 +15,10 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const builtInScalarMap = {
[_graphql.GraphQLString.name]: 'String',
[_graphql.GraphQLInt.name]: 'Int',
[_graphql.GraphQLFloat.name]: 'Double',
[_graphql.GraphQLBoolean.name]: 'Bool',
[_graphql.GraphQLID.name]: 'GraphQLID'
};
var builtInScalarMap = (_builtInScalarMap = {}, (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLString.name, 'String'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLInt.name, 'Int'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLFloat.name, 'Double'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLBoolean.name, 'Bool'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLID.name, 'GraphQLID'), _builtInScalarMap);
function typeNameFromGraphQLType(context, type, bareTypeName, isOptional) {

@@ -34,3 +31,3 @@ if (type instanceof _graphql.GraphQLNonNull) {

var typeName = void 0;
let typeName;
if (type instanceof _graphql.GraphQLList) {

@@ -37,0 +34,0 @@ typeName = '[' + typeNameFromGraphQLType(context, type.ofType, bareTypeName) + ']';

@@ -19,6 +19,2 @@ 'use strict';

var _typeof2 = require('babel-runtime/helpers/typeof');
var _typeof3 = _interopRequireDefault(_typeof2);
exports.escapedString = escapedString;

@@ -37,6 +33,6 @@ exports.multilineString = multilineString;

function multilineString(context, string) {
var lines = string.split('\n');
lines.forEach(function (line, index) {
var isLastLine = index != lines.length - 1;
context.printOnNewline('"' + escapedString(line) + '"' + (isLastLine ? ' +' : ''));
const lines = string.split('\n');
lines.forEach((line, index) => {
const isLastLine = index != lines.length - 1;
context.printOnNewline(`"${escapedString(line)}"` + (isLastLine ? ' +' : ''));
});

@@ -48,10 +44,10 @@ }

return (0, _printing.wrap)('[', (0, _printing.join)(value.map(literalFromValue), ', '), ']');
} else if ((typeof value === 'undefined' ? 'undefined' : (0, _typeof3.default)(value)) === 'object') {
return (0, _printing.wrap)('[', (0, _printing.join)((0, _entries2.default)(value).map(function (_ref) {
} else if (typeof value === 'object') {
return (0, _printing.wrap)('[', (0, _printing.join)((0, _entries2.default)(value).map((_ref) => {
var _ref2 = (0, _slicedToArray3.default)(_ref, 2);
var key = _ref2[0];
var value = _ref2[1];
let key = _ref2[0],
value = _ref2[1];
return '"' + key + '": ' + literalFromValue(value);
return `"${key}": ${literalFromValue(value)}`;
}), ', '), ']');

@@ -58,0 +54,0 @@ } else {

@@ -51,16 +51,17 @@ 'use strict';

function generateSource(context) {
var generator = new _CodeGenerator2.default(context);
const generator = new _CodeGenerator2.default(context);
generator.printOnNewline('// This file was automatically generated and should not be edited.');
typeDeclarationForGraphQLType(context.typesUsed.forEach(function (type) {
return typeDeclarationForGraphQLType(generator, type);
}));
(0, _values2.default)(context.operations).forEach(function (operation) {
generator.printOnNewline('/* tslint:disable */');
typeDeclarationForGraphQLType(context.typesUsed.forEach(type => typeDeclarationForGraphQLType(generator, type)));
(0, _values2.default)(context.operations).forEach(operation => {
interfaceVariablesDeclarationForOperation(generator, operation);
interfaceDeclarationForOperation(generator, operation);
});
(0, _values2.default)(context.fragments).forEach(function (operation) {
return interfaceDeclarationForFragment(generator, operation);
});
(0, _values2.default)(context.fragments).forEach(operation => interfaceDeclarationForFragment(generator, operation));
generator.printOnNewline('/* tslint:enable */');
generator.printOnNewline();
return generator.output;

@@ -78,14 +79,12 @@ }

function enumerationDeclaration(generator, type) {
var name = type.name;
var description = type.description;
const name = type.name,
description = type.description;
var values = type.getValues();
const values = type.getValues();
generator.printNewlineIfNeeded();
generator.printOnNewline(description && '// ' + description);
generator.printOnNewline('export type ' + name + ' =');
var nValues = values.length;
values.forEach(function (value, i) {
return generator.printOnNewline(' "' + value.value + '"' + (i === nValues - 1 ? ';' : ' |') + (0, _printing.wrap)(' // ', value.description));
});
generator.printOnNewline(description && `// ${description}`);
generator.printOnNewline(`export type ${name} =`);
const nValues = values.length;
values.forEach((value, i) => generator.printOnNewline(` "${value.value}"${i === nValues - 1 ? ';' : ' |'}${(0, _printing.wrap)(' // ', value.description)}`));
generator.printNewline();

@@ -95,7 +94,7 @@ }

function structDeclarationForInputObjectType(generator, type) {
var interfaceName = (0, _changeCase.pascalCase)(type.name);
const interfaceName = (0, _changeCase.pascalCase)(type.name);
(0, _language.interfaceDeclaration)(generator, {
interfaceName: interfaceName
}, function () {
var properties = propertiesFromFields(generator.context, (0, _values2.default)(type.getFields()));
}, () => {
const properties = propertiesFromFields(generator.context, (0, _values2.default)(type.getFields()));
propertyDeclarations(generator, properties, true);

@@ -106,17 +105,17 @@ });

function interfaceNameFromOperation(_ref) {
var operationName = _ref.operationName;
var operationType = _ref.operationType;
let operationName = _ref.operationName,
operationType = _ref.operationType;
switch (operationType) {
case 'query':
return (0, _changeCase.pascalCase)(operationName) + 'Query';
return `${(0, _changeCase.pascalCase)(operationName)}Query`;
break;
case 'mutation':
return (0, _changeCase.pascalCase)(operationName) + 'Mutation';
return `${(0, _changeCase.pascalCase)(operationName)}Mutation`;
break;
case 'subscription':
return (0, _changeCase.pascalCase)(operationName) + 'Subscription';
return `${(0, _changeCase.pascalCase)(operationName)}Subscription`;
break;
default:
throw new _graphql.GraphQLError('Unsupported operation type "' + operationType + '"');
throw new _graphql.GraphQLError(`Unsupported operation type "${operationType}"`);
}

@@ -126,8 +125,8 @@ }

function interfaceVariablesDeclarationForOperation(generator, _ref2) {
var operationName = _ref2.operationName;
var operationType = _ref2.operationType;
var variables = _ref2.variables;
var fields = _ref2.fields;
var fragmentsReferenced = _ref2.fragmentsReferenced;
var source = _ref2.source;
let operationName = _ref2.operationName,
operationType = _ref2.operationType,
variables = _ref2.variables,
fields = _ref2.fields,
fragmentsReferenced = _ref2.fragmentsReferenced,
source = _ref2.source;

@@ -137,8 +136,8 @@ if (!variables || variables.length < 1) {

}
var interfaceName = interfaceNameFromOperation({ operationName: operationName, operationType: operationType }) + 'Variables';
const interfaceName = `${interfaceNameFromOperation({ operationName: operationName, operationType: operationType })}Variables`;
(0, _language.interfaceDeclaration)(generator, {
interfaceName: interfaceName
}, function () {
var properties = propertiesFromFields(generator.context, variables);
}, () => {
const properties = propertiesFromFields(generator.context, variables);
propertyDeclarations(generator, properties, true);

@@ -149,18 +148,16 @@ });

function interfaceDeclarationForOperation(generator, _ref3) {
var operationName = _ref3.operationName;
var operationType = _ref3.operationType;
var variables = _ref3.variables;
var fields = _ref3.fields;
var fragmentSpreads = _ref3.fragmentSpreads;
var fragmentsReferenced = _ref3.fragmentsReferenced;
var source = _ref3.source;
let operationName = _ref3.operationName,
operationType = _ref3.operationType,
variables = _ref3.variables,
fields = _ref3.fields,
fragmentSpreads = _ref3.fragmentSpreads,
fragmentsReferenced = _ref3.fragmentsReferenced,
source = _ref3.source;
var interfaceName = interfaceNameFromOperation({ operationName: operationName, operationType: operationType });
const interfaceName = interfaceNameFromOperation({ operationName: operationName, operationType: operationType });
(0, _language.interfaceDeclaration)(generator, {
interfaceName: interfaceName,
extendTypes: fragmentSpreads ? fragmentSpreads.map(function (f) {
return (0, _changeCase.pascalCase)(f) + 'Fragment';
}) : null
}, function () {
var properties = propertiesFromFields(generator.context, fields);
extendTypes: fragmentSpreads ? fragmentSpreads.map(f => `${(0, _changeCase.pascalCase)(f)}Fragment`) : null
}, () => {
const properties = propertiesFromFields(generator.context, fields);
propertyDeclarations(generator, properties, true);

@@ -171,22 +168,18 @@ });

function interfaceDeclarationForFragment(generator, _ref4) {
var fragmentName = _ref4.fragmentName;
var typeCondition = _ref4.typeCondition;
var fields = _ref4.fields;
var inlineFragments = _ref4.inlineFragments;
var fragmentSpreads = _ref4.fragmentSpreads;
var source = _ref4.source;
let fragmentName = _ref4.fragmentName,
typeCondition = _ref4.typeCondition,
fields = _ref4.fields,
inlineFragments = _ref4.inlineFragments,
fragmentSpreads = _ref4.fragmentSpreads,
source = _ref4.source;
var interfaceName = (0, _changeCase.pascalCase)(fragmentName) + 'Fragment';
const interfaceName = `${(0, _changeCase.pascalCase)(fragmentName)}Fragment`;
(0, _language.interfaceDeclaration)(generator, {
interfaceName: interfaceName,
extendTypes: fragmentSpreads ? fragmentSpreads.map(function (f) {
return (0, _changeCase.pascalCase)(f) + 'Fragment';
}) : null
}, function () {
extendTypes: fragmentSpreads ? fragmentSpreads.map(f => `${(0, _changeCase.pascalCase)(f)}Fragment`) : null
}, () => {
var _propertiesFromFields;
var properties = (_propertiesFromFields = propertiesFromFields(generator.context, fields)).concat.apply(_propertiesFromFields, (0, _toConsumableArray3.default)((inlineFragments || []).map(function (fragment) {
return propertiesFromFields(generator.context, fragment.fields, true);
})));
const properties = (_propertiesFromFields = propertiesFromFields(generator.context, fields)).concat.apply(_propertiesFromFields, (0, _toConsumableArray3.default)((inlineFragments || []).map(fragment => propertiesFromFields(generator.context, fragment.fields, true))));

@@ -198,26 +191,24 @@ propertyDeclarations(generator, properties, true);

function propertiesFromFields(context, fields, forceNullable) {
return fields.map(function (field) {
return propertyFromField(context, field, forceNullable);
});
return fields.map(field => propertyFromField(context, field, forceNullable));
}
function propertyFromField(context, field, forceNullable) {
var fieldName = field.name;
var fieldType = field.type;
var description = field.description;
var fragmentSpreads = field.fragmentSpreads;
var inlineFragments = field.inlineFragments;
let fieldName = field.name,
fieldType = field.type,
description = field.description,
fragmentSpreads = field.fragmentSpreads,
inlineFragments = field.inlineFragments;
fieldName = fieldName || field.responseName;
var propertyName = fieldName;
const propertyName = fieldName;
var property = { fieldName: fieldName, fieldType: fieldType, propertyName: propertyName, description: description };
let property = { fieldName: fieldName, fieldType: fieldType, propertyName: propertyName, description: description };
var namedType = (0, _graphql.getNamedType)(fieldType);
const namedType = (0, _graphql.getNamedType)(fieldType);
if ((0, _graphql.isCompositeType)(namedType)) {
var bareTypeName = (0, _changeCase.pascalCase)(_inflected2.default.singularize(propertyName));
var typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType, bareTypeName);
var isArray = false;
const bareTypeName = (0, _changeCase.pascalCase)(_inflected2.default.singularize(propertyName));
const typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType, bareTypeName);
let isArray = false;
if (fieldType instanceof _graphql.GraphQLList) {

@@ -228,3 +219,3 @@ isArray = true;

}
var isNullable = true;
let isNullable = true;
if (fieldType instanceof _graphql.GraphQLNonNull && !forceNullable) {

@@ -238,4 +229,4 @@ isNullable = false;

} else {
var _typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType);
return (0, _extends3.default)({}, property, { typeName: _typeName, isComposite: false, fieldType: fieldType });
const typeName = (0, _types.typeNameFromGraphQLType)(context, fieldType);
return (0, _extends3.default)({}, property, { typeName: typeName, isComposite: false, fieldType: fieldType });
}

@@ -246,10 +237,8 @@ }

if (!properties) return;
properties.forEach(function (property) {
properties.forEach(property => {
if (property.fields && property.fields.length > 0 || property.inlineFragments && property.inlineFragments.length > 0) {
(0, _language.propertyDeclaration)(generator, (0, _extends3.default)({}, property, { inInterface: inInterface }), function () {
(0, _language.propertyDeclaration)(generator, (0, _extends3.default)({}, property, { inInterface: inInterface }), () => {
var _propertiesFromFields2;
var properties = (_propertiesFromFields2 = propertiesFromFields(generator.context, property.fields)).concat.apply(_propertiesFromFields2, (0, _toConsumableArray3.default)((property.inlineFragments || []).map(function (fragment) {
return propertiesFromFields(generator.context, fragment.fields, true);
})));
const properties = (_propertiesFromFields2 = propertiesFromFields(generator.context, property.fields)).concat.apply(_propertiesFromFields2, (0, _toConsumableArray3.default)((property.inlineFragments || []).map(fragment => propertiesFromFields(generator.context, fragment.fields, true))));
propertyDeclarations(generator, properties);

@@ -256,0 +245,0 @@ });

@@ -13,10 +13,10 @@ 'use strict';

function interfaceDeclaration(generator, _ref, closure) {
var interfaceName = _ref.interfaceName;
var extendTypes = _ref.extendTypes;
let interfaceName = _ref.interfaceName,
extendTypes = _ref.extendTypes;
generator.printNewlineIfNeeded();
generator.printNewline();
generator.print('export interface ' + interfaceName);
generator.print(`export interface ${interfaceName}`);
if (extendTypes && extendTypes.length > 0) {
generator.print(' extends ' + extendTypes.join(', '));
generator.print(` extends ${extendTypes.join(', ')}`);
}

@@ -29,13 +29,13 @@ generator.pushScope({ typeName: interfaceName });

function propertyDeclaration(generator, _ref2, closure) {
var propertyName = _ref2.propertyName;
var typeName = _ref2.typeName;
var description = _ref2.description;
var isArray = _ref2.isArray;
var isNullable = _ref2.isNullable;
var inInterface = _ref2.inInterface;
var fragmentSpreads = _ref2.fragmentSpreads;
let propertyName = _ref2.propertyName,
typeName = _ref2.typeName,
description = _ref2.description,
isArray = _ref2.isArray,
isNullable = _ref2.isNullable,
inInterface = _ref2.inInterface,
fragmentSpreads = _ref2.fragmentSpreads;
generator.printOnNewline(description && '// ' + description);
generator.printOnNewline(description && `// ${description}`);
if (closure) {
generator.printOnNewline(propertyName + ':');
generator.printOnNewline(`${propertyName}:`);
if (isArray) {

@@ -45,5 +45,3 @@ generator.print(' Array<');

if (fragmentSpreads && fragmentSpreads.length > 0) {
generator.print(' ' + fragmentSpreads.map(function (n) {
return n + 'Fragment';
}).join(' & ') + ' &');
generator.print(` ${fragmentSpreads.map(n => `${n}Fragment`).join(' & ')} &`);
}

@@ -60,7 +58,5 @@ generator.pushScope({ typeName: propertyName });

} else if (fragmentSpreads && fragmentSpreads.length > 0) {
generator.printOnNewline(propertyName + ': ' + (isArray ? 'Array<' : '') + fragmentSpreads.map(function (n) {
return n + 'Fragment';
}).join(' & ') + (isArray ? '>' : ''));
generator.printOnNewline(`${propertyName}: ${isArray ? 'Array<' : ''}${fragmentSpreads.map(n => `${n}Fragment`).join(' & ')}${isArray ? '>' : ''}`);
} else {
generator.printOnNewline(propertyName + ': ' + typeName);
generator.printOnNewline(`${propertyName}: ${typeName}`);
}

@@ -72,6 +68,4 @@ generator.print(inInterface ? ';' : ',');

if (!properties) return;
properties.forEach(function (property) {
return propertyDeclaration(generator, property);
});
properties.forEach(property => propertyDeclaration(generator, property));
}
//# sourceMappingURL=language.js.map

@@ -6,9 +6,2 @@ 'use strict';

});
var _defineProperty2 = require('babel-runtime/helpers/defineProperty');
var _defineProperty3 = _interopRequireDefault(_defineProperty2);
var _builtInScalarMap;
exports.typeNameFromGraphQLType = typeNameFromGraphQLType;

@@ -22,8 +15,12 @@

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const builtInScalarMap = {
[_graphql.GraphQLString.name]: 'string',
[_graphql.GraphQLInt.name]: 'number',
[_graphql.GraphQLFloat.name]: 'number',
[_graphql.GraphQLBoolean.name]: 'boolean',
[_graphql.GraphQLID.name]: 'string'
};
var builtInScalarMap = (_builtInScalarMap = {}, (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLString.name, 'string'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLInt.name, 'number'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLFloat.name, 'number'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLBoolean.name, 'boolean'), (0, _defineProperty3.default)(_builtInScalarMap, _graphql.GraphQLID.name, 'string'), _builtInScalarMap);
function typeNameFromGraphQLType(context, type, bareTypeName) {
var nullable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
let nullable = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;

@@ -34,5 +31,5 @@ if (type instanceof _graphql.GraphQLNonNull) {

var typeName = void 0;
let typeName;
if (type instanceof _graphql.GraphQLList) {
typeName = 'Array< ' + typeNameFromGraphQLType(context, type.ofType, bareTypeName, true) + ' >';
typeName = `Array< ${typeNameFromGraphQLType(context, type.ofType, bareTypeName, true)} >`;
} else if (type instanceof _graphql.GraphQLScalarType) {

@@ -39,0 +36,0 @@ typeName = builtInScalarMap[type.name] || (context.passthroughCustomScalars ? type.name : _graphql.GraphQLString);

@@ -7,18 +7,6 @@ 'use strict';

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
var _createClass2 = require('babel-runtime/helpers/createClass');
var _createClass3 = _interopRequireDefault(_createClass2);
var _printing = require('./printing');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var CodeGenerator = function () {
function CodeGenerator(context) {
(0, _classCallCheck3.default)(this, CodeGenerator);
class CodeGenerator {
constructor(context) {
this.context = context;

@@ -34,71 +22,58 @@

(0, _createClass3.default)(CodeGenerator, [{
key: 'pushScope',
value: function pushScope(scope) {
this.scopeStack.push(scope);
pushScope(scope) {
this.scopeStack.push(scope);
}
popScope() {
return this.scopeStack.pop();
}
print(maybeString) {
if (maybeString) {
this.output += maybeString;
}
}, {
key: 'popScope',
value: function popScope() {
return this.scopeStack.pop();
}
printNewline() {
if (this.output) {
this.print('\n');
this.startOfIndentLevel = false;
}
}, {
key: 'print',
value: function print(maybeString) {
if (maybeString) {
this.output += maybeString;
}
}
printNewlineIfNeeded() {
if (!this.startOfIndentLevel) {
this.printNewline();
}
}, {
key: 'printNewline',
value: function printNewline() {
if (this.output) {
this.print('\n');
this.startOfIndentLevel = false;
}
}
}, {
key: 'printNewlineIfNeeded',
value: function printNewlineIfNeeded() {
if (!this.startOfIndentLevel) {
this.printNewline();
}
}
}, {
key: 'printOnNewline',
value: function printOnNewline(maybeString) {
if (maybeString) {
this.printNewline();
this.printIndent();
this.print(maybeString);
}
}
}, {
key: 'printIndent',
value: function printIndent() {
var indentation = ' '.repeat(this.indentLevel * this.indentWidth);
this.output += indentation;
}
}, {
key: 'withIndent',
value: function withIndent(closure) {
if (!closure) return;
}
this.indentLevel++;
this.startOfIndentLevel = true;
closure();
this.indentLevel--;
printOnNewline(maybeString) {
if (maybeString) {
this.printNewline();
this.printIndent();
this.print(maybeString);
}
}, {
key: 'withinBlock',
value: function withinBlock(closure) {
this.print(' {');
this.withIndent(closure);
this.printOnNewline('}');
}
}]);
return CodeGenerator;
}();
}
printIndent() {
const indentation = ' '.repeat(this.indentLevel * this.indentWidth);
this.output += indentation;
}
withIndent(closure) {
if (!closure) return;
this.indentLevel++;
this.startOfIndentLevel = true;
closure();
this.indentLevel--;
}
withinBlock(closure) {
this.print(' {');
this.withIndent(closure);
this.printOnNewline('}');
}
}
exports.default = CodeGenerator;
//# sourceMappingURL=CodeGenerator.js.map

@@ -20,3 +20,3 @@ 'use strict';

function filePathForNode(node) {
var name = node.loc.source && node.loc.source.name;
const name = node.loc.source && node.loc.source.name;
return name === "GraphQL" ? undefined : name;

@@ -26,3 +26,3 @@ }

function valueFromValueNode(valueNode) {
var kind = valueNode.kind;
const kind = valueNode.kind;

@@ -36,3 +36,3 @@ if (kind === 'IntValue' || kind === 'FloatValue') {

} else if (kind === 'ObjectValue') {
return valueNode.fields.reduce(function (object, field) {
return valueNode.fields.reduce((object, field) => {
object[field.name.value] = valueFromValueNode(field.value);

@@ -60,3 +60,3 @@ return object;

case 'mutation':
var mutationType = schema.getMutationType();
const mutationType = schema.getMutationType();
if (!mutationType) {

@@ -67,3 +67,3 @@ throw new GraphQLError('Schema is not configured for mutations', [operation]);

case 'subscription':
var subscriptionType = schema.getSubscriptionType();
const subscriptionType = schema.getSubscriptionType();
if (!subscriptionType) {

@@ -84,3 +84,3 @@ throw new GraphQLError('Schema is not configured for subscriptions', [operation]);

function getFieldDef(schema, parentType, fieldAST) {
var name = fieldAST.name.value;
const name = fieldAST.name.value;
if (name === _graphql.SchemaMetaFieldDef.name && schema.getQueryType() === parentType) {

@@ -87,0 +87,0 @@ return _graphql.SchemaMetaFieldDef;

@@ -17,5 +17,3 @@ 'use strict';

function join(maybeArray, separator) {
return maybeArray ? maybeArray.filter(function (x) {
return x;
}).join(separator || '') : '';
return maybeArray ? maybeArray.filter(x => x).join(separator || '') : '';
}

@@ -22,0 +20,0 @@

@@ -6,7 +6,2 @@ 'use strict';

});
var _getIterator2 = require('babel-runtime/core-js/get-iterator');
var _getIterator3 = _interopRequireDefault(_getIterator2);
exports.validateQueryDocument = validateQueryDocument;

@@ -21,34 +16,10 @@ exports.NoAnonymousQueries = NoAnonymousQueries;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function validateQueryDocument(schema, document) {
var rules = [NoAnonymousQueries, NoExplicitTypename, NoTypenameAlias].concat(_graphql.specifiedRules);
const rules = [NoAnonymousQueries, NoExplicitTypename, NoTypenameAlias].concat(_graphql.specifiedRules);
var validationErrors = (0, _graphql.validate)(schema, document, rules);
const validationErrors = (0, _graphql.validate)(schema, document, rules);
if (validationErrors && validationErrors.length > 0) {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = (0, _getIterator3.default)(validationErrors), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var error = _step.value;
(0, _errors.logError)(error);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
for (const error of validationErrors) {
(0, _errors.logError)(error);
}
throw new _errors.ToolError("Validation of GraphQL query document failed");

@@ -72,3 +43,3 @@ }

Field: function Field(node) {
var fieldName = node.name.value;
const fieldName = node.name.value;
if (fieldName == "__typename") {

@@ -84,3 +55,3 @@ context.reportError(new _graphql.GraphQLError('Apollo iOS inserts __typename automatically when needed, please do not include it explicitly', [node]));

Field: function Field(node) {
var aliasName = node.alias && node.alias.value;
const aliasName = node.alias && node.alias.value;
if (aliasName == "__typename") {

@@ -87,0 +58,0 @@ context.reportError(new _graphql.GraphQLError('Apollo iOS needs to be able to insert __typename when needed, please do not use it as an alias', [node]));

{
"name": "apollo-codegen",
"version": "0.10.1",
"version": "0.10.2",
"description": "Generate API code or type annotations based on a GraphQL schema and query documents",

@@ -22,4 +22,3 @@ "main": "./lib/index.js",

"babel-plugin-transform-runtime": "^6.12.0",
"babel-preset-es2015": "^6.13.2",
"babel-preset-stage-0": "^6.5.0",
"babel-preset-full-node4": "^1.0.0",
"babel-register": "^6.16.3",

@@ -36,3 +35,3 @@ "chai": "^3.5.0",

"change-case": "^3.0.0",
"graphql": "^0.8.1",
"graphql": "^0.9.1",
"inflected": "^1.1.7",

@@ -39,0 +38,0 @@ "mkdirp": "^0.5.1",

@@ -19,3 +19,2 @@ import { expect } from 'chai';

initializerDeclarationForProperties,
mappedProperty,
structDeclarationForFragment,

@@ -349,29 +348,2 @@ structDeclarationForSelectionSet,

describe('#mappedProperty()', function() {
it(`should generate variables property for a variable`, function() {
mappedProperty(this.generator, { propertyName: 'variables', propertyType: 'GraphQLMap?' }, [
{ propertyName: 'episode', type: new GraphQLNonNull(schema.getType('Episode')) }
]);
expect(this.generator.output).to.equal(stripIndent`
public var variables: GraphQLMap? {
return ["episode": episode]
}
`);
});
it(`should generate variables property for multiple variables`, function() {
mappedProperty(this.generator, { propertyName: 'variables', propertyType: 'GraphQLMap?' }, [
{ propertyName: 'episode', fieldType: schema.getType('Episode') },
{ propertyName: 'scene', fieldType: GraphQLString }
]);
expect(this.generator.output).to.equal(stripIndent`
public var variables: GraphQLMap? {
return ["episode": episode, "scene": scene]
}
`);
});
});
describe('#structDeclarationForFragment()', function() {

@@ -566,2 +538,28 @@ it(`should generate a struct declaration for a fragment with an abstract type condition`, function() {

it(`should escape reserved keywords in a struct declaration for a selection set`, function() {
structDeclarationForSelectionSet(this.generator, {
structName: 'Hero',
parentType: schema.getType('Character'),
fields: [
{
responseName: 'private',
fieldName: 'name',
type: GraphQLString
}
]
});
expect(this.generator.output).to.equal(stripIndent`
public struct Hero: GraphQLMappable {
public let __typename: String
public let \`private\`: String?
public init(reader: GraphQLResultReader) throws {
__typename = try reader.value(for: Field(responseName: "__typename"))
\`private\` = try reader.optionalValue(for: Field(responseName: "private", fieldName: "name"))
}
}
`);
});
it(`should generate a nested struct declaration for a selection set with subselections`, function() {

@@ -832,15 +830,3 @@ structDeclarationForSelectionSet(this.generator, {

public init(stars: Int) {
graphQLMap = ["stars": stars]
}
public init(stars: Int, favoriteColor: ColorInput?) {
graphQLMap = ["stars": stars, "favoriteColor": favoriteColor]
}
public init(stars: Int, commentary: String?) {
graphQLMap = ["stars": stars, "commentary": commentary]
}
public init(stars: Int, commentary: String?, favoriteColor: ColorInput?) {
public init(stars: Int, commentary: String? = nil, favoriteColor: ColorInput? = nil) {
graphQLMap = ["stars": stars, "commentary": commentary, "favoriteColor": favoriteColor]

@@ -851,30 +837,3 @@ }

});
it('should generate a valid struct declaration for a GraphQLInputObjectType with only optional fields', function() {
const generator = new CodeGenerator();
const inputType = new GraphQLInputObjectType({
name: 'OnlyOptionalFieldsInput',
fields: {
optionalString: { type: GraphQLString },
}
});
typeDeclarationForGraphQLType(generator, inputType);
expect(generator.output).to.equal(stripIndent`
public struct OnlyOptionalFieldsInput: GraphQLMapConvertible {
public var graphQLMap: GraphQLMap
public init() {
graphQLMap = [:]
}
public init(optionalString: String?) {
graphQLMap = ["optionalString": optionalString]
}
}
`);
});
});
});

@@ -49,2 +49,10 @@ import { expect } from 'chai';

it('should return [[String?]?]? for GraphQLList(GraphQLList(GraphQLString))', function() {
expect(typeNameFromGraphQLType({}, new GraphQLList(new GraphQLList(GraphQLString)))).to.equal('[[String?]?]?');
});
it('should return [[String?]]? for GraphQLList(GraphQLNonNull(GraphQLList(GraphQLString)))', function() {
expect(typeNameFromGraphQLType({}, new GraphQLList(new GraphQLNonNull(new GraphQLList(GraphQLString))))).to.equal('[[String?]]?');
});
it('should return Int? for GraphQLInt', function() {

@@ -51,0 +59,0 @@ expect(typeNameFromGraphQLType({}, GraphQLInt)).to.equal('Int?');

@@ -63,2 +63,3 @@ import { expect } from 'chai';

// This file was automatically generated and should not be edited.
/* tslint:disable */

@@ -70,2 +71,4 @@ export interface HeroNameQuery {

}
/* tslint:enable */
`);

@@ -87,2 +90,3 @@ });

// This file was automatically generated and should not be edited.
/* tslint:disable */

@@ -105,2 +109,4 @@ // The episodes in the Star Wars trilogy

}
/* tslint:enable */
`);

@@ -125,2 +131,3 @@ });

// This file was automatically generated and should not be edited.
/* tslint:disable */

@@ -146,2 +153,4 @@ // The episodes in the Star Wars trilogy

}
/* tslint:enable */
`);

@@ -170,2 +179,3 @@ });

// This file was automatically generated and should not be edited.
/* tslint:disable */

@@ -183,2 +193,4 @@ export interface HeroAndFriendsNamesQuery {

}
/* tslint:enable */
`);

@@ -210,2 +222,3 @@ });

// This file was automatically generated and should not be edited.
/* tslint:disable */

@@ -222,2 +235,4 @@ export interface HeroAndDetailsQuery {

}
/* tslint:enable */
`);

@@ -240,2 +255,3 @@ });

// This file was automatically generated and should not be edited.
/* tslint:disable */

@@ -275,2 +291,4 @@ // The episodes in the Star Wars trilogy

}
/* tslint:enable */
`);

@@ -299,2 +317,3 @@ });

// This file was automatically generated and should not be edited.
/* tslint:disable */

@@ -322,2 +341,4 @@ // The episodes in the Star Wars trilogy

}
/* tslint:enable */
`);

@@ -324,0 +345,0 @@ });

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc