apollo-codegen
Advanced tools
Comparing version 0.17.1 to 0.17.2
@@ -11,2 +11,3 @@ "use strict"; | ||
generator.printOnNewline('/* @flow */'); | ||
generator.printOnNewline('/* eslint-disable */'); | ||
generator.printOnNewline('// This file was automatically generated and should not be edited.'); | ||
@@ -13,0 +14,0 @@ typeDeclarationForGraphQLType(context.typesUsed.forEach(type => typeDeclarationForGraphQLType(generator, type))); |
@@ -519,9 +519,48 @@ "use strict"; | ||
this.comment(description); | ||
this.printOnNewline(`public enum ${name}: String, Apollo.JSONDecodable, Apollo.JSONEncodable`); | ||
this.printOnNewline(`public enum ${name}: RawRepresentable, Equatable, Apollo.JSONDecodable, Apollo.JSONEncodable`); | ||
this.withinBlock(() => { | ||
this.printOnNewline('public typealias RawValue = String'); | ||
values.forEach(value => { | ||
this.comment(value.description); | ||
this.deprecationAttributes(value.isDeprecated, value.deprecationReason); | ||
this.printOnNewline(`case ${language_1.escapeIdentifierIfNeeded(this.helpers.enumCaseName(value.name))} = "${value.value}"`); | ||
this.printOnNewline(`case ${language_1.escapeIdentifierIfNeeded(this.helpers.enumCaseName(value.name))}`); | ||
}); | ||
this.comment('Auto generated constant for unknown enum values'); | ||
this.printOnNewline('case unknown(RawValue)'); | ||
this.printNewlineIfNeeded(); | ||
this.printOnNewline('public init?(rawValue: RawValue)'); | ||
this.withinBlock(() => { | ||
this.printOnNewline('switch rawValue'); | ||
this.withinBlock(() => { | ||
values.forEach(value => { | ||
this.printOnNewline(`case "${value.value}": self = ${language_1.escapeIdentifierIfNeeded(this.helpers.enumDotCaseName(value.name))}`); | ||
}); | ||
this.printOnNewline(`default: self = .unknown(rawValue)`); | ||
}); | ||
}); | ||
this.printNewlineIfNeeded(); | ||
this.printOnNewline('public var rawValue: RawValue'); | ||
this.withinBlock(() => { | ||
this.printOnNewline('switch self'); | ||
this.withinBlock(() => { | ||
values.forEach(value => { | ||
this.printOnNewline(`case ${language_1.escapeIdentifierIfNeeded(this.helpers.enumDotCaseName(value.name))}: return "${value.value}"`); | ||
}); | ||
this.printOnNewline(`case .unknown(let value): return value`); | ||
}); | ||
}); | ||
this.printNewlineIfNeeded(); | ||
this.printOnNewline(`public static func == (lhs: ${name}, rhs: ${name}) -> Bool`); | ||
this.withinBlock(() => { | ||
this.printOnNewline('switch (lhs, rhs)'); | ||
this.withinBlock(() => { | ||
values.forEach(value => { | ||
const enumDotCaseName = language_1.escapeIdentifierIfNeeded(this.helpers.enumDotCaseName(value.name)); | ||
const tuple = `(${enumDotCaseName}, ${enumDotCaseName})`; | ||
this.printOnNewline(`case ${tuple}: return true`); | ||
}); | ||
this.printOnNewline(`case (.unknown(let lhsValue), .unknown(let rhsValue)): return lhsValue == rhsValue`); | ||
this.printOnNewline(`default: return false`); | ||
}); | ||
}); | ||
}); | ||
@@ -528,0 +567,0 @@ } |
@@ -68,2 +68,5 @@ "use strict"; | ||
} | ||
enumDotCaseName(name) { | ||
return `.${change_case_1.camelCase(name)}`; | ||
} | ||
operationClassName(name) { | ||
@@ -70,0 +73,0 @@ return change_case_1.pascalCase(name); |
{ | ||
"name": "apollo-codegen", | ||
"version": "0.17.1", | ||
"version": "0.17.2", | ||
"description": "Generate API code or type annotations based on a GraphQL schema and query documents", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -42,2 +42,3 @@ import { | ||
generator.printOnNewline('/* @flow */'); | ||
generator.printOnNewline('/* eslint-disable */'); | ||
generator.printOnNewline('// This file was automatically generated and should not be edited.'); | ||
@@ -44,0 +45,0 @@ typeDeclarationForGraphQLType(context.typesUsed.forEach(type => |
@@ -735,4 +735,6 @@ import * as path from 'path'; | ||
this.comment(description); | ||
this.printOnNewline(`public enum ${name}: String, Apollo.JSONDecodable, Apollo.JSONEncodable`); | ||
this.printOnNewline(`public enum ${name}: RawRepresentable, Equatable, Apollo.JSONDecodable, Apollo.JSONEncodable`); | ||
this.withinBlock(() => { | ||
this.printOnNewline('public typealias RawValue = String') | ||
values.forEach(value => { | ||
@@ -742,5 +744,52 @@ this.comment(value.description); | ||
this.printOnNewline( | ||
`case ${escapeIdentifierIfNeeded(this.helpers.enumCaseName(value.name))} = "${value.value}"` | ||
`case ${escapeIdentifierIfNeeded(this.helpers.enumCaseName(value.name))}` | ||
); | ||
}); | ||
this.comment('Auto generated constant for unknown enum values'); | ||
this.printOnNewline('case unknown(RawValue)'); | ||
this.printNewlineIfNeeded(); | ||
this.printOnNewline('public init?(rawValue: RawValue)'); | ||
this.withinBlock(() => { | ||
this.printOnNewline('switch rawValue'); | ||
this.withinBlock(() => { | ||
values.forEach(value => { | ||
this.printOnNewline( | ||
`case "${value.value}": self = ${escapeIdentifierIfNeeded(this.helpers.enumDotCaseName(value.name))}` | ||
); | ||
}); | ||
this.printOnNewline(`default: self = .unknown(rawValue)`); | ||
}); | ||
}); | ||
this.printNewlineIfNeeded(); | ||
this.printOnNewline('public var rawValue: RawValue'); | ||
this.withinBlock(() => { | ||
this.printOnNewline('switch self'); | ||
this.withinBlock(() => { | ||
values.forEach(value => { | ||
this.printOnNewline( | ||
`case ${escapeIdentifierIfNeeded(this.helpers.enumDotCaseName(value.name))}: return "${value.value}"` | ||
); | ||
}); | ||
this.printOnNewline(`case .unknown(let value): return value`); | ||
}); | ||
}); | ||
this.printNewlineIfNeeded(); | ||
this.printOnNewline(`public static func == (lhs: ${name}, rhs: ${name}) -> Bool`); | ||
this.withinBlock(() => { | ||
this.printOnNewline('switch (lhs, rhs)'); | ||
this.withinBlock(() => { | ||
values.forEach(value => { | ||
const enumDotCaseName = escapeIdentifierIfNeeded(this.helpers.enumDotCaseName(value.name)); | ||
const tuple = `(${enumDotCaseName}, ${enumDotCaseName})` | ||
this.printOnNewline( | ||
`case ${tuple}: return true` | ||
); | ||
}); | ||
this.printOnNewline(`case (.unknown(let lhsValue), .unknown(let rhsValue)): return lhsValue == rhsValue`); | ||
this.printOnNewline(`default: return false`); | ||
}); | ||
}); | ||
}); | ||
@@ -747,0 +796,0 @@ } |
@@ -91,2 +91,6 @@ import { | ||
enumDotCaseName(name: string) { | ||
return `.${camelCase(name)}`; | ||
} | ||
operationClassName(name: string) { | ||
@@ -93,0 +97,0 @@ return pascalCase(name); |
Sorry, the diff of this file is not supported yet
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
474676
8308