Skip to content

Commit

Permalink
Making context keys public
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdsupremacist committed Mar 22, 2020
1 parent c9fd863 commit 67801fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/nerdsupremacist/ContextKit.git",
"state": {
"branch": null,
"revision": "fe6a135c1f58b7115d4f524f1224036a3de0a852",
"version": "0.1.0"
"revision": "792019618a7245ca1bb05e8d2163decd00528927",
"version": "0.2.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let package = Package(
dependencies: [
.package(url: "https://github.com/nerdsupremacist/GraphQL.git", from: "0.12.1-beta.2"),
.package(url: "https://github.com/nerdsupremacist/Runtime.git", from: "2.1.2-beta.1"),
.package(url: "https://github.com/nerdsupremacist/ContextKit.git", from: "0.1.0"),
.package(url: "https://github.com/nerdsupremacist/ContextKit.git", from: "0.2.0"),
],
targets: [
.target(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ extension GraphQLSchema where ViewerContext == Void {

extension GraphQLSchema {

static var viewerContext: Context.Key<ViewerContext> {
public static var viewerContext: Context.Key<ViewerContext> {
return .viewerContext
}

Expand Down
14 changes: 13 additions & 1 deletion Sources/GraphZahl/Utils/ContextKey+ViewerContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ private var keys = [Int : Context.AnyKey]()

extension Context.Key {

static var viewerContext: Context.Key<T> {
public static var viewerContext: Context.Key<T> {
let keyForKey = unsafeBitCast(T.self as Any.Type, to: Int.self)
return keys.getOrPut(keyForKey, default: Context.Key<T>()) as! Context.Key<T>
}

}

extension Context.Key where T == Any {
public static let anyViewerContext = Context.Key<Any>()
}

extension ContextKeyPaths {

public var anyViewerContext: Context.Key<Any> {
return .anyViewerContext
}

}

0 comments on commit 67801fa

Please sign in to comment.