Skip to content

Commit 600357f

Browse files
feat: Adds ExtendSchema functionality
1 parent 8b9a38a commit 600357f

File tree

6 files changed

+312
-23
lines changed

6 files changed

+312
-23
lines changed

Sources/GraphQL/Execution/Values.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,34 @@ func coerceValue(value: Map, type: GraphQLInputType) throws -> Map {
184184

185185
throw GraphQLError(message: "Provided type is not an input type")
186186
}
187+
188+
/**
189+
* Prepares an object map of argument values given a directive definition
190+
* and a AST node which may contain directives. Optionally also accepts a map
191+
* of variable values.
192+
*
193+
* If the directive does not exist on the node, returns undefined.
194+
*
195+
* Note: The returned value is a plain Object with a prototype, since it is
196+
* exposed to user code. Care should be taken to not pull values from the
197+
* Object prototype.
198+
*/
199+
func getDirectiveValues(
200+
directiveDef: GraphQLDirective,
201+
directives: [Directive],
202+
variableValues: [String: Map] = [:]
203+
) throws -> Map? {
204+
let directiveNode = directives.find { directive in
205+
directive.name.value == directiveDef.name
206+
}
207+
208+
if let directiveNode = directiveNode {
209+
return try getArgumentValues(
210+
argDefs: directiveDef.args,
211+
argASTs: directiveNode.arguments,
212+
variables: variableValues
213+
)
214+
}
215+
216+
return nil
217+
}

Sources/GraphQL/Language/AST.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,10 +2182,12 @@ public final class ScalarExtensionDefinition {
21822182
public let kind: Kind = .scalarExtensionDefinition
21832183
public let loc: Location?
21842184
public let definition: ScalarTypeDefinition
2185+
public let directives: [Directive]
21852186

2186-
init(loc: Location? = nil, definition: ScalarTypeDefinition) {
2187+
init(loc: Location? = nil, definition: ScalarTypeDefinition, directives: [Directive] = []) {
21872188
self.loc = loc
21882189
self.definition = definition
2190+
self.directives = directives
21892191
}
21902192
}
21912193

0 commit comments

Comments
 (0)