-
Notifications
You must be signed in to change notification settings - Fork 27
Commit generated code for tests to provide more information to reviewers #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Generated from graphql_swift_gen gem | ||
|
||
open class Generated { | ||
open static func buildQuery(_ subfields: (QueryRootQuery) -> Void) -> QueryRootQuery { | ||
let root = QueryRootQuery() | ||
subfields(root) | ||
return root | ||
} | ||
|
||
open static func buildMutation(_ subfields: (MutationQuery) -> Void) -> MutationQuery { | ||
let root = MutationQuery() | ||
subfields(root) | ||
return root | ||
} | ||
} |
152 changes: 152 additions & 0 deletions
152
support/Tests/GraphQLSupportTests/Generated/Entry.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// Generated from graphql_swift_gen gem | ||
import Foundation | ||
|
||
import GraphQLSupport | ||
|
||
public protocol Entry { | ||
var typeName: String { get } | ||
|
||
var key: String { get } | ||
|
||
var ttl: Date? { get } | ||
|
||
func childResponseObjectMap() -> [GraphQL.AbstractResponse] | ||
|
||
func responseObject() -> GraphQL.AbstractResponse | ||
} | ||
|
||
extension Generated { | ||
open class EntryQuery: GraphQL.AbstractQuery, GraphQLQuery { | ||
public typealias Response = Entry | ||
|
||
@discardableResult | ||
open func key(aliasSuffix: String? = nil) -> EntryQuery { | ||
addField(field: "key", aliasSuffix: aliasSuffix) | ||
return self | ||
} | ||
|
||
@discardableResult | ||
open func ttl(aliasSuffix: String? = nil) -> EntryQuery { | ||
addField(field: "ttl", aliasSuffix: aliasSuffix) | ||
return self | ||
} | ||
|
||
override init() { | ||
super.init() | ||
addField(field: "__typename") | ||
} | ||
|
||
@discardableResult | ||
open func onIntegerEntry(subfields: (IntegerEntryQuery) -> Void) -> EntryQuery { | ||
let subquery = IntegerEntryQuery() | ||
subfields(subquery) | ||
addInlineFragment(on: "IntegerEntry", subfields: subquery) | ||
return self | ||
} | ||
|
||
@discardableResult | ||
open func onStringEntry(subfields: (StringEntryQuery) -> Void) -> EntryQuery { | ||
let subquery = StringEntryQuery() | ||
subfields(subquery) | ||
addInlineFragment(on: "StringEntry", subfields: subquery) | ||
return self | ||
} | ||
} | ||
|
||
open class UnknownEntry: GraphQL.AbstractResponse, GraphQLObject, Entry { | ||
public typealias Query = EntryQuery | ||
|
||
open override func deserializeValue(fieldName: String, value: Any) throws -> Any? { | ||
let fieldValue = value | ||
switch fieldName { | ||
case "key": | ||
guard let value = value as? String else { | ||
throw SchemaViolationError(type: UnknownEntry.self, field: fieldName, value: fieldValue) | ||
} | ||
return value | ||
|
||
case "ttl": | ||
if value is NSNull { return nil } | ||
guard let value = value as? String else { | ||
throw SchemaViolationError(type: UnknownEntry.self, field: fieldName, value: fieldValue) | ||
} | ||
return iso8601DateParser.date(from: value)! | ||
|
||
default: | ||
throw SchemaViolationError(type: UnknownEntry.self, field: fieldName, value: fieldValue) | ||
} | ||
} | ||
|
||
open var typeName: String { return field(field: "__typename") as! String } | ||
|
||
open static func create(fields: [String: Any]) throws -> Entry { | ||
guard let typeName = fields["__typename"] as? String else { | ||
throw SchemaViolationError(type: UnknownEntry.self, field: "__typename", value: fields["__typename"] ?? NSNull()) | ||
} | ||
switch typeName { | ||
case "IntegerEntry": | ||
return try IntegerEntry.init(fields: fields) | ||
|
||
case "StringEntry": | ||
return try StringEntry.init(fields: fields) | ||
|
||
default: | ||
return try UnknownEntry.init(fields: fields) | ||
} | ||
} | ||
|
||
open var key: String { | ||
return internalGetKey() | ||
} | ||
|
||
func internalGetKey(aliasSuffix: String? = nil) -> String { | ||
return field(field: "key", aliasSuffix: aliasSuffix) as! String | ||
} | ||
|
||
open var ttl: Date? { | ||
return internalGetTtl() | ||
} | ||
|
||
func internalGetTtl(aliasSuffix: String? = nil) -> Date? { | ||
return field(field: "ttl", aliasSuffix: aliasSuffix) as! Date? | ||
} | ||
|
||
override open func childObjectType(key: String) -> GraphQL.ChildObjectType { | ||
switch(key) { | ||
case "key": | ||
|
||
return .scalar | ||
|
||
case "ttl": | ||
|
||
return .scalar | ||
|
||
default: | ||
return .scalar | ||
} | ||
} | ||
|
||
override open func fetchChildObject(key: String) -> GraphQL.AbstractResponse? { | ||
switch(key) { | ||
default: | ||
break | ||
} | ||
return nil | ||
} | ||
|
||
override open func fetchChildObjectList(key: String) -> [GraphQL.AbstractResponse] { | ||
switch(key) { | ||
default: | ||
return [] | ||
} | ||
} | ||
|
||
open func childResponseObjectMap() -> [GraphQL.AbstractResponse] { | ||
return [] | ||
} | ||
|
||
open func responseObject() -> GraphQL.AbstractResponse { | ||
return self as GraphQL.AbstractResponse | ||
} | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
support/Tests/GraphQLSupportTests/Generated/EntryUnion.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// Generated from graphql_swift_gen gem | ||
import Foundation | ||
|
||
import GraphQLSupport | ||
|
||
public protocol EntryUnion { | ||
var typeName: String { get } | ||
|
||
func childResponseObjectMap() -> [GraphQL.AbstractResponse] | ||
|
||
func responseObject() -> GraphQL.AbstractResponse | ||
} | ||
|
||
extension Generated { | ||
open class EntryUnionQuery: GraphQL.AbstractQuery, GraphQLQuery { | ||
public typealias Response = EntryUnion | ||
|
||
override init() { | ||
super.init() | ||
addField(field: "__typename") | ||
} | ||
|
||
@discardableResult | ||
open func onIntegerEntry(subfields: (IntegerEntryQuery) -> Void) -> EntryUnionQuery { | ||
let subquery = IntegerEntryQuery() | ||
subfields(subquery) | ||
addInlineFragment(on: "IntegerEntry", subfields: subquery) | ||
return self | ||
} | ||
|
||
@discardableResult | ||
open func onStringEntry(subfields: (StringEntryQuery) -> Void) -> EntryUnionQuery { | ||
let subquery = StringEntryQuery() | ||
subfields(subquery) | ||
addInlineFragment(on: "StringEntry", subfields: subquery) | ||
return self | ||
} | ||
} | ||
|
||
open class UnknownEntryUnion: GraphQL.AbstractResponse, GraphQLObject, EntryUnion { | ||
public typealias Query = EntryUnionQuery | ||
|
||
open override func deserializeValue(fieldName: String, value: Any) throws -> Any? { | ||
let fieldValue = value | ||
switch fieldName { | ||
default: | ||
throw SchemaViolationError(type: UnknownEntryUnion.self, field: fieldName, value: fieldValue) | ||
} | ||
} | ||
|
||
open var typeName: String { return field(field: "__typename") as! String } | ||
|
||
open static func create(fields: [String: Any]) throws -> EntryUnion { | ||
guard let typeName = fields["__typename"] as? String else { | ||
throw SchemaViolationError(type: UnknownEntryUnion.self, field: "__typename", value: fields["__typename"] ?? NSNull()) | ||
} | ||
switch typeName { | ||
case "IntegerEntry": | ||
return try IntegerEntry.init(fields: fields) | ||
|
||
case "StringEntry": | ||
return try StringEntry.init(fields: fields) | ||
|
||
default: | ||
return try UnknownEntryUnion.init(fields: fields) | ||
} | ||
} | ||
|
||
override open func childObjectType(key: String) -> GraphQL.ChildObjectType { | ||
switch(key) { | ||
default: | ||
return .scalar | ||
} | ||
} | ||
|
||
override open func fetchChildObject(key: String) -> GraphQL.AbstractResponse? { | ||
switch(key) { | ||
default: | ||
break | ||
} | ||
return nil | ||
} | ||
|
||
override open func fetchChildObjectList(key: String) -> [GraphQL.AbstractResponse] { | ||
switch(key) { | ||
default: | ||
return [] | ||
} | ||
} | ||
|
||
open func childResponseObjectMap() -> [GraphQL.AbstractResponse] { | ||
return [] | ||
} | ||
|
||
open func responseObject() -> GraphQL.AbstractResponse { | ||
return self as GraphQL.AbstractResponse | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 If the date string is in an unexpected format, this will cause our clients to die at runtime with a fatal error that is out of their control.
Instead, the date parsing could be rolled into the
guard
clause so that failure to parse becomes a SchemaViolationError as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code to serialize and deserialize a date string is specified to the generator, so this would only need to be improved for the example. It would be worth checking to see what we do for our shopify ios app though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we use essentially the same code: