Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gql-tools

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gql-tools - npm Package Compare versions

Comparing version 0.0.3 to 0.0.4

2

cli.js

@@ -12,3 +12,3 @@ #! /usr/bin/env node

'',
' Given a file with a GraphQL schema as text, generates the introspected schema as JSON file and / or the schema AST as JSON file.',
' Given a file with a GraphQL schema in the schema language or the URL of a GraphQL endpoint, generates the introspected schema and / or the schema AST as JSON files.',
' By default, only the introspected schema is generated.',

@@ -15,0 +15,0 @@ ' To select which files to generate use the "-i" and "-o" options.'

var fs = require('fs');
var graphql = require('graphql');
var mockServer = require('graphql-tools').mockServer;
var isUrl = require('is-url');
var fetch = require('node-fetch');
exports.generateSchemaAst = function (schemaTextFileName, outputFileName) {
var schemaText = fs.readFileSync(schemaTextFileName, 'utf-8');
exports.generateSchemaAst = function (schemaResource, outputFileName) {
if (isUrl(schemaResource)) {
throw new Error('URLs not supported yet for schema AST generation.');
}
createWriter(outputFileName)(graphql.parse(schemaText));
createWriter(outputFileName)(graphql.parse(read(schemaResource)));
};
exports.generateIntrospectedSchema = function (schemaTextFileName, outputFileName) {
var schemaText = fs.readFileSync(schemaTextFileName, 'utf-8');
exports.generateIntrospectedSchema = function (schemaResource, outputFileName) {
var promise = isUrl(schemaResource) ?
fetchIntrospectionSchema(schemaResource) :
mockServer(read(schemaResource)).query(graphql.introspectionQuery);
mockServer(schemaText).query(graphql.introspectionQuery).then(createWriter(outputFileName));
promise.then(createWriter(outputFileName));
};
function fetchIntrospectionSchema(endpointUrl) {
var headers = {
'content-type': 'application/json',
'accept': 'application/json'
};
var body = JSON.stringify({query: graphql.introspectionQuery});
return fetch(endpointUrl, {method: 'POST', body: body, headers: headers}).then(toJson);
function toJson(response) {
return response.json();
}
}
function read(fileName) {
return fs.readFileSync(fileName, 'utf-8');
}
function createWriter(fileName) {
return content => fs.writeFileSync(fileName, JSON.stringify(content, null, 2));
return function (content) {
return fs.writeFileSync(fileName, JSON.stringify(content, null, 2));
}
}
{
"name": "gql-tools",
"description": "GraphQL Tools for schema handling.",
"version": "0.0.3",
"version": "0.0.4",
"author": "Alberto Mijares <almilo@almilo.es>",

@@ -12,3 +12,5 @@ "license": "MIT",

"commander": "^2.9.0",
"graphql-tools": "^0.6.0"
"graphql-tools": "^0.6.0",
"is-url": "^1.2.2",
"node-fetch": "^1.5.3"
},

@@ -15,0 +17,0 @@ "peerDependencies": {

@@ -25,3 +25,4 @@ # gql-tools

### Usage
* **gqlschema**: generates the introspected schema and the schema AST of a given GraphQL schema language.
* **usage**: *gqlschema <schema.txt>*
* **gqlschema**: generates the introspected schema and the schema AST of a given GraphQL schema either in the schema
language (file) or from a GraphQL endpoint (URL).
* **usage**: *gqlschema <schema.txt | http://example.com/graphql>*
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