-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(loader): added basic schema loader and validator from JSON intro…
…spection file
- Loading branch information
1 parent
12b4458
commit 13b3dec
Showing
7 changed files
with
64 additions
and
2 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
Empty file.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#!/usr/bin/env node | ||
|
||
console.log('test'); | ||
import {loadSchema} from './scheme-loader'; | ||
|
||
console.log(loadSchema('./schema.json')); |
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,24 @@ | ||
import {buildClientSchema, GraphQLSchema, IntrospectionQuery} from 'graphql'; | ||
import * as fs from 'fs'; | ||
|
||
export const loadFileContent = (filePath: string): IntrospectionQuery => { | ||
if (fs.existsSync(filePath)) { | ||
return <IntrospectionQuery>(JSON.parse(fs.readFileSync(filePath, 'utf8'))); | ||
} else { | ||
throw new Error(`File ${filePath} does not exists!`); | ||
} | ||
}; | ||
|
||
|
||
export const validateSchema = (schema: IntrospectionQuery) => { | ||
if (!schema.__schema) { | ||
throw new Error('Invalid schema provided!'); | ||
} | ||
}; | ||
|
||
export const loadSchema = (filePath: string): GraphQLSchema => { | ||
const schemaObject = loadFileContent(filePath); | ||
validateSchema(schemaObject); | ||
|
||
return buildClientSchema(schemaObject); | ||
}; |
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
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,2 @@ | ||
/// <reference types="typed-graphql" /> | ||
/// <reference types="@types/node" /> |
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 |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
# yarn lockfile v1 | ||
|
||
|
||
"@types/node@^0.0.2": | ||
version "0.0.2" | ||
resolved "https://registry.yarnpkg.com/@types/node/-/node-0.0.2.tgz#0da4934902fbf68a97a0f53204a35ad2224917bc" | ||
|
||
ansi-align@^1.1.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/ansi-align/-/ansi-align-1.1.0.tgz#2f0c1658829739add5ebb15e6b0c6e3423f016ba" | ||
|
@@ -75,6 +79,12 @@ colors@^1.1.2: | |
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/colors/-/colors-1.1.2.tgz#168a4701756b6a7f51a12ce0c97bfa28c084ed63" | ||
|
||
commander@^2.9.0: | ||
version "2.9.0" | ||
resolved "https://registry.yarnpkg.com/commander/-/commander-2.9.0.tgz#9c99094176e12240cb22d6c5146098400fe0f7d4" | ||
dependencies: | ||
graceful-readlink ">= 1.0.0" | ||
|
||
[email protected]: | ||
version "0.0.1" | ||
resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" | ||
|
@@ -207,6 +217,16 @@ graceful-fs@^4.1.2: | |
version "4.1.11" | ||
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" | ||
|
||
"graceful-readlink@>= 1.0.0": | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725" | ||
|
||
graphql@^0.8.2: | ||
version "0.8.2" | ||
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.8.2.tgz#eb1bb524b38104bbf2c9157f9abc67db2feba7d2" | ||
dependencies: | ||
iterall "1.0.2" | ||
|
||
has-ansi@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" | ||
|
@@ -272,6 +292,10 @@ isarray@~1.0.0: | |
version "1.0.0" | ||
resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" | ||
|
||
[email protected]: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.0.2.tgz#41a2e96ce9eda5e61c767ee5dc312373bb046e91" | ||
|
||
latest-version@^2.0.0: | ||
version "2.0.0" | ||
resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-2.0.0.tgz#56f8d6139620847b8017f8f1f4d78e211324168b" | ||
|
@@ -526,6 +550,10 @@ tslint@^4.0.2: | |
underscore.string "^3.3.4" | ||
update-notifier "^1.0.2" | ||
|
||
typed-graphql@^1.0.2: | ||
version "1.0.2" | ||
resolved "https://registry.yarnpkg.com/typed-graphql/-/typed-graphql-1.0.2.tgz#4c0f788775d552df4d4ec3d73f25469252f40fb8" | ||
|
||
typescript@^2.0.10: | ||
version "2.1.1" | ||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.1.tgz#41c2b64472f529331b2055c0424862b44ce58d42" | ||
|