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

babel-relay-plugin

Package Overview
Dependencies
Maintainers
8
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-relay-plugin - npm Package Compare versions

Comparing version 0.7.3 to 0.8.0

lib/buildDirective.js

47

lib/getBabelRelayPlugin.js

@@ -16,2 +16,4 @@ // @generated

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _require = require('./GraphQL');

@@ -23,7 +25,5 @@

var babelAdapter = require('./babelAdapter');
var generateHash = require('./generateHash');
var invariant = require('./invariant');
var util = require('util');
var HASH_LENGTH = 12;
var PROVIDES_MODULE = 'providesModule';

@@ -59,2 +59,3 @@

*/
Program: function Program(_ref2, state) {

@@ -66,7 +67,7 @@ var parent = _ref2.parent;

}
var documentName = undefined;
var documentName = void 0;
if (parent.comments && parent.comments.length) {
var docblock = parent.comments[0].value || '';
var propertyRegex = /@(\S+) *(\S*)/g;
var captures = undefined;
var captures = void 0;
while (captures = propertyRegex.exec(docblock)) {

@@ -83,5 +84,5 @@ var property = captures[1];

if (basename && !documentName) {
var captures = basename.match(/^[_A-Za-z][_0-9A-Za-z]*/);
if (captures) {
documentName = captures[0];
var _captures = basename.match(/^[_A-Za-z][_0-9A-Za-z]*/);
if (_captures) {
documentName = _captures[0];
}

@@ -92,2 +93,3 @@ }

/**

@@ -99,2 +101,3 @@ * Transform Relay.QL`...`.

var tag = path.get('tag');

@@ -110,13 +113,2 @@ var tagName = tag.matchesPattern('Relay.QL') ? 'Relay.QL' : tag.isIdentifier({ name: 'RelayQL' }) ? 'RelayQL' : null;

var _path$node$loc$start = path.node.loc.start;
var line = _path$node$loc$start.line;
var column = _path$node$loc$start.column;
var fragmentLocationID = generateHash(JSON.stringify({
filename: state.file.filename,
code: state.file.code,
line: line,
column: column
})).substring(0, HASH_LENGTH);
var p = path;

@@ -130,7 +122,6 @@ var propName = null;

var result = undefined;
var result = void 0;
try {
result = transformer.transform(t, node.quasi, {
documentName: documentName,
fragmentLocationID: fragmentLocationID,
tagName: tagName,

@@ -148,3 +139,4 @@ propName: propName

var errorMessages = [];
if (validationErrors && sourceText) {
var isValidationError = !!(validationErrors && sourceText);
if (isValidationError) {
var sourceLines = sourceText.split('\n');

@@ -170,11 +162,12 @@ validationErrors.forEach(function (_ref3) {

}
var runtimeMessage = util.format('GraphQL validation/transform error ``%s`` in file `%s`.', errorMessages.join(' '), filename);
var runtimeMessage = util.format('%s error ``%s`` in file `%s`. Try updating your GraphQL ' + 'schema if an argument/field/type was recently added.', isValidationError ? 'GraphQL validation' : 'Relay transform', errorMessages.join(' '), filename);
result = t.callExpression(t.functionExpression(null, [], t.blockStatement([t.throwStatement(t.newExpression(t.identifier('Error'), [t.valueToNode(runtimeMessage)]))])), []);
if (options.debug) {
if (state.opts && state.opts.enforceSchema) {
throw new Error(util.format(errorMessages.length ? 'Aborting due to a %s error:\n\n%s\n' : 'Aborting due to %s errors:\n\n%s\n', isValidationError ? 'GraphQL validation' : 'Relay transform', errorMessages.map(function (errorMessage) {
return ' - ' + errorMessage;
}).join('\n')));
} else if (options.debug) {
console.error(error.stack);
}
if (state.opts && state.opts.enforceSchema) {
throw new Error('Aborting due to GraphQL validation/transform error(s).');
}
}

@@ -196,3 +189,3 @@ // For babel 5 compatibility

var introspection = typeof schemaProvider === 'function' ? schemaProvider() : schemaProvider;
invariant(typeof introspection === 'object' && introspection && typeof introspection.__schema === 'object' && introspection.__schema, 'Invalid introspection data supplied to `getBabelRelayPlugin()`. The ' + 'resulting schema is not an object with a `__schema` property.');
invariant((typeof introspection === 'undefined' ? 'undefined' : _typeof(introspection)) === 'object' && introspection && _typeof(introspection.__schema) === 'object' && introspection.__schema, 'Invalid introspection data supplied to `getBabelRelayPlugin()`. The ' + 'resulting schema is not an object with a `__schema` property.');
return buildClientSchema(introspection);

@@ -199,0 +192,0 @@ }

@@ -16,4 +16,14 @@ // @generated

var types = require('./GraphQL').type;
var TypeKind = require('./GraphQL').type_introspection.TypeKind;
var BOOLEAN = {
kind: TypeKind.SCALAR,
name: 'Boolean'
};
var STRING = {
kind: TypeKind.SCALAR,
name: 'String'
};
module.exports = {

@@ -25,3 +35,3 @@ name: 'relay',

description: 'Marks a connection field as containing nodes without `id` fields. ' + 'This is used to silence the warning when diffing connections.',
type: types.GraphQLBoolean,
type: BOOLEAN,
defaultValue: null

@@ -31,3 +41,3 @@ }, {

description: 'Marks a fragment as static. A static fragment will share the same ' + 'identity regardless of how many times the expression is evaluated.',
type: types.GraphQLBoolean,
type: BOOLEAN,
defaultValue: null

@@ -37,3 +47,3 @@ }, {

description: 'Marks a fragment as intended for pattern matching (as opposed to ' + 'fetching).',
type: types.GraphQLBoolean,
type: BOOLEAN,
defaultValue: null

@@ -43,4 +53,12 @@ }, {

description: 'Marks a fragment as being backed by a GraphQLList',
type: types.GraphQLBoolean,
type: BOOLEAN,
defaultValue: null
}, {
name: 'variables',
description: 'Selectively pass variables down into a fragment.',
type: {
kind: TypeKind.LIST,
ofType: STRING
},
defaultValue: null
}],

@@ -47,0 +65,0 @@ onOperation: false,

@@ -14,3 +14,2 @@ // @generated

// TODO: Import types from `graphql`.
'use strict';

@@ -20,9 +19,9 @@

var _get = function get(_x, _x2, _x3) { var _again = true; _function: while (_again) { var object = _x, property = _x2, receiver = _x3; _again = false; if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { _x = parent; _x2 = property; _x3 = receiver; _again = true; desc = parent = undefined; continue _function; } } else if ('value' in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } } };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
function _inherits(subClass, superClass) { if (typeof superClass !== 'function' && superClass !== null) { throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -32,13 +31,19 @@ var _require = require('./GraphQL');

var types = _require.type;
var _require$type_introspection = _require.type_introspection;
var SchemaMetaFieldDef = _require$type_introspection.SchemaMetaFieldDef;
var TypeMetaFieldDef = _require$type_introspection.TypeMetaFieldDef;
var TypeNameMetaFieldDef = _require$type_introspection.TypeNameMetaFieldDef;
var _require$type_introsp = _require.type_introspection;
var SchemaMetaFieldDef = _require$type_introsp.SchemaMetaFieldDef;
var TypeMetaFieldDef = _require$type_introsp.TypeMetaFieldDef;
var TypeNameMetaFieldDef = _require$type_introsp.TypeNameMetaFieldDef;
var GraphQLRelayDirective = require('./GraphQLRelayDirective');
var buildDirective = require('./buildDirective');
var find = require('./find');
var invariant = require('./invariant');
var RelayQLNode = (function () {
var GraphQLRelayDirectiveInstance = buildDirective(GraphQLRelayDirective);
// TODO: Import types from `graphql`.
var RelayQLNode = function () {
function RelayQLNode(context, ast) {

@@ -118,5 +123,5 @@ _classCallCheck(this, RelayQLNode);

return RelayQLNode;
})();
}();
var RelayQLDefinition = (function (_RelayQLNode) {
var RelayQLDefinition = function (_RelayQLNode) {
_inherits(RelayQLDefinition, _RelayQLNode);

@@ -127,3 +132,3 @@

_get(Object.getPrototypeOf(RelayQLDefinition.prototype), 'constructor', this).apply(this, arguments);
return _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLDefinition).apply(this, arguments));
}

@@ -139,5 +144,5 @@

return RelayQLDefinition;
})(RelayQLNode);
}(RelayQLNode);
var RelayQLFragment = (function (_RelayQLDefinition) {
var RelayQLFragment = function (_RelayQLDefinition) {
_inherits(RelayQLFragment, _RelayQLDefinition);

@@ -149,3 +154,3 @@

var relayDirectiveArgs = {};
var relayDirective = (ast.directives || []).find(function (directive) {
var relayDirective = find(ast.directives || [], function (directive) {
return directive.name.value === 'relay';

@@ -165,6 +170,8 @@ });

_get(Object.getPrototypeOf(RelayQLFragment.prototype), 'constructor', this).call(this, _extends({}, context, { isPattern: isPattern }), ast);
this.hasStaticFragmentID = isStaticFragment;
this.parentType = parentType;
this.staticFragmentID = null;
var _this4 = _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLFragment).call(this, _extends({}, context, { isPattern: isPattern }), ast));
_this4.hasStaticFragmentID = isStaticFragment;
_this4.parentType = parentType;
_this4.staticFragmentID = null;
return _this4;
}

@@ -177,6 +184,5 @@

var suffix = this.context.generateID();
// The fragmentLocationID is the same for all inline/nested fragments
// within each Relay.QL tagged template expression; the auto-incrementing
// suffix distinguishes these fragments from each other.
this.staticFragmentID = this.context.fragmentLocationID + ':' + suffix;
var _name = this.getName();
invariant(_name, 'Static fragments require a name. Use `fragment NAME on %s { ... }`.', this.getType().getName({ modifiers: true }));
this.staticFragmentID = _name + ':' + suffix;
}

@@ -206,5 +212,5 @@ return this.staticFragmentID;

return RelayQLFragment;
})(RelayQLDefinition);
}(RelayQLDefinition);
var RelayQLMutation = (function (_RelayQLDefinition2) {
var RelayQLMutation = function (_RelayQLDefinition2) {
_inherits(RelayQLMutation, _RelayQLDefinition2);

@@ -215,3 +221,3 @@

_get(Object.getPrototypeOf(RelayQLMutation.prototype), 'constructor', this).apply(this, arguments);
return _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLMutation).apply(this, arguments));
}

@@ -227,5 +233,5 @@

return RelayQLMutation;
})(RelayQLDefinition);
}(RelayQLDefinition);
var RelayQLQuery = (function (_RelayQLDefinition3) {
var RelayQLQuery = function (_RelayQLDefinition3) {
_inherits(RelayQLQuery, _RelayQLDefinition3);

@@ -236,3 +242,3 @@

_get(Object.getPrototypeOf(RelayQLQuery.prototype), 'constructor', this).apply(this, arguments);
return _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLQuery).apply(this, arguments));
}

@@ -248,5 +254,5 @@

return RelayQLQuery;
})(RelayQLDefinition);
}(RelayQLDefinition);
var RelayQLSubscription = (function (_RelayQLDefinition4) {
var RelayQLSubscription = function (_RelayQLDefinition4) {
_inherits(RelayQLSubscription, _RelayQLDefinition4);

@@ -257,3 +263,3 @@

_get(Object.getPrototypeOf(RelayQLSubscription.prototype), 'constructor', this).apply(this, arguments);
return _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLSubscription).apply(this, arguments));
}

@@ -269,5 +275,5 @@

return RelayQLSubscription;
})(RelayQLDefinition);
}(RelayQLDefinition);
var RelayQLField = (function (_RelayQLNode2) {
var RelayQLField = function (_RelayQLNode2) {
_inherits(RelayQLField, _RelayQLNode2);

@@ -278,7 +284,9 @@

_get(Object.getPrototypeOf(RelayQLField.prototype), 'constructor', this).call(this, context, ast);
var fieldName = this.ast.name.value;
var _this8 = _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLField).call(this, context, ast));
var fieldName = _this8.ast.name.value;
var fieldDef = parentType.getFieldDefinition(fieldName, ast);
invariant(fieldDef, 'You supplied a field named `%s` on type `%s`, but no such field ' + 'exists on that type.', fieldName, parentType.getName({ modifiers: false }));
this.fieldDef = fieldDef;
_this8.fieldDef = fieldDef;
return _this8;
}

@@ -309,5 +317,12 @@

}, {
key: 'findArgument',
value: function findArgument(argName) {
return find(this.getArguments(), function (arg) {
return arg.getName() === argName;
});
}
}, {
key: 'getArguments',
value: function getArguments() {
var _this3 = this;
var _this9 = this;

@@ -318,4 +333,4 @@ var argTypes = this.fieldDef.getDeclaredArguments();

var argType = argTypes[argName];
invariant(argType, 'You supplied an argument named `%s` on field `%s`, but no such ' + 'argument exists on that field.', argName, _this3.getName());
return new RelayQLArgument(_this3.context, arg, argType);
invariant(argType, 'You supplied an argument named `%s` on field `%s`, but no such ' + 'argument exists on that field.', argName, _this9.getName());
return new RelayQLArgument(_this9.context, arg, argType);
});

@@ -341,5 +356,5 @@ }

return RelayQLField;
})(RelayQLNode);
}(RelayQLNode);
var RelayQLFragmentSpread = (function (_RelayQLNode3) {
var RelayQLFragmentSpread = function (_RelayQLNode3) {
_inherits(RelayQLFragmentSpread, _RelayQLNode3);

@@ -350,3 +365,3 @@

_get(Object.getPrototypeOf(RelayQLFragmentSpread.prototype), 'constructor', this).apply(this, arguments);
return _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLFragmentSpread).apply(this, arguments));
}

@@ -367,5 +382,5 @@

return RelayQLFragmentSpread;
})(RelayQLNode);
}(RelayQLNode);
var RelayQLInlineFragment = (function (_RelayQLNode4) {
var RelayQLInlineFragment = function (_RelayQLNode4) {
_inherits(RelayQLInlineFragment, _RelayQLNode4);

@@ -376,4 +391,6 @@

_get(Object.getPrototypeOf(RelayQLInlineFragment.prototype), 'constructor', this).call(this, context, ast);
this.parentType = parentType;
var _this11 = _possibleConstructorReturn(this, Object.getPrototypeOf(RelayQLInlineFragment).call(this, context, ast));
_this11.parentType = parentType;
return _this11;
}

@@ -389,7 +406,7 @@

return RelayQLInlineFragment;
})(RelayQLNode);
}(RelayQLNode);
var RelayQLDirective = (function () {
var RelayQLDirective = function () {
function RelayQLDirective(context, ast) {
var _this4 = this;
var _this12 = this;

@@ -403,6 +420,6 @@ _classCallCheck(this, RelayQLDirective);

var directiveName = ast.name.value;
var schemaDirective = directiveName === GraphQLRelayDirective.name ? GraphQLRelayDirective : context.schema.getDirective(directiveName);
var schemaDirective = directiveName === GraphQLRelayDirective.name ? GraphQLRelayDirectiveInstance : context.schema.getDirective(directiveName);
invariant(schemaDirective, 'You supplied a directive named `%s`, but no such directive exists.', directiveName);
schemaDirective.args.forEach(function (schemaArg) {
_this4.argTypes[schemaArg.name] = new RelayQLArgumentType(schemaArg.type);
_this12.argTypes[schemaArg.name] = new RelayQLArgumentType(schemaArg.type);
});

@@ -419,9 +436,9 @@ }

value: function getArguments() {
var _this5 = this;
var _this13 = this;
return (this.ast.arguments || []).map(function (arg) {
var argName = arg.name.value;
var argType = _this5.argTypes[argName];
invariant(argType, 'You supplied an argument named `%s` on directive `%s`, but no ' + 'such argument exists on that directive.', argName, _this5.getName());
return new RelayQLArgument(_this5.context, arg, argType);
var argType = _this13.argTypes[argName];
invariant(argType, 'You supplied an argument named `%s` on directive `%s`, but no ' + 'such argument exists on that directive.', argName, _this13.getName());
return new RelayQLArgument(_this13.context, arg, argType);
});

@@ -432,5 +449,5 @@ }

return RelayQLDirective;
})();
}();
var RelayQLArgument = (function () {
var RelayQLArgument = function () {
function RelayQLArgument(context, ast, type) {

@@ -468,3 +485,3 @@ _classCallCheck(this, RelayQLArgument);

value: function getValue() {
var _this6 = this;
var _this14 = this;

@@ -475,3 +492,3 @@ invariant(!this.isVariable(), 'Cannot get value of an argument variable.');

return value.values.map(function (value) {
return new RelayQLArgument(_this6.context, _extends({}, _this6.ast, { value: value }), _this6.type.ofType());
return new RelayQLArgument(_this14.context, _extends({}, _this14.ast, { value: value }), _this14.type.ofType());
});

@@ -485,5 +502,5 @@ } else {

return RelayQLArgument;
})();
}();
var RelayQLType = (function () {
var RelayQLType = function () {
function RelayQLType(context, schemaModifiedType) {

@@ -515,5 +532,4 @@ _classCallCheck(this, RelayQLType);

var modifiers = _ref.modifiers;
return (function () {
return modifiers ? this.schemaModifiedType.toString() : this.schemaUnmodifiedType.toString();
}).apply(this, arguments);
return modifiers ? this.schemaModifiedType.toString() : this.schemaUnmodifiedType.toString();
}

@@ -533,3 +549,3 @@ }, {

var schemaFieldDef = undefined;
var schemaFieldDef = void 0;
if (isQueryType && fieldName === SchemaMetaFieldDef.name) {

@@ -560,3 +576,3 @@ schemaFieldDef = SchemaMetaFieldDef;

var _loop = function (ii) {
var _loop = function _loop(ii) {
var possibleField = possibleTypes[ii].getFields()[fieldName];

@@ -594,7 +610,7 @@ if (possibleField) {

value: function getInterfaces() {
var _this7 = this;
var _this15 = this;
if (this.schemaUnmodifiedType instanceof types.GraphQLObjectType) {
return this.schemaUnmodifiedType.getInterfaces().map(function (schemaInterface) {
return new RelayQLType(_this7.context, schemaInterface);
return new RelayQLType(_this15.context, schemaInterface);
});

@@ -607,7 +623,7 @@ }

value: function getConcreteTypes() {
var _this8 = this;
var _this16 = this;
invariant(this.isAbstract(), 'Cannot get concrete types of a concrete type.');
return this.schemaUnmodifiedType.getPossibleTypes().map(function (concreteType) {
return new RelayQLType(_this8.context, concreteType);
return new RelayQLType(_this16.context, concreteType);
});

@@ -729,5 +745,5 @@ }

return RelayQLType;
})();
}();
var RelayQLFieldDefinition = (function () {
var RelayQLFieldDefinition = function () {
function RelayQLFieldDefinition(context, schemaFieldDef) {

@@ -778,5 +794,5 @@ _classCallCheck(this, RelayQLFieldDefinition);

return RelayQLFieldDefinition;
})();
}();
var RelayQLArgumentType = (function () {
var RelayQLArgumentType = function () {
function RelayQLArgumentType(schemaModifiedArgType) {

@@ -801,5 +817,4 @@ _classCallCheck(this, RelayQLArgumentType);

var modifiers = _ref2.modifiers;
return (function () {
return modifiers ? this.schemaModifiedArgType.toString() : this.schemaUnmodifiedArgType.toString();
}).apply(this, arguments);
return modifiers ? this.schemaModifiedArgType.toString() : this.schemaUnmodifiedArgType.toString();
}

@@ -840,3 +855,3 @@ }, {

return RelayQLArgumentType;
})();
}();

@@ -843,0 +858,0 @@ function stripMarkerTypes(schemaModifiedType) {

@@ -16,13 +16,11 @@ // @generated

Object.defineProperty(exports, '__esModule', {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; };
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -44,2 +42,3 @@ var _require = require('./RelayQLAST');

var find = require('./find');

@@ -77,3 +76,3 @@ var invariant = require('./invariant');

var RelayQLPrinter = (function () {
var RelayQLPrinter = function () {
function RelayQLPrinter(tagName, variableNames) {

@@ -86,14 +85,6 @@ _classCallCheck(this, RelayQLPrinter);

/**
* Determine if a `... on Node { id }` fragment should be generated for a
* field/fragment to allow identification of the response record. This
* fragment should be added when some/all implementors of the node's type
* also implement `Node` but a `Node` fragment is not already present. If it
* is present then `id` would be added as a requisite field.
*/
_createClass(RelayQLPrinter, [{
key: 'print',
value: function print(definition, substitutions) {
var printedDocument = undefined;
var printedDocument = void 0;
if (definition instanceof RelayQLQuery) {

@@ -148,10 +139,12 @@ printedDocument = this.printQuery(definition);

var identifyingArg = rootFieldArgs[0];
metadata.identifyingArgName = identifyingArg.getName();
metadata.identifyingArgType = this.printArgumentTypeForMetadata(identifyingArg.getType());
var identifyingArgName = identifyingArg.getName();
var identifyingArgType = identifyingArg.getType().getName({ modifiers: true });
metadata.identifyingArgName = identifyingArgName;
metadata.identifyingArgType = identifyingArgType;
calls = t.arrayExpression([codify({
kind: t.valueToNode('Call'),
metadata: objectify({
type: this.printArgumentTypeForMetadata(identifyingArg.getType())
type: identifyingArgType
}),
name: t.valueToNode(identifyingArg.getName()),
name: t.valueToNode(identifyingArgName),
value: this.printArgumentValue(identifyingArg)

@@ -175,6 +168,8 @@ })]);

value: function printFragment(fragment) {
var _this = this;
var fragmentType = fragment.getType();
var requisiteFields = {};
var idFragment = undefined;
var idFragment = void 0;
if (fragmentType.hasField(FIELDS.id)) {

@@ -189,7 +184,14 @@ requisiteFields.id = true;

var selections = this.printSelections(fragment, requisiteFields, idFragment ? [idFragment] : null, fragment.hasDirective('generated'));
var relayDirective = findRelayDirective(fragment);
var selectVariables = relayDirective && find(relayDirective.getArguments(), function (arg) {
return arg.getName() === 'variables';
});
var metadata = this.printRelayDirectiveMetadata(fragment, {
isAbstract: fragmentType.isAbstract()
isAbstract: fragmentType.isAbstract(),
isTrackingEnabled: !!selectVariables
});
return codify({
var fragmentCode = codify({
children: selections,

@@ -203,2 +205,14 @@ directives: this.printDirectives(fragment.getDirectives()),

});
if (selectVariables) {
var selectVariablesValue = selectVariables.getValue();
invariant(Array.isArray(selectVariablesValue), 'The variables argument to the @relay directive should be an array ' + 'of strings.');
return t.callExpression(t.memberExpression(identify(this.tagName), t.identifier('__createFragment')), [fragmentCode, t.objectExpression(selectVariablesValue.map(function (item) {
var value = item.getValue();
return property(value, _this.printVariable(value));
}))]);
}
return fragmentCode;
}

@@ -282,3 +296,3 @@ }, {

value: function printSelections(parent, requisiteFields, extraFragments) {
var _this = this;
var _this2 = this;

@@ -294,6 +308,6 @@ var isGeneratedQuery = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];

invariant(selection.getDirectives().length === 0, 'Directives are not yet supported for `${fragment}`-style fragment ' + 'references.');
printedFragments.push(_this.printFragmentReference(selection));
printedFragments.push(_this2.printFragmentReference(selection));
didPrintFragmentReference = true;
} else if (selection instanceof RelayQLInlineFragment) {
printedFragments.push(_this.printFragment(selection.getFragment()));
printedFragments.push(_this2.printFragment(selection.getFragment()));
} else if (selection instanceof RelayQLField) {

@@ -307,3 +321,3 @@ fields.push(selection);

extraFragments.forEach(function (fragment) {
printedFragments.push(_this.printFragment(fragment));
printedFragments.push(_this2.printFragment(fragment));
});

@@ -323,3 +337,3 @@ }

value: function printFields(fields, parent, requisiteFields) {
var _this2 = this;
var _this3 = this;

@@ -340,3 +354,3 @@ var isGeneratedQuery = arguments.length <= 3 || arguments[3] === undefined ? false : arguments[3];

delete generatedFields[field.getName()];
printedFields.push(_this2.printField(field, parent, requisiteFields, generatedFields, isGeneratedQuery));
printedFields.push(_this3.printField(field, parent, requisiteFields, generatedFields, isGeneratedQuery));
});

@@ -346,3 +360,3 @@

var generatedField = parentType.generateField(fieldName);
printedFields.push(_this2.printField(generatedField, parent, requisiteFields, generatedFields, isGeneratedQuery));
printedFields.push(_this3.printField(generatedField, parent, requisiteFields, generatedFields, isGeneratedQuery));
});

@@ -354,3 +368,3 @@ return printedFields;

value: function printField(field, parent, requisiteSiblings, generatedSiblings) {
var _this3 = this;
var _this4 = this;

@@ -363,3 +377,3 @@ var isGeneratedQuery = arguments.length <= 4 || arguments[4] === undefined ? false : arguments[4];

var requisiteFields = {};
var idFragment = undefined;
var idFragment = void 0;
if (fieldType.hasField(FIELDS.id)) {

@@ -418,3 +432,3 @@ requisiteFields.id = true;

var calls = args.length ? t.arrayExpression(args.map(function (arg) {
return _this3.printArgument(arg);
return _this4.printArgument(arg);
})) : NULL;

@@ -477,7 +491,7 @@

value: function printValue(value) {
var _this4 = this;
var _this5 = this;
if (Array.isArray(value)) {
return t.arrayExpression(value.map(function (element) {
return _this4.printArgumentValue(element);
return _this5.printArgumentValue(element);
}));

@@ -493,3 +507,3 @@ }

value: function printDirectives(directives) {
var _this5 = this;
var _this6 = this;

@@ -502,3 +516,3 @@ var printedDirectives = [];

printedDirectives.push(t.objectExpression([property('kind', t.valueToNode('Directive')), property('name', t.valueToNode(directive.getName())), property('args', t.arrayExpression(directive.getArguments().map(function (arg) {
return t.objectExpression([property('name', t.valueToNode(arg.getName())), property('value', _this5.printArgumentValue(arg))]);
return t.objectExpression([property('name', t.valueToNode(arg.getName())), property('value', _this6.printArgumentValue(arg))]);
})))]));

@@ -515,5 +529,3 @@ });

var properties = [];
var relayDirective = find(node.getDirectives(), function (directive) {
return directive.getName() === 'relay';
});
var relayDirective = findRelayDirective(node);
if (relayDirective) {

@@ -524,3 +536,5 @@ relayDirective.getArguments().forEach(function (arg) {

}
properties.push(property(arg.getName(), t.valueToNode(arg.getValue())));
if (arg.getName() !== 'variables') {
properties.push(property(arg.getName(), t.valueToNode(arg.getValue())));
}
});

@@ -544,2 +558,3 @@ }

*/
}, {

@@ -561,4 +576,13 @@ key: 'printArgumentTypeForMetadata',

return RelayQLPrinter;
})();
}();
/**
* Determine if a `... on Node { id }` fragment should be generated for a
* field/fragment to allow identification of the response record. This
* fragment should be added when some/all implementors of the node's type
* also implement `Node` but a `Node` fragment is not already present. If it
* is present then `id` would be added as a requisite field.
*/
function shouldGenerateIdFragment(node) {

@@ -579,5 +603,11 @@ return node.getType().mayImplement('Node') && !node.getSelections().some(function (selection) {

function validateConnectionField(field) {
invariant(!field.hasArgument('first') || !field.hasArgument('before'), 'Connection arguments `%s(before: <cursor>, first: <count>)` are ' + 'not supported. Use `(first: <count>)`, ' + '`(after: <cursor>, first: <count>)`, or ' + '`(before: <cursor>, last: <count>)`.', field.getName());
invariant(!field.hasArgument('last') || !field.hasArgument('after'), 'Connection arguments `%s(after: <cursor>, last: <count>)` are ' + 'not supported. Use `(last: <count>)`, ' + '`(before: <cursor>, last: <count>)`, or ' + '`(after: <cursor>, first: <count>)`.', field.getName());
var first = field.findArgument('first');
var last = field.findArgument('last');
var before = field.findArgument('before');
var after = field.findArgument('after');
invariant(!first || !last || first.isVariable() && last.isVariable(), 'Connection arguments `%s(first: <count>, last: <count>)` are ' + 'not supported unless both are variables. Use `(first: <count>)`, ' + '`(last: <count>)`, or `(first: $<var>, last: $<var>)`.', field.getName());
invariant(!first || !before || first.isVariable() && before.isVariable(), 'Connection arguments `%s(before: <cursor>, first: <count>)` are ' + 'not supported unless both are variables. Use `(first: <count>)`, ' + '`(after: <cursor>, first: <count>)`, `(before: <cursor>, last: <count>)`, ' + 'or `(before: $<var>, first: $<var>)`.', field.getName());
invariant(!last || !after || last.isVariable() && after.isVariable(), 'Connection arguments `%s(after: <cursor>, last: <count>)` are ' + 'not supported unless both are variables. Use `(last: <count>)`, ' + '`(before: <cursor>, last: <count>)`, `(after: <cursor>, first: <count>)`, ' + 'or `(after: $<var>, last: $<var>)`.', field.getName());
// Use `any` because we already check `isConnection` before validating.

@@ -660,4 +690,4 @@ var connectionNodeType = field.getType().getFieldDefinition(FIELDS.edges).getType().getFieldDefinition(FIELDS.node).getType();

return t.arrayExpression(value.map(printLiteralValue));
} else if (typeof value === 'object' && value != null) {
var _ret2 = (function () {
} else if ((typeof value === 'undefined' ? 'undefined' : _typeof(value)) === 'object' && value != null) {
var _ret2 = function () {
var objectValue = value;

@@ -669,5 +699,5 @@ return {

};
})();
}();
if (typeof _ret2 === 'object') return _ret2.v;
if ((typeof _ret2 === 'undefined' ? 'undefined' : _typeof(_ret2)) === "object") return _ret2.v;
} else {

@@ -682,3 +712,9 @@ return t.valueToNode(value);

function findRelayDirective(node) {
return find(node.getDirectives(), function (directive) {
return directive.getName() === 'relay';
});
}
return RelayQLPrinter;
};

@@ -16,10 +16,6 @@ // @generated

Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var GraphQL = require('./GraphQL');

@@ -49,3 +45,3 @@ var formatError = GraphQL.error.formatError;

var RelayQLTransformer = (function () {
var RelayQLTransformer = function () {
function RelayQLTransformer(schema, options) {

@@ -62,7 +58,7 @@ _classCallCheck(this, RelayQLTransformer);

node, options) {
var _processTemplateLiteral = this.processTemplateLiteral(node, options.documentName);
var _processTemplateLiter = this.processTemplateLiteral(node, options.documentName);
var substitutions = _processTemplateLiteral.substitutions;
var templateText = _processTemplateLiteral.templateText;
var variableNames = _processTemplateLiteral.variableNames;
var substitutions = _processTemplateLiter.substitutions;
var templateText = _processTemplateLiter.templateText;
var variableNames = _processTemplateLiter.variableNames;

@@ -81,2 +77,3 @@ var documentText = this.processTemplateText(templateText, options);

*/
}, {

@@ -94,11 +91,11 @@ key: 'processTemplateLiteral',

if (!element.tail) {
var _name = 'RQL_' + ii;
var name = 'RQL_' + ii;
var _value = node.expressions[ii];
substitutions.push({ name: _name, value: _value });
substitutions.push({ name: name, value: _value });
if (/:\s*$/.test(chunk)) {
invariant(_this.options.substituteVariables, 'You supplied a GraphQL document named `%s` that uses template ' + 'substitution for an argument value, but variable substitution ' + 'has not been enabled.', documentName);
chunks.push('$' + _name);
variableNames[_name] = undefined;
chunks.push('$' + name);
variableNames[name] = undefined;
} else {
chunks.push('...' + _name);
chunks.push('...' + name);
}

@@ -113,2 +110,3 @@ }

*/
}, {

@@ -138,2 +136,3 @@ key: 'processTemplateText',

*/
}, {

@@ -143,6 +142,5 @@ key: 'processDocumentText',

var documentName = _ref2.documentName;
var fragmentLocationID = _ref2.fragmentLocationID;
var document = parser.parse(new Source(documentText, documentName));
var validationErrors = this.validateDocument(document);
var validationErrors = this.validateDocument(document, documentName);
if (validationErrors) {

@@ -160,4 +158,3 @@ var error = new Error(util.format('You supplied a GraphQL document named `%s` with validation errors.', documentName));

generateID: createIDGenerator(),
schema: this.schema,
fragmentLocationID: fragmentLocationID
schema: this.schema
};

@@ -182,4 +179,4 @@ if (definition.kind === 'FragmentDefinition') {

key: 'validateDocument',
value: function validateDocument(document) {
invariant(document.definitions.length === 1, 'You supplied a GraphQL document named `%s` with %d definitions, but ' + 'it must have exactly one definition.', document.definitions.length);
value: function validateDocument(document, documentName) {
invariant(document.definitions.length === 1, 'You supplied a GraphQL document named `%s` with %d definitions, but ' + 'it must have exactly one definition.', documentName, document.definitions.length);
var definition = document.definitions[0];

@@ -189,3 +186,3 @@ var isMutation = definition.kind === 'OperationDefinition' && definition.operation === 'mutation';

var validator = this.options.validator;
var validationErrors = undefined;
var validationErrors = void 0;
if (validator) {

@@ -213,3 +210,3 @@ var _validator = validator(GraphQL);

return RelayQLTransformer;
})();
}();

@@ -216,0 +213,0 @@ function capitalize(string) {

// @generated
'use strict';
/**

@@ -17,4 +19,2 @@ * Copyright (c) 2013-present, Facebook, Inc.

'use strict';
var fs = require('fs');

@@ -21,0 +21,0 @@ var path = require('path');

@@ -21,9 +21,9 @@ // @generated

var _schemas = {};
var schemaCache = {};
function getSchema(schemaPath) {
try {
var schema = _schemas[schemaPath];
var schema = schemaCache[schemaPath];
if (!schema) {
schema = JSON.parse(fs.readFileSync(schemaPath, 'utf8')).data;
_schemas[schemaPath] = schema;
schemaCache[schemaPath] = schema;
}

@@ -37,3 +37,3 @@ return schema;

function transformGraphQL(schemaPath, source, filename) {
var plugin = getBabelRelayPlugin(getSchema(schemaPath), {
var relayPlugin = getBabelRelayPlugin(getSchema(schemaPath), {
debug: true,

@@ -44,6 +44,5 @@ substituteVariables: true,

return babel.transform(source, {
plugins: [relayPlugin],
compact: false,
filename: filename,
plugins: [plugin],
blacklist: ['strict']
filename: filename
}).code;

@@ -50,0 +49,0 @@ }

{
"name": "babel-relay-plugin",
"version": "0.7.3",
"version": "0.8.0",
"description": "Babel Relay Plugin for transpiling GraphQL queries for use with Relay.",

@@ -10,8 +10,9 @@ "license": "BSD-3-Clause",

"build": "node scripts/build-lib",
"jest": "NODE_ENV=test jest $@",
"lint": "eslint .",
"prepublish": "npm run build",
"test": "f() { EXIT=0; npm run typecheck || EXIT=$?; NODE_ENV=test jest $@ || EXIT=$?; exit $EXIT; }; f",
"test": "f() { EXIT=0; npm run typecheck || EXIT=$?; npm run jest || EXIT=$?; exit $EXIT; }; f",
"typecheck": "flow check src/",
"update-schema": "babel-node ./src/tools/generateSchemaJson.js",
"update-fixtures": "babel-node ./src/tools/regenerateFixtures.js"
"update-fixtures": "babel-node ./src/tools/regenerateFixtures.js",
"update-schema": "babel-node ./src/tools/generateSchemaJson.js"
},

@@ -25,12 +26,20 @@ "files": [

"devDependencies": {
"babel-core": "^5.8.35",
"babel-cli": "^6.7.5",
"babel-core": "^6.6.4",
"babel-eslint": "^4.1.1",
"babel-jest": "^5.3.0",
"babel-jest": "^10.0.1",
"babel-plugin-syntax-flow": "^6.5.0",
"babel-plugin-syntax-object-rest-spread": "^6.5.0",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
"babel-plugin-transform-class-properties": "^6.6.0",
"babel-plugin-transform-flow-strip-types": "^6.7.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-preset-es2015": "^6.6.0",
"eslint": "^1.3.1",
"flow-bin": "0.21.0",
"glob": "^5.0.15",
"jest-cli": "0.9.0-fb3",
"flow-bin": "0.22.0",
"glob": "^7.0.3",
"jest-cli": "^0.10.0",
"minimist": "^1.1.3",
"mkdirp": "^0.5.1",
"rimraf": "^2.1"
"rimraf": "^2.5"
},

@@ -41,12 +50,10 @@ "dependencies": {

"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"persistModuleRegistryBetweenSpecs": true,
"testPathIgnorePatterns": [
"<rootDir>/node_modules"
],
"preprocessorIgnorePatterns": [
"<rootDir>/node_modules/"
],
"testRunner": "<rootDir>/node_modules/jest-cli/src/testRunners/jasmine/jasmine2.js",
"unmockedModulePathPatterns": [
"<rootDir>/"
"<rootDir>/node_modules"
]
}
}

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