New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@remoklify/graphql-to-typescript

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@remoklify/graphql-to-typescript - npm Package Compare versions

Comparing version 1.0.0 to 1.0.2

dist/index.js

0

app.json

@@ -0,0 +0,0 @@ {

@@ -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);
}
});

43

lib/util/gql-to-type-converter.util.ts
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc