babel-relay-plugin
Advanced tools
Comparing version 0.9.3 to 0.10.0
@@ -18,3 +18,9 @@ // @generated | ||
var RelayQLTransformer = require('./RelayQLTransformer'); | ||
var RelayTransformError = require('./RelayTransformError'); | ||
var babelAdapter = require('./babelAdapter'); | ||
var computeLocation = require('./computeLocation'); | ||
var invariant = require('./invariant'); | ||
var util = require('util'); | ||
@@ -24,10 +30,7 @@ var _require = require('./GraphQL'); | ||
var buildClientSchema = _require.utilities_buildClientSchema.buildClientSchema; | ||
var buildASTSchema = _require.utilities_buildASTSchema.buildASTSchema; | ||
var RelayQLTransformer = require('./RelayQLTransformer'); | ||
var RelayTransformError = require('./RelayTransformError'); | ||
var babelAdapter = require('./babelAdapter'); | ||
var invariant = require('./invariant'); | ||
var util = require('util'); | ||
var PROVIDES_MODULE = 'providesModule'; | ||
var RELAY_QL_GENERATED = 'RelayQL_GENERATED'; | ||
@@ -102,3 +105,3 @@ /** | ||
var tag = path.get('tag'); | ||
var tagName = tag.matchesPattern('Relay.QL') ? 'Relay.QL' : tag.isIdentifier({ name: 'RelayQL' }) ? 'RelayQL' : null; | ||
var tagName = tag.matchesPattern('Relay.QL') ? 'Relay.QL' : tag.isIdentifier({ name: 'RelayQL' }) ? 'RelayQL' : tag.isIdentifier({ name: RELAY_QL_GENERATED }) ? RELAY_QL_GENERATED : null; | ||
if (!tagName) { | ||
@@ -124,2 +127,3 @@ return; | ||
documentName: documentName, | ||
enableValidation: tagName !== RELAY_QL_GENERATED, | ||
tagName: tagName, | ||
@@ -136,6 +140,8 @@ propName: propName | ||
warning('\n-- Relay Transform Error -- %s --\n', basename); | ||
var sourceLine = node.quasi.loc.start.line; | ||
var relative_loc = computeLocation(error.loc); | ||
if (relative_loc) { | ||
warning(['Within RelayQLDocument ' + filename + ':' + sourceLine, '> ', '> line ' + relative_loc.line + ' (approximate)', '> ' + relative_loc.source, '> ' + ' '.repeat(relative_loc.column - 1) + '^^^', 'Error: ' + error.message, 'Stack: ' + error.stack].join('\n')); | ||
var sourceLine = node.quasi.loc && node.quasi.loc.start.line; | ||
var relativeLocation = error.loc && computeLocation(error.loc); | ||
if (sourceLine && relativeLocation) { | ||
warning(['Within RelayQLDocument ' + filename + ':' + sourceLine, '> ', '> line ' + relativeLocation.line + ' (approximate)', '> ' + relativeLocation.source, '> ' + ' '.repeat(relativeLocation.column - 1) + '^^^', 'Error: ' + error.message, 'Stack: ' + error.stack].join('\n')); | ||
} else { | ||
warning(error.message); | ||
} | ||
@@ -197,6 +203,11 @@ } else { | ||
var introspection = typeof schemaProvider === 'function' ? schemaProvider() : schemaProvider; | ||
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); | ||
if (_typeof(introspection.__schema) === 'object' && introspection.__schema) { | ||
return buildClientSchema(introspection); | ||
} else if (introspection.kind && introspection.kind === 'Document') { | ||
return buildASTSchema(introspection); | ||
} | ||
throw new Error('Invalid introspection data supplied to `getBabelRelayPlugin()`. The ' + 'resulting schema is not an object with a `__schema` property or ' + 'a schema IDL language.'); | ||
} | ||
module.exports = getBabelRelayPlugin; |
@@ -28,2 +28,3 @@ // @generated | ||
utilities_buildClientSchema: require('graphql/utilities/buildClientSchema'), | ||
utilities_buildASTSchema: require('graphql/utilities/buildASTSchema'), | ||
validation: require('graphql/validation'), | ||
@@ -30,0 +31,0 @@ validation_rules_KnownFragmentNames: require('graphql/validation/rules/KnownFragmentNames'), |
@@ -26,6 +26,19 @@ // @generated | ||
var GraphQLRelayDirective = require('./GraphQLRelayDirective'); | ||
var RelayTransformError = require('./RelayTransformError'); | ||
var find = require('./find'); | ||
var invariant = require('./invariant'); | ||
var util = require('util'); | ||
var _require = require('./GraphQL'); | ||
var types = _require.type; | ||
var GraphQLDirectiveClass = _require.type_directives.GraphQLDirective; | ||
var GraphQLDirective = _require.type_directives.GraphQLDirective; | ||
var _require$type_scalars = _require.type_scalars; | ||
var GraphQLBoolean = _require$type_scalars.GraphQLBoolean; | ||
var GraphQLFloat = _require$type_scalars.GraphQLFloat; | ||
var GraphQLID = _require$type_scalars.GraphQLID; | ||
var GraphQLInt = _require$type_scalars.GraphQLInt; | ||
var GraphQLString = _require$type_scalars.GraphQLString; | ||
var _require$type_introsp = _require.type_introspection; | ||
@@ -36,9 +49,2 @@ var SchemaMetaFieldDef = _require$type_introsp.SchemaMetaFieldDef; | ||
var GraphQLRelayDirective = require('./GraphQLRelayDirective'); | ||
var find = require('./find'); | ||
var invariant = require('./invariant'); | ||
var util = require('util'); | ||
var RelayTransformError = require('./RelayTransformError'); | ||
var _require2 = require('./RelayQLNodeInterface'); | ||
@@ -49,3 +55,3 @@ | ||
var GraphQLRelayDirectiveInstance = new GraphQLDirectiveClass(GraphQLRelayDirective); | ||
var GraphQLRelayDirectiveInstance = new GraphQLDirective(GraphQLRelayDirective); | ||
@@ -99,2 +105,3 @@ // TODO: Import types from `graphql`. | ||
} | ||
// $FlowFixMe | ||
return this.ast.selectionSet.selections.map(function (selection) { | ||
@@ -117,2 +124,3 @@ if (selection.kind === 'Field') { | ||
// $FlowFixMe | ||
return (this.ast.directives || []).map(function (directive) { | ||
@@ -125,2 +133,3 @@ return new RelayQLDirective(_this2.context, directive); | ||
value: function hasDirective(name) { | ||
// $FlowFixMe | ||
return (this.ast.directives || []).some(function (d) { | ||
@@ -153,3 +162,5 @@ return d.name.value === name; | ||
// TODO: this.context.definitionName; | ||
return this.ast.name ? this.ast.name.value : this.getType().getName({ modifiers: false }); | ||
return this.ast.name ? | ||
// $FlowFixMe | ||
this.ast.name.value : this.getType().getName({ modifiers: false }); | ||
} | ||
@@ -667,2 +678,7 @@ }]); | ||
}, { | ||
key: 'isQueryType', | ||
value: function isQueryType() { | ||
return this.schemaUnmodifiedType === this.context.schema.getQueryType(); | ||
} | ||
}, { | ||
key: 'isConnection', | ||
@@ -830,2 +846,7 @@ value: function isConnection() { | ||
}, { | ||
key: 'isCustomScalar', | ||
value: function isCustomScalar() { | ||
return this.isScalar() && !(this.schemaUnmodifiedArgType === GraphQLBoolean || this.schemaUnmodifiedArgType === GraphQLFloat || this.schemaUnmodifiedArgType === GraphQLID || this.schemaUnmodifiedArgType === GraphQLInt || this.schemaUnmodifiedArgType === GraphQLString); | ||
} | ||
}, { | ||
key: 'isEnum', | ||
@@ -889,2 +910,4 @@ value: function isEnum() { | ||
return value.values.map(getLiteralValue); | ||
case 'NullValue': | ||
return null; | ||
case 'ObjectValue': | ||
@@ -891,0 +914,0 @@ var object = {}; |
@@ -10,3 +10,2 @@ // @generated | ||
* | ||
* @providesModule RelayQLNodeInterface | ||
* | ||
@@ -13,0 +12,0 @@ */ |
@@ -26,2 +26,8 @@ // @generated | ||
var RelayTransformError = require('./RelayTransformError'); | ||
var find = require('./find'); | ||
var invariant = require('./invariant'); | ||
var util = require('util'); | ||
var _require = require('./RelayQLAST'); | ||
@@ -42,8 +48,2 @@ | ||
var find = require('./find'); | ||
var invariant = require('./invariant'); | ||
var util = require('util'); | ||
var RelayTransformError = require('./RelayTransformError'); | ||
var _require2 = require('./RelayQLNodeInterface'); | ||
@@ -93,11 +93,13 @@ | ||
value: function print(definition, substitutions) { | ||
var enableValidation = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2]; | ||
var printedDocument = void 0; | ||
if (definition instanceof RelayQLQuery) { | ||
printedDocument = this.printQuery(definition); | ||
printedDocument = this.printQuery(definition, enableValidation); | ||
} else if (definition instanceof RelayQLFragment) { | ||
printedDocument = this.printFragment(definition); | ||
} else if (definition instanceof RelayQLMutation) { | ||
printedDocument = this.printMutation(definition); | ||
printedDocument = this.printMutation(definition, enableValidation); | ||
} else if (definition instanceof RelayQLSubscription) { | ||
printedDocument = this.printSubscription(definition); | ||
printedDocument = this.printSubscription(definition, enableValidation); | ||
} else { | ||
@@ -114,5 +116,5 @@ throw new RelayTransformError(util.format('Unsupported definition: %s', definition), definition.getLocation()); | ||
key: 'printQuery', | ||
value: function printQuery(query) { | ||
value: function printQuery(query, enableValidation) { | ||
var rootFields = query.getFields(); | ||
if (rootFields.length !== 1) { | ||
if (rootFields.length !== 1 && enableValidation) { | ||
throw new RelayTransformError(util.format('There are %d fields supplied to the query named `%s`, but queries ' + 'must have exactly one field.', rootFields.length, query.getName()), query.getLocation()); | ||
@@ -220,2 +222,3 @@ } | ||
return t.callExpression(t.memberExpression(identify(this.tagName), t.identifier('__createFragment')), [fragmentCode, t.objectExpression(selectVariablesValue.map(function (item) { | ||
// $FlowFixMe | ||
var value = item.getValue(); | ||
@@ -240,5 +243,5 @@ return property(value, _this.printVariable(value)); | ||
key: 'printMutation', | ||
value: function printMutation(mutation) { | ||
value: function printMutation(mutation, enableValidation) { | ||
var rootFields = mutation.getFields(); | ||
if (rootFields.length !== 1) { | ||
if (rootFields.length !== 1 && enableValidation) { | ||
throw new RelayTransformError(util.format('There are %d fields supplied to the mutation named `%s`, but ' + 'mutations must have exactly one field.', rootFields.length, mutation.getName()), mutation.getLocation()); | ||
@@ -275,5 +278,5 @@ } | ||
key: 'printSubscription', | ||
value: function printSubscription(subscription) { | ||
value: function printSubscription(subscription, enableValidation) { | ||
var rootFields = subscription.getFields(); | ||
if (rootFields.length !== 1) { | ||
if (rootFields.length !== 1 && enableValidation) { | ||
throw new RelayTransformError(util.format('There are %d fields supplied to the subscription named `%s`, but ' + 'subscriptions must have exactly one field.', rootFields.length, subscription.getName()), subscription.getLocation()); | ||
@@ -288,2 +291,5 @@ } | ||
} | ||
if (rootFieldType.hasField(FIELDS.clientMutationId)) { | ||
requisiteFields[FIELDS.clientMutationId] = true; | ||
} | ||
var selections = this.printSelections(rootField, requisiteFields); | ||
@@ -452,2 +458,3 @@ var metadata = { | ||
kind: t.valueToNode('Field'), | ||
// $FlowFixMe | ||
metadata: this.printRelayDirectiveMetadata(field, metadata), | ||
@@ -504,3 +511,5 @@ type: t.valueToNode(fieldType.getName({ modifiers: false })) | ||
if (Array.isArray(value)) { | ||
return t.arrayExpression(value.map(function (element) { | ||
return t.arrayExpression( | ||
// $FlowFixMe | ||
value.map(function (element) { | ||
return _this5.printArgumentValue(element); | ||
@@ -511,3 +520,6 @@ })); | ||
kind: t.valueToNode('CallValue'), | ||
callValue: printLiteralValue(value) | ||
// codify() skips properties where value === NULL, but `callValue` is a | ||
// required property. Create fresh null literals to force the property | ||
// to be printed. | ||
callValue: value == null ? t.nullLiteral() : printLiteralValue(value) | ||
}); | ||
@@ -569,7 +581,10 @@ } | ||
value: function printArgumentTypeForMetadata(argType) { | ||
// Currently, we always send Enum and Object types as variables. | ||
if (argType.isEnum() || argType.isObject()) { | ||
// Print enums, input objects, and custom scalars as variables, since | ||
// there are more complicated rules for printing them (for example, | ||
// correctly inlining custom scalars would require access to the | ||
// user-defined type definition at runtime). | ||
if (argType.isEnum() || argType.isObject() || argType.isCustomScalar()) { | ||
return argType.getName({ modifiers: true }); | ||
} | ||
// Currently, we always inline scalar types. | ||
// Only the built-in scalar types can be printed inline | ||
if (argType.isScalar()) { | ||
@@ -604,3 +619,3 @@ return null; | ||
var argNames = Object.keys(argTypes); | ||
if (argNames.length === 1 && argNames[0] === ID) { | ||
if (!parentType.isQueryType() && argNames.length === 1 && argNames[0] === ID) { | ||
throw new RelayTransformError(util.format('You defined a `node(%s: %s)` field on type `%s`, but Relay requires ' + 'the `node` field to be defined on the root type. See the Object ' + 'Identification Guide: \n' + 'http://facebook.github.io/relay/docs/graphql-object-identification.html', ID, argNames[0] && argTypes[argNames[0]].getName({ modifiers: true }), parentType.getName({ modifiers: false })), field.getLocation()); | ||
@@ -670,4 +685,4 @@ } | ||
var forEachRecursiveField = function forEachRecursiveField(selection, callback) { | ||
selection.getSelections().forEach(function (selection) { | ||
var forEachRecursiveField = function forEachRecursiveField(parentSelection, callback) { | ||
parentSelection.getSelections().forEach(function (selection) { | ||
if (selection instanceof RelayQLField) { | ||
@@ -674,0 +689,0 @@ callback(selection); |
@@ -66,3 +66,3 @@ // @generated | ||
var Printer = RelayQLPrinter(t, this.options); | ||
return new Printer(options.tagName, variableNames).print(definition, substitutions); | ||
return new Printer(options.tagName, variableNames).print(definition, substitutions, options.enableValidation); | ||
} | ||
@@ -136,5 +136,6 @@ | ||
var documentName = _ref2.documentName; | ||
var enableValidation = _ref2.enableValidation; | ||
var document = parser.parse(new Source(documentText, documentName)); | ||
var validationErrors = this.validateDocument(document, documentName); | ||
var validationErrors = enableValidation ? this.validateDocument(document, documentName) : null; | ||
if (validationErrors) { | ||
@@ -141,0 +142,0 @@ var error = new Error(util.format('You supplied a GraphQL document named `%s` with validation errors.', documentName)); |
// @generated | ||
'use strict'; | ||
/** | ||
@@ -14,2 +12,3 @@ * Copyright (c) 2013-present, Facebook, Inc. | ||
*/ | ||
'use strict'; | ||
@@ -21,6 +20,6 @@ /** | ||
var fs = require('fs'); | ||
var graphql = require('graphql'); | ||
var language = require('graphql/language'); | ||
var path = require('path'); | ||
var language = require('graphql/language'); | ||
var utilities = require('graphql/utilities'); | ||
var graphql = require('graphql'); | ||
@@ -27,0 +26,0 @@ var TESTS_DIR = path.resolve(__dirname, '..', '__tests__'); |
{ | ||
"name": "babel-relay-plugin", | ||
"version": "0.9.3", | ||
"version": "0.10.0", | ||
"description": "Babel Relay Plugin for transpiling GraphQL queries for use with Relay.", | ||
@@ -26,3 +26,3 @@ "license": "BSD-3-Clause", | ||
"babel-core": "^6.9.0", | ||
"babel-jest": "^14.0.0", | ||
"babel-jest": "^15.0.0", | ||
"babel-plugin-syntax-flow": "^6.8.0", | ||
@@ -35,5 +35,5 @@ "babel-plugin-syntax-object-rest-spread": "^6.8.0", | ||
"babel-preset-es2015": "^6.9.0", | ||
"flow-bin": "^0.30.0", | ||
"flow-bin": "^0.36.0", | ||
"glob": "^7.0.3", | ||
"jest-cli": "^14.0.0", | ||
"jest-cli": "^15.1.1", | ||
"minimist": "^1.2.0", | ||
@@ -44,6 +44,6 @@ "mkdirp": "^0.5.1", | ||
"dependencies": { | ||
"graphql": "^0.6.0" | ||
"graphql": "0.8.2" | ||
}, | ||
"jest": { | ||
"persistModuleRegistryBetweenSpecs": true, | ||
"automock": true, | ||
"testPathIgnorePatterns": [ | ||
@@ -50,0 +50,0 @@ "<rootDir>/node_modules" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
101806
2292
+ Addedgraphql@0.8.2(transitive)
- Removedgraphql@0.6.2(transitive)
Updatedgraphql@0.8.2