-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
utils: validateDirectiveConfig initial draft
- Loading branch information
1 parent
dbe5c57
commit 67a94e5
Showing
2 changed files
with
32 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const createDirective = require("./create-directive"); | ||
const createSchemaDirective = require("./create-schema-directives"); | ||
|
||
module.exports = { | ||
createDirective, | ||
createSchemaDirective, | ||
}; |
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,25 @@ | ||
const validateDirectiveConfig = (directiveConfig) => { | ||
const { name, resolverReplacer } = directiveConfig; | ||
|
||
let message; | ||
if (!name || !resolverReplacer) { | ||
message = "directiveConfig.name is required"; | ||
} else if (!resolverReplacer) { | ||
message = "directiveConfig.resolverReplacer is required"; | ||
} else if (typeof name !== "string") { | ||
message = "directiveConfig.name must be a string"; | ||
} else if (typeof resolverReplacer !== "function") { | ||
message = "directiveConfig.resolverReplacer must be a function"; | ||
} else { | ||
return directiveConfig; | ||
} | ||
|
||
const error = new Error(message); | ||
error.name = "CreateDirectiveError"; | ||
|
||
throw error; | ||
}; | ||
|
||
module.exports = { | ||
validateDirectiveConfig, | ||
}; |