@remoklify/graphql-to-typescript
Advanced tools
Comparing version 1.0.0 to 1.0.2
@@ -0,0 +0,0 @@ { |
48
index.ts
@@ -5,7 +5,47 @@ /** | ||
import { GqlToTypeConverterUtil } from "./lib/util/gql-to-type-converter.util"; | ||
// util | ||
import yargs from 'yargs/yargs'; | ||
import * as inquirer from 'inquirer'; | ||
import * as path from 'path'; | ||
import { GqlToTypeConverterUtil } from './lib/util/gql-to-type-converter.util'; | ||
var gql = new GqlToTypeConverterUtil(); | ||
gql.convert(); | ||
const QUESTIONS = [ | ||
{ | ||
name: 'url', | ||
type: 'input', | ||
message: 'GraphQL API Url: ', | ||
when: () => yargs().argv, | ||
validate: (input: string) => { | ||
return true; | ||
}, | ||
}, | ||
{ | ||
name: 'auth', | ||
type: 'input', | ||
message: 'Auth Token (Optional): ', | ||
when: () => yargs().argv, | ||
validate: (input: string) => { | ||
return true; | ||
}, | ||
}, | ||
]; | ||
// current directory | ||
const CURR_DIR = process.cwd(); | ||
// prompts questions to user | ||
inquirer.prompt(QUESTIONS).then(async (answers) => { | ||
let userAnswers = Object.assign({}, answers, yargs().argv); | ||
const url = userAnswers['url']; | ||
const auth = userAnswers['auth']; | ||
const targetPath = path.join(CURR_DIR, 'schema'); | ||
const gql = new GqlToTypeConverterUtil(); | ||
if (auth && auth.length > 0) { | ||
gql.convert(url, 'Bearer ' + auth, targetPath); | ||
} else { | ||
gql.convert(url, null, targetPath); | ||
} | ||
}); |
import * as fs from 'fs'; | ||
import axios from 'axios'; | ||
import { buildClientSchema, printSchema } from 'graphql'; | ||
import { generateTypeScriptTypes } from 'graphql-schema-typescript'; | ||
import * as path from 'path'; | ||
export class GqlToTypeConverterUtil { | ||
convert = () => { | ||
const schema = fs.readFileSync('schema.json', 'utf8'); | ||
const schemaObj = JSON.parse(schema); | ||
const gql = buildClientSchema(schemaObj.data); | ||
fs.writeFileSync('schema.docs.graphql', printSchema(gql)); | ||
const outputPath = 'schema.generated.ts'; | ||
generateTypeScriptTypes(gql, outputPath) | ||
.then(() => {}) | ||
.catch((err) => {}); | ||
convert = async (url: string, authorization: any, targetPath: string) => { | ||
const query = fs.readFileSync('query.graphql', 'utf8'); | ||
const response = await axios.post<any>( | ||
url, | ||
{ query }, | ||
{ | ||
headers: { Authorization: authorization }, | ||
} | ||
); | ||
if (response && response.data) { | ||
if (!fs.existsSync(targetPath)) { | ||
fs.mkdirSync(targetPath); | ||
} | ||
console.log('Reponse is taken from: ', url); | ||
console.log('Processing code generation..'); | ||
const schema = response.data; | ||
const gql = buildClientSchema(schema.data); | ||
const schemaDocsPath = path.join(targetPath, 'schema.docs.graphql'); | ||
fs.writeFileSync(schemaDocsPath, printSchema(gql)); | ||
const schemaGeneratedPath = path.join(targetPath, 'schema.generated.ts'); | ||
generateTypeScriptTypes(gql, schemaGeneratedPath) | ||
.then(() => { | ||
console.log( | ||
'Code is generated, please check the file: schema.generated.ts' | ||
); | ||
}) | ||
.catch((err) => { | ||
throw err; | ||
}); | ||
} else { | ||
throw new Error('The GraphQL Url not responding.'); | ||
} | ||
}; | ||
} |
{ | ||
"name": "@remoklify/graphql-to-typescript", | ||
"description": "Generates typescript codes for client by only taking the inputs GraphQL Api url and Authorization.", | ||
"version": "1.0.0", | ||
"description": "Command-line interface generator that generates typescript codes for client by only taking the inputs GraphQL Api url and Authorization.", | ||
"version": "1.0.2", | ||
"license": "MIT", | ||
@@ -12,8 +12,14 @@ "main": "dist/index.js", | ||
}, | ||
"bin": { | ||
"remoklify:graphql:codegen": "dist/index.js" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.24.0", | ||
"graphql": "^14.0.0", | ||
"graphql-schema-typescript": "^1.5.2", | ||
"inquirer": "^8.2.0", | ||
"json-to-graphql": "^0.1.1", | ||
"ts-node": "^10.3.0", | ||
"typescript": "^4.4.4" | ||
"typescript": "^4.4.4", | ||
"yargs": "^17.3.1" | ||
}, | ||
@@ -45,3 +51,8 @@ "git repository": "https://github.com/remoklify/graphql-to-typescript", | ||
"token" | ||
] | ||
], | ||
"devDependencies": { | ||
"@types/inquirer": "^8.1.3", | ||
"@types/node": "^17.0.5", | ||
"@types/yargs": "^17.0.8" | ||
} | ||
} |
@@ -11,12 +11,6 @@ <p align="center"> | ||
[![Version](https://img.shields.io/npm/v/@remoklify/graphql-to-typescript?color=CB3837&style=for-the-badge&logo=npm)](https://www.npmjs.com/package/@remoklify/graphql-to-typescript) | ||
[![Downloads](https://img.shields.io/npm/dt/@remoklify/graphql-to-typescript?color=CB3837&logo=npm&style=for-the-badge)](https://www.npmjs.com/package/@remoklify/graphql-to-typescript) | ||
[![License](https://img.shields.io/github/license/remoklify/graphql-to-typescript?color=43b043&style=for-the-badge)](LICENSE) | ||
[![Issues](https://img.shields.io/github/issues/remoklify/graphql-to-typescript?color=43b043&style=for-the-badge)](https://github.com/remoklify/graphql-to-typescript/issues) | ||
[![PRCLosed](https://img.shields.io/github/issues-pr-closed-raw/remoklify/graphql-to-typescript?color=43b043&style=for-the-badge)](https://github.com/remoklify/graphql-to-typescript/pulls?q=is%3Apr+is%3Aclosed) | ||
[![LastCommit](https://img.shields.io/github/last-commit/remoklify/graphql-to-typescript?color=43b043&style=for-the-badge)](https://github.com/remoklify/graphql-to-typescript/commits/master) | ||
[![Release](https://img.shields.io/github/release/remoklify/graphql-to-typescript?include_prereleases&color=43b043&style=for-the-badge)](https://github.com/remoklify/graphql-to-typescript/releases) | ||
[![GitHubRepo](https://img.shields.io/badge/GitHub-Repository-24292e.svg?style=for-the-badge&logo=github)](https://github.com/remoklify/graphql-to-typescript) | ||
[![SonarCloud](https://img.shields.io/sonar/quality_gate/remoklify_graphql-to-typescript?server=https%3A%2F%2Fsonarcloud.io&label=Sonar%20Cloud&style=for-the-badge&logo=sonarcloud)](https://sonarcloud.io/dashboard?id=remoklify_graphql-to-typescript) | ||
Generates typescript codes for client by only taking the inputs GraphQL Api url and Authorization. | ||
Command-line interface generator that generates typescript codes for client by only taking the inputs GraphQL Api url and Authorization. | ||
@@ -28,5 +22,16 @@ ## About the NPM Package | ||
```sh | ||
npm install --save @remoklify/graphql-to-typescript | ||
npm install -g @remoklify/graphql-to-typescript | ||
``` | ||
### Usage | ||
Run command: | ||
```sh | ||
remoklify:graphql:codegen | ||
``` | ||
Give the GraphQL API url and auth token if necessary (without bearer) | ||
? GraphQL API Url: https://api.github.com/graphql | ||
? Auth Token (Optional): ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | ||
# Sponsors | ||
@@ -33,0 +38,0 @@ |
@@ -8,3 +8,6 @@ { | ||
/* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
// "lib": [], /* Specify library files to be included in the compilation. */ | ||
"lib": [ | ||
"es2018", | ||
"dom" | ||
], /* Specify library files to be included in the compilation. */ | ||
// "allowJs": true, /* Allow javascript files to be compiled. */ | ||
@@ -11,0 +14,0 @@ // "checkJs": true, /* Report errors in .js files. */ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
20
58
3279489
8
3
61781
1
1
+ Addedaxios@^0.24.0
+ Addedinquirer@^8.2.0
+ Addedyargs@^17.3.1
+ Addedansi-escapes@4.3.2(transitive)
+ Addedaxios@0.24.0(transitive)
+ Addedbase64-js@1.5.1(transitive)
+ Addedbl@4.1.0(transitive)
+ Addedbuffer@5.7.1(transitive)
+ Addedchalk@4.1.2(transitive)
+ Addedchardet@0.7.0(transitive)
+ Addedcli-cursor@3.1.0(transitive)
+ Addedcli-spinners@2.9.2(transitive)
+ Addedcli-width@3.0.0(transitive)
+ Addedcliui@8.0.1(transitive)
+ Addedclone@1.0.4(transitive)
+ Addeddefaults@1.0.4(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedexternal-editor@3.1.0(transitive)
+ Addedfigures@3.2.0(transitive)
+ Addedfollow-redirects@1.15.9(transitive)
+ Addedhas-flag@4.0.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedieee754@1.2.1(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedinquirer@8.2.6(transitive)
+ Addedis-interactive@1.0.0(transitive)
+ Addedis-unicode-supported@0.1.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedlog-symbols@4.1.0(transitive)
+ Addedmimic-fn@2.1.0(transitive)
+ Addedmute-stream@0.0.8(transitive)
+ Addedonetime@5.1.2(transitive)
+ Addedora@5.4.1(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrestore-cursor@3.1.0(transitive)
+ Addedrun-async@2.4.1(transitive)
+ Addedrxjs@7.8.1(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedsupports-color@7.2.0(transitive)
+ Addedthrough@2.3.8(transitive)
+ Addedtmp@0.0.33(transitive)
+ Addedtslib@2.8.1(transitive)
+ Addedtype-fest@0.21.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwcwidth@1.0.1(transitive)
+ Addedwrap-ansi@6.2.0(transitive)
+ Addedyargs@17.7.2(transitive)
+ Addedyargs-parser@21.1.1(transitive)