|
| 1 | +import GraphQL |
| 2 | + |
| 3 | +extension Type { |
| 4 | + |
| 5 | + @discardableResult |
| 6 | + /// Define and add the federated key to this type. |
| 7 | + /// |
| 8 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 9 | + /// - Parameters: |
| 10 | + /// - function: The resolver function used to load this entity based on the key value. |
| 11 | + /// - _: The key value. The name of this argument must match a Type field. |
| 12 | + /// - Returns: Self for chaining. |
| 13 | + public func key<Arguments: Codable>( |
| 14 | + at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>, |
| 15 | + @ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments> |
| 16 | + ) -> Self { |
| 17 | + keys.append(Key(arguments: [argument()], asyncResolve: function)) |
| 18 | + return self |
| 19 | + } |
| 20 | + |
| 21 | + @discardableResult |
| 22 | + /// Define and add the federated key to this type. |
| 23 | + /// |
| 24 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 25 | + /// - Parameters: |
| 26 | + /// - function: The resolver function used to load this entity based on the key value. |
| 27 | + /// - _: The key values. The names of these arguments must match Type fields. |
| 28 | + /// - Returns: Self for chaining. |
| 29 | + public func key<Arguments: Codable>( |
| 30 | + at function: @escaping AsyncResolve<Resolver, Context, Arguments, ObjectType?>, |
| 31 | + @ArgumentComponentBuilder<Arguments> _ arguments: () |
| 32 | + -> [ArgumentComponent<Arguments>] = { [] } |
| 33 | + ) -> Self { |
| 34 | + keys.append(Key(arguments: arguments(), asyncResolve: function)) |
| 35 | + return self |
| 36 | + } |
| 37 | + |
| 38 | + @discardableResult |
| 39 | + /// Define and add the federated key to this type. |
| 40 | + /// |
| 41 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 42 | + /// - Parameters: |
| 43 | + /// - function: The resolver function used to load this entity based on the key value. |
| 44 | + /// - _: The key value. The name of this argument must match a Type field. |
| 45 | + /// - Returns: Self for chaining. |
| 46 | + public func key<Arguments: Codable>( |
| 47 | + at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>, |
| 48 | + @ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments> |
| 49 | + ) -> Self { |
| 50 | + keys.append(Key(arguments: [argument()], simpleAsyncResolve: function)) |
| 51 | + return self |
| 52 | + } |
| 53 | + |
| 54 | + @discardableResult |
| 55 | + /// Define and add the federated key to this type. |
| 56 | + /// |
| 57 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 58 | + /// - Parameters: |
| 59 | + /// - function: The resolver function used to load this entity based on the key value. |
| 60 | + /// - _: The key values. The names of these arguments must match Type fields. |
| 61 | + /// - Returns: Self for chaining. |
| 62 | + public func key<Arguments: Codable>( |
| 63 | + at function: @escaping SimpleAsyncResolve<Resolver, Context, Arguments, ObjectType?>, |
| 64 | + @ArgumentComponentBuilder<Arguments> _ arguments: () |
| 65 | + -> [ArgumentComponent<Arguments>] = { [] } |
| 66 | + ) -> Self { |
| 67 | + keys.append(Key(arguments: arguments(), simpleAsyncResolve: function)) |
| 68 | + return self |
| 69 | + } |
| 70 | + |
| 71 | + @discardableResult |
| 72 | + /// Define and add the federated key to this type. |
| 73 | + /// |
| 74 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 75 | + /// - Parameters: |
| 76 | + /// - function: The resolver function used to load this entity based on the key value. |
| 77 | + /// - _: The key value. The name of this argument must match a Type field. |
| 78 | + /// - Returns: Self for chaining. |
| 79 | + public func key<Arguments: Codable>( |
| 80 | + at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>, |
| 81 | + @ArgumentComponentBuilder<Arguments> _ arguments: () |
| 82 | + -> [ArgumentComponent<Arguments>] = { [] } |
| 83 | + ) -> Self { |
| 84 | + keys.append(Key(arguments: arguments(), syncResolve: function)) |
| 85 | + return self |
| 86 | + } |
| 87 | + |
| 88 | + @discardableResult |
| 89 | + /// Define and add the federated key to this type. |
| 90 | + /// |
| 91 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 92 | + /// - Parameters: |
| 93 | + /// - function: The resolver function used to load this entity based on the key value. |
| 94 | + /// - _: The key values. The names of these arguments must match Type fields. |
| 95 | + /// - Returns: Self for chaining. |
| 96 | + public func key<Arguments: Codable>( |
| 97 | + at function: @escaping SyncResolve<Resolver, Context, Arguments, ObjectType?>, |
| 98 | + @ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments> |
| 99 | + ) -> Self { |
| 100 | + keys.append(Key(arguments: [argument()], syncResolve: function)) |
| 101 | + return self |
| 102 | + } |
| 103 | +} |
| 104 | + |
| 105 | +#if compiler(>=5.5) && canImport(_Concurrency) |
| 106 | + |
| 107 | +public extension Type { |
| 108 | + @available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *) |
| 109 | + @discardableResult |
| 110 | + /// Define and add the federated key to this type. |
| 111 | + /// |
| 112 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 113 | + /// - Parameters: |
| 114 | + /// - function: The resolver function used to load this entity based on the key value. |
| 115 | + /// - _: The key value. The name of this argument must match a Type field. |
| 116 | + /// - Returns: Self for chaining. |
| 117 | + func key<Arguments: Codable>( |
| 118 | + at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>, |
| 119 | + @ArgumentComponentBuilder<Arguments> _ argument: () -> ArgumentComponent<Arguments> |
| 120 | + ) -> Self { |
| 121 | + keys.append(Key(arguments: [argument()], concurrentResolve: function)) |
| 122 | + return self |
| 123 | + } |
| 124 | + |
| 125 | + @available(macOS 10.15, iOS 15, watchOS 8, tvOS 15, *) |
| 126 | + @discardableResult |
| 127 | + /// Define and add the federated key to this type. |
| 128 | + /// |
| 129 | + /// For more information, see https://www.apollographql.com/docs/federation/entities |
| 130 | + /// - Parameters: |
| 131 | + /// - function: The resolver function used to load this entity based on the key value. |
| 132 | + /// - _: The key values. The names of these arguments must match Type fields. |
| 133 | + /// - Returns: Self for chaining. |
| 134 | + func key<Arguments: Codable>( |
| 135 | + at function: @escaping ConcurrentResolve<Resolver, Context, Arguments, ObjectType?>, |
| 136 | + @ArgumentComponentBuilder<Arguments> _ arguments: () -> [ArgumentComponent<Arguments>] |
| 137 | + ) -> Self { |
| 138 | + keys.append(Key(arguments: arguments(), concurrentResolve: function)) |
| 139 | + return self |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +#endif |
0 commit comments