Socket
Socket
Sign inDemoInstall

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.12.0 to 0.12.1

135

lib/swift/codeGeneration.js

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

var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _extends2 = require('babel-runtime/helpers/extends');

@@ -243,22 +247,48 @@

generator.printNewlineIfNeeded();
generator.printOnNewline(`public init`);
generator.print('(');
generator.print((0, _printing.join)(fields.map((_ref7) => {
let propertyName = _ref7.propertyName,
type = _ref7.type,
typeName = _ref7.typeName,
isOptional = _ref7.isOptional;
return (0, _printing.join)([`${propertyName}: ${typeName}`, isOptional && ' = nil']);
}), ', '));
generator.print(')');
if (inlineFragments.length < 1) {
generator.printNewlineIfNeeded();
generator.printOnNewline(`public init`);
generator.print('(');
generator.print((0, _printing.join)(fields.map((_ref7) => {
let propertyName = _ref7.propertyName,
type = _ref7.type,
typeName = _ref7.typeName,
isOptional = _ref7.isOptional;
return (0, _printing.join)([`${propertyName}: ${typeName}`, isOptional && ' = nil']);
}), ', '));
generator.print(')');
generator.withinBlock(() => {
generator.printOnNewline((0, _printing.wrap)(`self.snapshot = [`, (0, _printing.join)(fields.map((_ref8) => {
let name = _ref8.name,
propertyName = _ref8.propertyName;
return `"${propertyName}": ${propertyName}`;
}), ', ') || ':', `]`));
});
generator.withinBlock(() => {
generator.printOnNewline((0, _printing.wrap)(`self.init(snapshot: [`, (0, _printing.join)(fields.map((_ref8) => {
let name = _ref8.name,
propertyName = _ref8.propertyName;
return `"${propertyName}": ${propertyName}`;
}), ', ') || ':', `])`));
});
} else {
inlineFragments.forEach(inlineFragment => {
generator.printNewlineIfNeeded();
generator.printOnNewline(`public static func make${inlineFragment.typeCondition}`);
generator.print('(');
const properties = (0, _naming.propertiesFromSelectionSet)(generator.context, inlineFragment.selectionSet, inlineFragment.structName);
const fields = properties.filter(property => property.kind === 'Field' && property.propertyName !== '__typename');
generator.print((0, _printing.join)(fields.map((_ref9) => {
let propertyName = _ref9.propertyName,
type = _ref9.type,
typeName = _ref9.typeName,
isOptional = _ref9.isOptional;
return (0, _printing.join)([`${propertyName}: ${typeName}`, isOptional && ' = nil']);
}), ', '));
generator.print(`) -> ${structName}`);
generator.withinBlock(() => {
generator.printOnNewline((0, _printing.wrap)(`return ${structName}(snapshot: [`, (0, _printing.join)([`"__typename": "${inlineFragment.typeCondition}"`].concat((0, _toConsumableArray3.default)(fields.map((_ref10) => {
let name = _ref10.name,
propertyName = _ref10.propertyName;
return `"${propertyName}": ${propertyName}`;
}))), ', '), `])`));
});
});
}
properties.forEach(property => {

@@ -287,6 +317,6 @@ if (property.kind === 'FragmentSpread') return;

if (inlineFragments.length > 0) {
inlineFragments.forEach((_ref9) => {
let structName = _ref9.structName,
typeCondition = _ref9.typeCondition,
selectionSet = _ref9.selectionSet;
inlineFragments.forEach((_ref11) => {
let structName = _ref11.structName,
typeCondition = _ref11.typeCondition,
selectionSet = _ref11.selectionSet;

@@ -308,7 +338,7 @@ structDeclarationForSelectionSet(generator, {

(0, _language.propertyDeclaration)(generator, { propertyName: "snapshot", typeName: "Snapshot" });
fragmentSpreads.forEach((_ref10) => {
let propertyName = _ref10.propertyName,
bareTypeName = _ref10.bareTypeName,
typeName = _ref10.typeName,
isOptional = _ref10.isOptional;
fragmentSpreads.forEach((_ref12) => {
let propertyName = _ref12.propertyName,
bareTypeName = _ref12.bareTypeName,
typeName = _ref12.typeName,
isOptional = _ref12.isOptional;

@@ -410,5 +440,4 @@ generator.printNewlineIfNeeded();

generator.withinBlock(() => {
let setter = `snapshot["${propertyName}"] = newValue`;
setter += mapExpressionForType(generator.context, type, `$0.snapshot`);
generator.printOnNewline(setter);
let newValueExpression = "newValue" + mapExpressionForType(generator.context, type, `$0.snapshot`);
generator.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${propertyName}")`);
});

@@ -422,8 +451,9 @@ } else {

generator.withinBlock(() => {
generator.printOnNewline(`snapshot["${propertyName}"] = `);
let newValueExpression;
if (isOptional) {
generator.print('newValue?.snapshot');
newValueExpression = 'newValue?.snapshot';
} else {
generator.print('newValue.snapshot');
newValueExpression = 'newValue.snapshot';
}
generator.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${propertyName}")`);
});

@@ -438,3 +468,3 @@ }

generator.withinBlock(() => {
generator.printOnNewline(`snapshot["${propertyName}"] = newValue`);
generator.printOnNewline(`snapshot.updateValue(newValue, forKey: "${propertyName}")`);
});

@@ -448,7 +478,7 @@ }

generator.print('(');
generator.print((0, _printing.join)(properties.map((_ref11) => {
let propertyName = _ref11.propertyName,
type = _ref11.type,
typeName = _ref11.typeName,
isOptional = _ref11.isOptional;
generator.print((0, _printing.join)(properties.map((_ref13) => {
let propertyName = _ref13.propertyName,
type = _ref13.type,
typeName = _ref13.typeName,
isOptional = _ref13.isOptional;
return (0, _printing.join)([`${propertyName}: ${typeName}`, isOptional && ' = nil']);

@@ -459,4 +489,4 @@ }), ', '));

generator.withinBlock(() => {
properties.forEach((_ref12) => {
let propertyName = _ref12.propertyName;
properties.forEach((_ref14) => {
let propertyName = _ref14.propertyName;

@@ -533,8 +563,13 @@ generator.printOnNewline(`self.${propertyName} = ${propertyName}`);

generator.print('(');
generator.print((0, _printing.join)(properties.map((_ref13) => {
let propertyName = _ref13.propertyName,
type = _ref13.type,
typeName = _ref13.typeName,
isOptional = _ref13.isOptional;
return (0, _printing.join)([`${propertyName}: ${typeName}`, isOptional && ' = nil']);
generator.print((0, _printing.join)(properties.map((_ref15) => {
let propertyName = _ref15.propertyName,
type = _ref15.type,
typeName = _ref15.typeName,
isOptional = _ref15.isOptional;
if (isOptional) {
return `${propertyName}: Optional<${typeName}> = nil`;
} else {
return `${propertyName}: ${typeName}`;
}
}), ', '));

@@ -544,5 +579,5 @@ generator.print(')');

generator.withinBlock(() => {
generator.printOnNewline((0, _printing.wrap)(`graphQLMap = [`, (0, _printing.join)(properties.map((_ref14) => {
let name = _ref14.name,
propertyName = _ref14.propertyName;
generator.printOnNewline((0, _printing.wrap)(`graphQLMap = [`, (0, _printing.join)(properties.map((_ref16) => {
let name = _ref16.name,
propertyName = _ref16.propertyName;
return `"${name}": ${propertyName}`;

@@ -549,0 +584,0 @@ }), ', ') || ':', `]`));

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

var _printing = require('../utilities/printing');
var _language = require('./language');

@@ -56,6 +58,6 @@

function propertiesFromSelectionSet(context, selectionSet) {
function propertiesFromSelectionSet(context, selectionSet, namespace) {
return selectionSet.map(selection => {
if (selection.kind === 'Field') {
return propertyFromField(context, selection);
return propertyFromField(context, selection, namespace);
} else if (selection.kind === 'InlineFragment') {

@@ -69,3 +71,3 @@ return propertyFromInlineFragment(context, selection);

function propertyFromField(context, field) {
function propertyFromField(context, field, namespace) {
const name = field.name || field.responseName;

@@ -81,3 +83,3 @@ const unescapedPropertyName = isMetaFieldName(name) ? name : (0, _changeCase.camelCase)(name);

if ((0, _graphql.isCompositeType)(bareType)) {
const bareTypeName = (0, _language.escapeIdentifierIfNeeded)((0, _changeCase.pascalCase)(_inflected2.default.singularize(name)));
const bareTypeName = (0, _printing.join)([namespace, (0, _language.escapeIdentifierIfNeeded)((0, _changeCase.pascalCase)(_inflected2.default.singularize(name)))], '.');
const typeName = (0, _types.typeNameFromGraphQLType)(context, type, bareTypeName, isOptional);

@@ -84,0 +86,0 @@ return (0, _extends3.default)({}, field, { propertyName: propertyName, typeName: typeName, bareTypeName: bareTypeName, isOptional: isOptional, isList: isList, isComposite: true });

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

@@ -5,0 +5,0 @@ "main": "./lib/index.js",

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