-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Building SchemaConfiguration to handle cacheKey resolution
- Loading branch information
1 parent
e5fa2ca
commit 3ad6de9
Showing
15 changed files
with
73 additions
and
104 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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,38 @@ | ||
public protocol SchemaConfiguration { | ||
static func objectType(forTypename __typename: String) -> Object.Type? | ||
} | ||
|
||
extension SchemaConfiguration { | ||
public static func cacheKey(for data: [String: JSONValue]) -> CacheKey? { | ||
guard let __typename = data["__typename"] as? String, | ||
let keyString = cacheKeyString(for: data, withTypename: __typename) else { | ||
return nil | ||
} | ||
return CacheKey(__typename + ":" + keyString) | ||
} | ||
|
||
private static func cacheKeyString( | ||
for data: [String: JSONValue], | ||
withTypename __typename: String | ||
) -> String? { | ||
if let objectType = objectType(forTypename: __typename), | ||
let resolver = objectType.Metadata as? ObjectCacheKeyResolver.Type { | ||
return resolver.cacheKey(for: data) | ||
} | ||
|
||
if let unknownTypeMapper = self as? SchemaUnknownTypeMapper.Type { | ||
return unknownTypeMapper.cacheKeyForUnknownType(withTypename: __typename, data: data) | ||
} | ||
|
||
return nil | ||
} | ||
} | ||
|
||
public protocol ObjectCacheKeyResolver { | ||
static func cacheKey(for: [String: JSONValue]) -> String? | ||
} | ||
|
||
public protocol SchemaUnknownTypeMapper { | ||
static func cacheKeyForUnknownType(withTypename: String, data: [String: JSONValue]) -> String? | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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