apollo-codegen
Advanced tools
Comparing version 0.17.0-alpha.3 to 0.17.0-alpha.4
@@ -163,3 +163,3 @@ "use strict"; | ||
this.withinBlock(() => { | ||
this.printOnNewline(`snapshot = newValue.snapshot`); | ||
this.printOnNewline(`snapshot += newValue.snapshot`); | ||
}); | ||
@@ -190,6 +190,6 @@ }); | ||
this.printOnNewline(`guard let newValue = newValue else { return }`); | ||
this.printOnNewline(`snapshot = newValue.snapshot`); | ||
this.printOnNewline(`snapshot += newValue.snapshot`); | ||
} | ||
else { | ||
this.printOnNewline(`snapshot = newValue.snapshot`); | ||
this.printOnNewline(`snapshot += newValue.snapshot`); | ||
} | ||
@@ -263,3 +263,3 @@ }); | ||
const valueExpression = graphql_1.isCompositeType(graphql_1.getNamedType(type)) | ||
? this.helpers.mapExpressionForType(type, `$0.snapshot`, language_1.escapeIdentifierIfNeeded(propertyName)) | ||
? this.helpers.mapExpressionForType(type, (identifier) => `${identifier}.snapshot`, language_1.escapeIdentifierIfNeeded(propertyName)) | ||
: language_1.escapeIdentifierIfNeeded(propertyName); | ||
@@ -289,3 +289,3 @@ return `"${responseKey}": ${valueExpression}`; | ||
} | ||
getter += this.helpers.mapExpressionForType(type, `${structName}(snapshot: $0)`); | ||
getter += this.helpers.mapExpressionForType(type, (identifier) => `${structName}(snapshot: ${identifier})`); | ||
this.printOnNewline(getter); | ||
@@ -295,3 +295,3 @@ }); | ||
this.withinBlock(() => { | ||
let newValueExpression = 'newValue' + this.helpers.mapExpressionForType(type, `$0.snapshot`); | ||
let newValueExpression = this.helpers.mapExpressionForType(type, (identifier) => `${identifier}.snapshot`, 'newValue'); | ||
this.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${responseKey}")`); | ||
@@ -298,0 +298,0 @@ }); |
@@ -145,3 +145,3 @@ "use strict"; | ||
} | ||
mapExpressionForType(type, expression, prefix = '') { | ||
mapExpressionForType(type, expression, identifier = '') { | ||
let isOptional; | ||
@@ -157,13 +157,13 @@ if (type instanceof graphql_1.GraphQLNonNull) { | ||
if (isOptional) { | ||
return `${prefix}.flatMap { $0.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} } }`; | ||
return `${identifier}.flatMap { $0.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} } }`; | ||
} | ||
else { | ||
return `${prefix}.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} }`; | ||
return `${identifier}.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} }`; | ||
} | ||
} | ||
else if (isOptional) { | ||
return `${prefix}.flatMap { ${expression} }`; | ||
return `${identifier}.flatMap { ${expression('$0')} }`; | ||
} | ||
else { | ||
return expression; | ||
return expression(identifier); | ||
} | ||
@@ -170,0 +170,0 @@ } |
{ | ||
"name": "apollo-codegen", | ||
"version": "0.17.0-alpha.3", | ||
"version": "0.17.0-alpha.4", | ||
"description": "Generate API code or type annotations based on a GraphQL schema and query documents", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -254,3 +254,3 @@ import { | ||
this.withinBlock(() => { | ||
this.printOnNewline(`snapshot = newValue.snapshot`); | ||
this.printOnNewline(`snapshot += newValue.snapshot`); | ||
}); | ||
@@ -288,5 +288,5 @@ }); | ||
this.printOnNewline(`guard let newValue = newValue else { return }`); | ||
this.printOnNewline(`snapshot = newValue.snapshot`); | ||
this.printOnNewline(`snapshot += newValue.snapshot`); | ||
} else { | ||
this.printOnNewline(`snapshot = newValue.snapshot`); | ||
this.printOnNewline(`snapshot += newValue.snapshot`); | ||
} | ||
@@ -397,6 +397,6 @@ }); | ||
propertyAssignmentForField(field: Field & Property) { | ||
propertyAssignmentForField(field: { responseKey: string, propertyName: string, type: GraphQLType }) { | ||
const { responseKey, propertyName, type } = field; | ||
const valueExpression = isCompositeType(getNamedType(type)) | ||
? this.helpers.mapExpressionForType(type, `$0.snapshot`, escapeIdentifierIfNeeded(propertyName)) | ||
? this.helpers.mapExpressionForType(type, (identifier) => `${identifier}.snapshot`, escapeIdentifierIfNeeded(propertyName)) | ||
: escapeIdentifierIfNeeded(propertyName); | ||
@@ -431,3 +431,3 @@ return `"${responseKey}": ${valueExpression}`; | ||
} | ||
getter += this.helpers.mapExpressionForType(type, `${structName}(snapshot: $0)`); | ||
getter += this.helpers.mapExpressionForType(type, (identifier) => `${structName}(snapshot: ${identifier})`); | ||
this.printOnNewline(getter); | ||
@@ -437,3 +437,3 @@ }); | ||
this.withinBlock(() => { | ||
let newValueExpression = 'newValue' + this.helpers.mapExpressionForType(type, `$0.snapshot`); | ||
let newValueExpression = this.helpers.mapExpressionForType(type, (identifier) => `${identifier}.snapshot`, 'newValue'); | ||
this.printOnNewline(`snapshot.updateValue(${newValueExpression}, forKey: "${responseKey}")`); | ||
@@ -440,0 +440,0 @@ }); |
@@ -203,3 +203,3 @@ import { | ||
mapExpressionForType(type: GraphQLType, expression: string, prefix = ''): string { | ||
mapExpressionForType(type: GraphQLType, expression: (identifier: string) => string, identifier = ''): string { | ||
let isOptional; | ||
@@ -215,12 +215,12 @@ if (type instanceof GraphQLNonNull) { | ||
if (isOptional) { | ||
return `${prefix}.flatMap { $0.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} } }`; | ||
return `${identifier}.flatMap { $0.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} } }`; | ||
} else { | ||
return `${prefix}.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} }`; | ||
return `${identifier}.map { ${this.mapExpressionForType(type.ofType, expression, '$0')} }`; | ||
} | ||
} else if (isOptional) { | ||
return `${prefix}.flatMap { ${expression} }`; | ||
return `${identifier}.flatMap { ${expression('$0')} }`; | ||
} else { | ||
return expression; | ||
return expression(identifier); | ||
} | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
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
437302