Skip to content

Commit 7d91bd0

Browse files
refactor: Adds SDL validation assertions
1 parent 5d9aecf commit 7d91bd0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

Sources/GraphQL/Validation/Validate.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,38 @@ func visit(
9696
)
9797
return context.errors
9898
}
99+
100+
/**
101+
* Utility function which asserts a SDL document is valid by throwing an error
102+
* if it is invalid.
103+
*
104+
* @internal
105+
*/
106+
func assertValidSDL(documentAST: Document) throws {
107+
let errors = validateSDL(documentAST: documentAST)
108+
if !errors.isEmpty {
109+
throw GraphQLError(
110+
message: errors.map { $0.message }.joined(separator: "\n\n"),
111+
locations: []
112+
)
113+
}
114+
}
115+
116+
/**
117+
* Utility function which asserts a SDL document is valid by throwing an error
118+
* if it is invalid.
119+
*
120+
* @internal
121+
*/
122+
func assertValidSDLExtension(
123+
documentAST: Document,
124+
schema: GraphQLSchema
125+
) throws {
126+
let errors = validateSDL(documentAST: documentAST, schemaToExtend: schema)
127+
if !errors.isEmpty {
128+
throw GraphQLError(
129+
message: errors.map { $0.message }.joined(separator: "\n\n"),
130+
locations: []
131+
)
132+
}
133+
}

0 commit comments

Comments
 (0)