Skip to content

Commit

Permalink
Making graphql dynamic property with non mutating wrapped value
Browse files Browse the repository at this point in the history
  • Loading branch information
nerdsupremacist committed Jan 11, 2020
1 parent 88f3154 commit ac8a90b
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions templates/swift/StructureAPI.swift.stencil
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,18 @@ enum NoOpDecoder<T>: GraphQLValueDecoder {
// MARK: - Basic API: Graph QL Property Wrapper

@propertyWrapper
struct GraphQL<Decoder: GraphQLValueDecoder> {
var wrappedValue: Decoder.Decoded
struct GraphQL<Decoder: GraphQLValueDecoder>: DynamicProperty {
@State
private var value: Decoder.Decoded

var wrappedValue: Decoder.Decoded {
get {
return value
}
nonmutating set {
value = newValue
}
}

init<T: Target>(_: @autoclosure () -> GraphQLPath<T, Decoder.Encoded>) {
fatalError("Initializer with path only should never be used")
Expand All @@ -357,7 +367,7 @@ struct GraphQL<Decoder: GraphQLValueDecoder> {
}

fileprivate init(_ wrappedValue: Decoder.Encoded) {
self.wrappedValue = try! Decoder.decode(encoded: wrappedValue)
self._value = State(initialValue: try! Decoder.decode(encoded: wrappedValue))
}
}

Expand Down

0 comments on commit ac8a90b

Please sign in to comment.