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

nexus

Package Overview
Dependencies
Maintainers
3
Versions
395
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nexus - npm Package Compare versions

Comparing version 0.6.0 to 0.6.1

dist/prettierFormat.d.ts

2

dist/metadata.d.ts

@@ -60,3 +60,3 @@ import { DirectiveLocationEnum, GraphQLNamedType, GraphQLSchema, GraphQLObjectType } from "graphql";

sortSchema(schema: GraphQLSchema): GraphQLSchema;
writeFile(name: string, output: string, filePath: string): void;
writeFile(type: "schema" | "types", output: string, filePath: string): Promise<void>;
/**

@@ -63,0 +63,0 @@ * Generates the schema, adding any directives as necessary

@@ -11,2 +11,3 @@ "use strict";

var common_1 = require("./common");
var prettierFormat_1 = require("./prettierFormat");
/**

@@ -141,3 +142,3 @@ * Passed into the SchemaBuilder, this keeps track of any necessary

this.generateTypesFile(sortedSchema).then(function (value) {
_this.writeFile("types", value, typegen_2);
return _this.writeFile("types", value, typegen_2);
});

@@ -154,10 +155,27 @@ }

};
Metadata.prototype.writeFile = function (name, output, filePath) {
Metadata.prototype.writeFile = function (type, output, filePath) {
if (typeof filePath !== "string" || !path_1.default.isAbsolute(filePath)) {
throw new Error("Expected an absolute path to output the GraphQL Nexus " + name + ", saw " + filePath);
return Promise.reject(new Error("Expected an absolute path to output the GraphQL Nexus " + type + ", saw " + filePath));
}
var fs = require("fs");
fs.writeFile(filePath, output, function (err) {
if (err) {
console.error(err);
var util = require("util");
var _a = [
util.promisify(fs.readFile),
util.promisify(fs.writeFile),
], readFile = _a[0], writeFile = _a[1];
var formatTypegen = null;
if (typeof this.config.formatTypegen === "function") {
formatTypegen = this.config.formatTypegen;
}
else if (this.config.prettierConfig) {
formatTypegen = prettierFormat_1.prettierFormat(this.config.prettierConfig);
}
var content = Promise.resolve(typeof formatTypegen === "function" ? formatTypegen(output, type) : output);
return Promise.all([
content,
readFile(filePath, "utf8").catch(function () { return ""; }),
]).then(function (_a) {
var toSave = _a[0], existing = _a[1];
if (toSave !== existing) {
return writeFile(filePath, toSave);
}

@@ -164,0 +182,0 @@ });

@@ -315,3 +315,14 @@ import { GraphQLFieldResolver, GraphQLScalarTypeConfig, GraphQLNamedType, GraphQLIsTypeOfFn, GraphQLResolveInfo, DirectiveLocationEnum, GraphQLDirective, GraphQLSchema } from "graphql";

typegenConfig?: ((schema: GraphQLSchema, outputPath: string) => TypegenInfo | PromiseLike<TypegenInfo>);
/**
* Either an absolute path to a .prettierrc file, or an object
* with relevant Prettier rules to be used on the generated output
*/
prettierConfig?: string | object;
/**
* Manually apply a formatter to the generated content before saving,
* see the `prettierConfig` option if you want to use Prettier.
*/
formatTypegen?: FormatTypegenFn;
}
export declare type FormatTypegenFn = (content: string, type: "types" | "schema") => MaybePromise<string>;
export interface SchemaConfig extends BuilderConfig {

@@ -478,3 +489,3 @@ /**

*/
debug?: true;
debug?: boolean;
/**

@@ -481,0 +492,0 @@ * If provided this will be used for the backing types rather than the auto-resolve

{
"name": "nexus",
"version": "0.6.0",
"version": "0.6.1",
"main": "dist/index.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

@@ -21,2 +21,3 @@ import {

import { SCALAR_TYPES } from "./common";
import { prettierFormat } from "./prettierFormat";

@@ -210,5 +211,5 @@ export interface DirectiveUse {

if (typegen) {
this.generateTypesFile(sortedSchema).then((value) => {
this.writeFile("types", value, typegen);
});
this.generateTypesFile(sortedSchema).then((value) =>
this.writeFile("types", value, typegen)
);
}

@@ -226,12 +227,31 @@ }

writeFile(name: string, output: string, filePath: string) {
writeFile(type: "schema" | "types", output: string, filePath: string) {
if (typeof filePath !== "string" || !path.isAbsolute(filePath)) {
throw new Error(
`Expected an absolute path to output the GraphQL Nexus ${name}, saw ${filePath}`
return Promise.reject(
new Error(
`Expected an absolute path to output the GraphQL Nexus ${type}, saw ${filePath}`
)
);
}
const fs = require("fs") as typeof import("fs");
fs.writeFile(filePath, output, (err) => {
if (err) {
console.error(err);
const util = require("util") as typeof import("util");
const [readFile, writeFile] = [
util.promisify(fs.readFile),
util.promisify(fs.writeFile),
];
let formatTypegen: Types.Maybe<Types.FormatTypegenFn> = null;
if (typeof this.config.formatTypegen === "function") {
formatTypegen = this.config.formatTypegen;
} else if (this.config.prettierConfig) {
formatTypegen = prettierFormat(this.config.prettierConfig);
}
const content = Promise.resolve(
typeof formatTypegen === "function" ? formatTypegen(output, type) : output
);
return Promise.all([
content,
readFile(filePath, "utf8").catch(() => ""),
]).then(([toSave, existing]) => {
if (toSave !== existing) {
return writeFile(filePath, toSave);
}

@@ -238,0 +258,0 @@ });

@@ -441,4 +441,19 @@ import {

) => TypegenInfo | PromiseLike<TypegenInfo>);
/**
* Either an absolute path to a .prettierrc file, or an object
* with relevant Prettier rules to be used on the generated output
*/
prettierConfig?: string | object;
/**
* Manually apply a formatter to the generated content before saving,
* see the `prettierConfig` option if you want to use Prettier.
*/
formatTypegen?: FormatTypegenFn;
}
export type FormatTypegenFn = (
content: string,
type: "types" | "schema"
) => MaybePromise<string>;
export interface SchemaConfig extends BuilderConfig {

@@ -610,3 +625,3 @@ /**

*/
debug?: true;
debug?: boolean;
/**

@@ -613,0 +628,0 @@ * If provided this will be used for the backing types rather than the auto-resolve

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