Socket
Socket
Sign inDemoInstall

apollo-codegen

Package Overview
Dependencies
Maintainers
3
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.18.8 to 0.19.0

77

lib/swift/codeGeneration.js

@@ -105,3 +105,3 @@ "use strict";

if (source) {
this.printOnNewline('public static let operationString =');
this.printOnNewline('public let operationDefinition =');
this.withIndent(() => {

@@ -116,9 +116,9 @@ this.multilineString(source);

this.printNewlineIfNeeded();
this.printOnNewline(`public static let operationIdentifier: String? = "${operationId}"`);
this.printOnNewline(`public let operationIdentifier: String? = "${operationId}"`);
}
if (fragmentsReferenced.size > 0) {
this.printNewlineIfNeeded();
this.printOnNewline('public static var requestString: String { return operationString');
this.printOnNewline('public var queryDocument: String { return operationDefinition');
fragmentsReferenced.forEach(fragmentName => {
this.print(`.appending(${this.helpers.structNameForFragmentName(fragmentName)}.fragmentString)`);
this.print(`.appending(${this.helpers.structNameForFragmentName(fragmentName)}.fragmentDefinition)`);
});

@@ -161,3 +161,3 @@ this.print(' }');

if (source) {
this.printOnNewline('public static let fragmentString =');
this.printOnNewline('public static let fragmentDefinition =');
this.withIndent(() => {

@@ -205,10 +205,7 @@ this.multilineString(source);

this.printNewlineIfNeeded();
this.propertyDeclaration({
propertyName: 'snapshot',
typeName: 'Snapshot'
});
this.printOnNewline(`public private(set) var resultMap: ResultMap`);
this.printNewlineIfNeeded();
this.printOnNewline('public init(snapshot: Snapshot)');
this.printOnNewline('public init(unsafeResultMap: ResultMap)');
this.withinBlock(() => {
this.printOnNewline(`self.snapshot = snapshot`);
this.printOnNewline(`self.resultMap = unsafeResultMap`);
});

@@ -233,7 +230,7 @@ if (typeCase) {

this.withinBlock(() => {
this.printOnNewline(`return Fragments(snapshot: snapshot)`);
this.printOnNewline(`return Fragments(unsafeResultMap: resultMap)`);
});
this.printOnNewline('set');
this.withinBlock(() => {
this.printOnNewline(`snapshot += newValue.snapshot`);
this.printOnNewline(`resultMap += newValue.resultMap`);
});

@@ -244,5 +241,7 @@ });

}, () => {
this.propertyDeclaration({
propertyName: 'snapshot',
typeName: 'Snapshot'
this.printOnNewline(`public private(set) var resultMap: ResultMap`);
this.printNewlineIfNeeded();
this.printOnNewline('public init(unsafeResultMap: ResultMap)');
this.withinBlock(() => {
this.printOnNewline(`self.resultMap = unsafeResultMap`);
});

@@ -257,5 +256,5 @@ for (const fragmentSpread of fragmentSpreads) {

if (isConditional) {
this.printOnNewline(`if !${structName}.possibleTypes.contains(snapshot["__typename"]! as! String) { return nil }`);
this.printOnNewline(`if !${structName}.possibleTypes.contains(resultMap["__typename"]! as! String) { return nil }`);
}
this.printOnNewline(`return ${structName}(snapshot: snapshot)`);
this.printOnNewline(`return ${structName}(unsafeResultMap: resultMap)`);
});

@@ -266,6 +265,6 @@ this.printOnNewline('set');

this.printOnNewline(`guard let newValue = newValue else { return }`);
this.printOnNewline(`snapshot += newValue.snapshot`);
this.printOnNewline(`resultMap += newValue.resultMap`);
}
else {
this.printOnNewline(`snapshot += newValue.snapshot`);
this.printOnNewline(`resultMap += newValue.resultMap`);
}

@@ -311,3 +310,3 @@ });

this.withinBlock(() => {
this.printOnNewline(printing_1.wrap(`self.init(snapshot: [`, printing_1.join([
this.printOnNewline(printing_1.wrap(`self.init(unsafeResultMap: [`, printing_1.join([
`"__typename": "${variant.possibleTypes[0]}"`,

@@ -332,3 +331,3 @@ ...properties.map(this.propertyAssignmentForField, this)

this.withinBlock(() => {
this.printOnNewline(printing_1.wrap(`return ${structName}(snapshot: [`, printing_1.join([`"__typename": "${possibleType}"`, ...properties.map(this.propertyAssignmentForField, this)], ', ') || ':', `])`));
this.printOnNewline(printing_1.wrap(`return ${structName}(unsafeResultMap: [`, printing_1.join([`"__typename": "${possibleType}"`, ...properties.map(this.propertyAssignmentForField, this)], ', ') || ':', `])`));
});

@@ -341,3 +340,3 @@ }

const valueExpression = graphql_1.isCompositeType(graphql_1.getNamedType(type))
? this.helpers.mapExpressionForType(type, isConditional, expression => `${expression}.snapshot`, language_1.escapeIdentifierIfNeeded(propertyName), structName, 'Snapshot')
? this.helpers.mapExpressionForType(type, isConditional, expression => `${expression}.resultMap`, language_1.escapeIdentifierIfNeeded(propertyName), structName, 'ResultMap')
: language_1.escapeIdentifierIfNeeded(propertyName);

@@ -359,16 +358,16 @@ return `"${responseKey}": ${valueExpression}`;

this.withinBlock(() => {
const snapshotTypeName = this.helpers.typeNameFromGraphQLType(type, 'Snapshot', false);
const resultMapTypeName = this.helpers.typeNameFromGraphQLType(type, 'ResultMap', false);
let expression;
if (isOptional) {
expression = `(snapshot["${responseKey}"] as? ${snapshotTypeName})`;
expression = `(resultMap["${responseKey}"] as? ${resultMapTypeName})`;
}
else {
expression = `(snapshot["${responseKey}"] as! ${snapshotTypeName})`;
expression = `(resultMap["${responseKey}"] as! ${resultMapTypeName})`;
}
this.printOnNewline(`return ${this.helpers.mapExpressionForType(type, isConditional, expression => `${structName}(snapshot: ${expression})`, expression, 'Snapshot', structName)}`);
this.printOnNewline(`return ${this.helpers.mapExpressionForType(type, isConditional, expression => `${structName}(unsafeResultMap: ${expression})`, expression, 'ResultMap', structName)}`);
});
this.printOnNewline('set');
this.withinBlock(() => {
let newValueExpression = this.helpers.mapExpressionForType(type, isConditional, expression => `${expression}.snapshot`, 'newValue', structName, 'Snapshot');
this.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
let newValueExpression = this.helpers.mapExpressionForType(type, isConditional, expression => `${expression}.resultMap`, 'newValue', structName, 'ResultMap');
this.printOnNewline(`resultMap.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
});

@@ -380,6 +379,6 @@ }

if (isOptional) {
this.printOnNewline(`return (snapshot["${responseKey}"] as? Snapshot).flatMap { ${structName}(snapshot: $0) }`);
this.printOnNewline(`return (resultMap["${responseKey}"] as? ResultMap).flatMap { ${structName}(unsafeResultMap: $0) }`);
}
else {
this.printOnNewline(`return ${structName}(snapshot: snapshot["${responseKey}"]! as! Snapshot)`);
this.printOnNewline(`return ${structName}(unsafeResultMap: resultMap["${responseKey}"]! as! ResultMap)`);
}

@@ -391,8 +390,8 @@ });

if (isOptional) {
newValueExpression = 'newValue?.snapshot';
newValueExpression = 'newValue?.resultMap';
}
else {
newValueExpression = 'newValue.snapshot';
newValueExpression = 'newValue.resultMap';
}
this.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
this.printOnNewline(`resultMap.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
});

@@ -405,6 +404,6 @@ }

if (isOptional) {
this.printOnNewline(`return snapshot["${responseKey}"] as? ${typeName.slice(0, -1)}`);
this.printOnNewline(`return resultMap["${responseKey}"] as? ${typeName.slice(0, -1)}`);
}
else {
this.printOnNewline(`return snapshot["${responseKey}"]! as! ${typeName}`);
this.printOnNewline(`return resultMap["${responseKey}"]! as! ${typeName}`);
}

@@ -414,3 +413,3 @@ });

this.withinBlock(() => {
this.printOnNewline(`snapshot.updateValue(newValue, forKey: "${responseKey}")`);
this.printOnNewline(`resultMap.updateValue(newValue, forKey: "${responseKey}")`);
});

@@ -428,3 +427,3 @@ }

this.printOnNewline(`if !${structName}.possibleTypes.contains(__typename) { return nil }`);
this.printOnNewline(`return ${structName}(snapshot: snapshot)`);
this.printOnNewline(`return ${structName}(unsafeResultMap: resultMap)`);
});

@@ -434,3 +433,3 @@ this.printOnNewline('set');

this.printOnNewline(`guard let newValue = newValue else { return }`);
this.printOnNewline(`snapshot = newValue.snapshot`);
this.printOnNewline(`resultMap = newValue.resultMap`);
});

@@ -437,0 +436,0 @@ });

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

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

"glob": "^7.1.2",
"graphql": "^0.12.3",
"graphql": "^0.13.1",
"graphql-config": "^1.1.1",

@@ -53,0 +53,0 @@ "inflected": "^2.0.3",

@@ -151,3 +151,3 @@ import * as path from 'path';

if (source) {
this.printOnNewline('public static let operationString =');
this.printOnNewline('public let operationDefinition =');
this.withIndent(() => {

@@ -167,3 +167,3 @@ this.multilineString(source);

this.printNewlineIfNeeded();
this.printOnNewline(`public static let operationIdentifier: String? = "${operationId}"`);
this.printOnNewline(`public let operationIdentifier: String? = "${operationId}"`);
}

@@ -173,5 +173,5 @@

this.printNewlineIfNeeded();
this.printOnNewline('public static var requestString: String { return operationString');
this.printOnNewline('public var queryDocument: String { return operationDefinition');
fragmentsReferenced.forEach(fragmentName => {
this.print(`.appending(${this.helpers.structNameForFragmentName(fragmentName)}.fragmentString)`);
this.print(`.appending(${this.helpers.structNameForFragmentName(fragmentName)}.fragmentDefinition)`);
});

@@ -232,3 +232,3 @@ this.print(' }');

if (source) {
this.printOnNewline('public static let fragmentString =');
this.printOnNewline('public static let fragmentDefinition =');
this.withIndent(() => {

@@ -317,11 +317,8 @@ this.multilineString(source);

this.propertyDeclaration({
propertyName: 'snapshot',
typeName: 'Snapshot'
});
this.printOnNewline(`public private(set) var resultMap: ResultMap`);
this.printNewlineIfNeeded();
this.printOnNewline('public init(snapshot: Snapshot)');
this.printOnNewline('public init(unsafeResultMap: ResultMap)');
this.withinBlock(() => {
this.printOnNewline(`self.snapshot = snapshot`);
this.printOnNewline(`self.resultMap = unsafeResultMap`);
});

@@ -356,7 +353,7 @@

this.withinBlock(() => {
this.printOnNewline(`return Fragments(snapshot: snapshot)`);
this.printOnNewline(`return Fragments(unsafeResultMap: resultMap)`);
});
this.printOnNewline('set');
this.withinBlock(() => {
this.printOnNewline(`snapshot += newValue.snapshot`);
this.printOnNewline(`resultMap += newValue.resultMap`);
});

@@ -370,5 +367,8 @@ });

() => {
this.propertyDeclaration({
propertyName: 'snapshot',
typeName: 'Snapshot'
this.printOnNewline(`public private(set) var resultMap: ResultMap`);
this.printNewlineIfNeeded();
this.printOnNewline('public init(unsafeResultMap: ResultMap)');
this.withinBlock(() => {
this.printOnNewline(`self.resultMap = unsafeResultMap`);
});

@@ -386,6 +386,6 @@

this.printOnNewline(
`if !${structName}.possibleTypes.contains(snapshot["__typename"]! as! String) { return nil }`
`if !${structName}.possibleTypes.contains(resultMap["__typename"]! as! String) { return nil }`
);
}
this.printOnNewline(`return ${structName}(snapshot: snapshot)`);
this.printOnNewline(`return ${structName}(unsafeResultMap: resultMap)`);
});

@@ -396,5 +396,5 @@ this.printOnNewline('set');

this.printOnNewline(`guard let newValue = newValue else { return }`);
this.printOnNewline(`snapshot += newValue.snapshot`);
this.printOnNewline(`resultMap += newValue.resultMap`);
} else {
this.printOnNewline(`snapshot += newValue.snapshot`);
this.printOnNewline(`resultMap += newValue.resultMap`);
}

@@ -453,3 +453,3 @@ });

wrap(
`self.init(snapshot: [`,
`self.init(unsafeResultMap: [`,
join(

@@ -490,3 +490,3 @@ [

wrap(
`return ${structName}(snapshot: [`,
`return ${structName}(unsafeResultMap: [`,
join(

@@ -510,6 +510,6 @@ [`"__typename": "${possibleType}"`, ...properties.map(this.propertyAssignmentForField, this)],

isConditional,
expression => `${expression}.snapshot`,
expression => `${expression}.resultMap`,
escapeIdentifierIfNeeded(propertyName),
structName!,
'Snapshot'
'ResultMap'
)

@@ -538,8 +538,8 @@ : escapeIdentifierIfNeeded(propertyName);

this.withinBlock(() => {
const snapshotTypeName = this.helpers.typeNameFromGraphQLType(type, 'Snapshot', false);
const resultMapTypeName = this.helpers.typeNameFromGraphQLType(type, 'ResultMap', false);
let expression;
if (isOptional) {
expression = `(snapshot["${responseKey}"] as? ${snapshotTypeName})`;
expression = `(resultMap["${responseKey}"] as? ${resultMapTypeName})`;
} else {
expression = `(snapshot["${responseKey}"] as! ${snapshotTypeName})`;
expression = `(resultMap["${responseKey}"] as! ${resultMapTypeName})`;
}

@@ -549,5 +549,5 @@ this.printOnNewline(`return ${this.helpers.mapExpressionForType(

isConditional,
expression => `${structName}(snapshot: ${expression})`,
expression => `${structName}(unsafeResultMap: ${expression})`,
expression,
'Snapshot',
'ResultMap',
structName

@@ -561,8 +561,8 @@ )}`);

isConditional,
expression => `${expression}.snapshot`,
expression => `${expression}.resultMap`,
'newValue',
structName,
'Snapshot'
'ResultMap'
);
this.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
this.printOnNewline(`resultMap.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
});

@@ -574,6 +574,6 @@ } else {

this.printOnNewline(
`return (snapshot["${responseKey}"] as? Snapshot).flatMap { ${structName}(snapshot: $0) }`
`return (resultMap["${responseKey}"] as? ResultMap).flatMap { ${structName}(unsafeResultMap: $0) }`
);
} else {
this.printOnNewline(`return ${structName}(snapshot: snapshot["${responseKey}"]! as! Snapshot)`);
this.printOnNewline(`return ${structName}(unsafeResultMap: resultMap["${responseKey}"]! as! ResultMap)`);
}

@@ -585,7 +585,7 @@ });

if (isOptional) {
newValueExpression = 'newValue?.snapshot';
newValueExpression = 'newValue?.resultMap';
} else {
newValueExpression = 'newValue.snapshot';
newValueExpression = 'newValue.resultMap';
}
this.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
this.printOnNewline(`resultMap.updateValue(${newValueExpression}, forKey: "${responseKey}")`);
});

@@ -597,5 +597,5 @@ }

if (isOptional) {
this.printOnNewline(`return snapshot["${responseKey}"] as? ${typeName.slice(0, -1)}`);
this.printOnNewline(`return resultMap["${responseKey}"] as? ${typeName.slice(0, -1)}`);
} else {
this.printOnNewline(`return snapshot["${responseKey}"]! as! ${typeName}`);
this.printOnNewline(`return resultMap["${responseKey}"]! as! ${typeName}`);
}

@@ -605,3 +605,3 @@ });

this.withinBlock(() => {
this.printOnNewline(`snapshot.updateValue(newValue, forKey: "${responseKey}")`);
this.printOnNewline(`resultMap.updateValue(newValue, forKey: "${responseKey}")`);
});

@@ -621,3 +621,3 @@ }

this.printOnNewline(`if !${structName}.possibleTypes.contains(__typename) { return nil }`);
this.printOnNewline(`return ${structName}(snapshot: snapshot)`);
this.printOnNewline(`return ${structName}(unsafeResultMap: resultMap)`);
});

@@ -627,3 +627,3 @@ this.printOnNewline('set');

this.printOnNewline(`guard let newValue = newValue else { return }`);
this.printOnNewline(`snapshot = newValue.snapshot`);
this.printOnNewline(`resultMap = newValue.resultMap`);
});

@@ -630,0 +630,0 @@ });

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