Skip to content

Internalize [2 of 4] #18

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions support/Sources/GraphQL.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ public class GraphQL {
}
}

public func addField(field: String, aliasSuffix: String? = nil, args: String? = nil, subfields: AbstractQuery? = nil) {
internal func addField(field: String, aliasSuffix: String? = nil, args: String? = nil, subfields: AbstractQuery? = nil) {
var alias: String? = nil
if let aliasSuffix = aliasSuffix {
alias = "\(field)\(AbstractQuery.aliasSuffixSeparator)\(aliasSuffix)"
}
addSelection(selection: Selection(field: field, alias: alias, args: args, subfields: subfields))
}

public func addInlineFragment(on object: String, subfields: AbstractQuery) {
internal func addInlineFragment(on object: String, subfields: AbstractQuery) {
addSelection(selection: Selection(field: "... on \(object)", alias: nil, args: nil, subfields: subfields))
}
}

public static func quoteString(input: String) -> String {
internal static func quoteString(input: String) -> String {
var escaped = "\""
for c in input.unicodeScalars {
switch c {
Expand All @@ -137,7 +137,7 @@ public class GraphQL {

open class AbstractResponse: CustomDebugStringConvertible {
public var fields: [String: Any]
public var objectMap: [String : Any?] = [:]
internal var objectMap: [String : Any?] = [:]

required public init(fields: [String: Any]) throws {
self.fields = fields
Expand All @@ -153,11 +153,11 @@ public class GraphQL {
}
}

open func deserializeValue(fieldName: String, value: Any) throws -> Any? {
internal func deserializeValue(fieldName: String, value: Any) throws -> Any? {
throw SchemaViolationError(type: type(of: self), field: fieldName, value: value)
}

public func field(field: String, aliasSuffix: String? = nil) -> Any? {
internal func field(field: String, aliasSuffix: String? = nil) -> Any? {
var responseKey = field
if let aliasSuffix = aliasSuffix {
responseKey += "\(AbstractQuery.aliasSuffixSeparator)\(aliasSuffix)"
Expand All @@ -172,19 +172,19 @@ public class GraphQL {
return "<\(type(of: self)): \(fields)>"
}

open func childObjectType(key: String) -> ChildObjectType {
internal func childObjectType(key: String) -> ChildObjectType {
return .unknown
}

open func fetchChildObject(key: String) -> GraphQL.AbstractResponse? {
internal func fetchChildObject(key: String) -> GraphQL.AbstractResponse? {
return nil
}

open func fetchChildObjectList(key: String) -> [GraphQL.AbstractResponse] {
internal func fetchChildObjectList(key: String) -> [GraphQL.AbstractResponse] {
return []
}

func fieldName(from key: String) -> String {
internal func fieldName(from key: String) -> String {
if let range = key.range(of: AbstractQuery.aliasSuffixSeparator) {
if key.distance(from: key.startIndex, to: range.lowerBound) > 0 {
return key.substring(to: range.lowerBound)
Expand Down Expand Up @@ -231,8 +231,8 @@ public class GraphQL {
}

public struct GraphQLResponse<DataType: GraphQL.AbstractResponse> {
public let data: DataType?
public let errors: [GraphQL.ResponseError]?
internal let data: DataType?
internal let errors: [GraphQL.ResponseError]?
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these should be left public, they are the purpose of this struct (deserializing response into errors/data)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They aren't needed on any of the generated models.

Copy link

@g-Off g-Off Sep 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are/can be used by external code though. From the README

guard let response = try? GraphQLResponse<ExampleSchema.QueryRoot>(jsonData: response) else {
    print("Invalid GraphQL response")
    return
}
if let errors = response.errors {
    for error in errors {
        print("GraphQL error: \(error.message)")
    }
}
if let data = response.data {
    let user = data.user
    print("\(user.firstName) \(user.lastName)")
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is GraphQLResponse used for? I can't find any usage of it. Can we not just remove it entirely?


public init(object: Any) throws {
guard let rootDict = object as? [String: AnyObject] else {
Expand Down