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

@apollo/core-schema

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

@apollo/core-schema - npm Package Compare versions

Comparing version 0.2.1 to 0.2.2

7

CHANGELOG.md

@@ -7,4 +7,9 @@ # CHANGELOG

- _Nothing to see here. Stay tuned._
## vNEXT
- _Nothing yet! Stay tuned._
## v0.2.2
- Don't call `GraphQLError.toString()` recursively [PR #36](https://github.com/apollographql/core-schema-js/pull/36)
## v0.2.1

@@ -11,0 +16,0 @@

4

dist/error.d.ts

@@ -1,3 +0,3 @@

import { ASTNode, GraphQLError, Source } from 'graphql';
import { Maybe } from 'graphql/jsutils/Maybe';
import { ASTNode, GraphQLError, Source } from "graphql";
import { Maybe } from "graphql/jsutils/Maybe";
export declare type Props = {

@@ -4,0 +4,0 @@ message: string;

@@ -17,13 +17,15 @@ "use strict";

}
throw() { throw this; }
throw() {
throw this;
}
toString() {
let output = `[${this.code}] ${(0, graphql_1.printError)(this)}`;
let output = `[${this.code}] ${super.toString()}`;
const causes = this.causes;
if (causes && causes.length) {
output += '\ncaused by:';
output += "\ncaused by:";
for (const cause of this.causes || []) {
if (!cause)
continue;
output += '\n\n - ';
output += cause.toString().split('\n').join('\n ');
output += "\n\n - ";
output += cause.toString().split("\n").join("\n ");
}

@@ -35,6 +37,6 @@ }

exports.GraphQLErrorExt = GraphQLErrorExt;
GraphQLErrorExt.BASE_PROPS = new Set('nodes source positions path originalError extensions'.split(' '));
GraphQLErrorExt.BASE_PROPS = new Set("nodes source positions path originalError extensions".split(" "));
function err(code, props) {
const message = typeof props === 'string' ? props : props.message;
const error = new GraphQLErrorExt(code, message, typeof props === 'string' ? undefined : props);
const message = typeof props === "string" ? props : props.message;
const error = new GraphQLErrorExt(code, message, typeof props === "string" ? undefined : props);
return error;

@@ -41,0 +43,0 @@ }

{
"name": "@apollo/core-schema",
"version": "0.2.1",
"version": "0.2.2",
"description": "Apollo Core Schema processing library",

@@ -36,10 +36,10 @@ "main": "dist/index.js",

"devDependencies": {
"@types/jest": "27.0.3",
"graphql": "16.0.1",
"jest": "27.4.4",
"jest-config": "27.0.3",
"@types/jest": "27.4.0",
"graphql": "16.3.0",
"jest": "27.5.1",
"jest-config": "27.5.1",
"prettier": "2.5.1",
"ts-jest": "27.1.1",
"typescript": "4.5.3"
"ts-jest": "27.1.3",
"typescript": "4.5.5"
}
}
import { ErrCheckFailed } from "../core";
import { GraphQLErrorExt } from "../error";

@@ -8,2 +9,14 @@ describe("GraphQLErrorExt", () => {

});
it("calling `toString` doesn't throw an error", () => {
const error = new GraphQLErrorExt("CheckFailed", "Check failed");
expect(() => error.toString()).not.toThrow();
});
it("calling `toString` prints the error", () => {
const error = new GraphQLErrorExt("CheckFailed", "Check failed");
expect(error.toString()).toMatchInlineSnapshot(
`"[CheckFailed] Check failed"`
);
});
});

@@ -1,17 +0,19 @@

import { ASTNode, GraphQLError, printError, Source } from 'graphql'
import { Maybe } from 'graphql/jsutils/Maybe'
import { ASTNode, GraphQLError, Source } from "graphql";
import { Maybe } from "graphql/jsutils/Maybe";
export type Props = {
message: string,
nodes?: Maybe<ReadonlyArray<ASTNode> | ASTNode>,
source?: Maybe<Source>,
positions?: Maybe<ReadonlyArray<number>>,
path?: Maybe<ReadonlyArray<string | number>>,
originalError?: Maybe<Error>,
extensions?: Maybe<{ [key: string]: any }>,
causes?: Error[]
}
message: string;
nodes?: Maybe<ReadonlyArray<ASTNode> | ASTNode>;
source?: Maybe<Source>;
positions?: Maybe<ReadonlyArray<number>>;
path?: Maybe<ReadonlyArray<string | number>>;
originalError?: Maybe<Error>;
extensions?: Maybe<{ [key: string]: any }>;
causes?: Error[];
};
export class GraphQLErrorExt<C extends string> extends GraphQLError {
static readonly BASE_PROPS = new Set('nodes source positions path originalError extensions'.split(' '))
static readonly BASE_PROPS = new Set(
"nodes source positions path originalError extensions".split(" ")
);

@@ -21,3 +23,4 @@ readonly name: string;

constructor(public readonly code: C, message: string, props?: Props) {
super(message,
super(
message,
props?.nodes,

@@ -29,8 +32,9 @@ props?.source,

props?.extensions
)
if (props) for (const prop in props) {
if (!GraphQLErrorExt.BASE_PROPS.has(prop)) {
(this as any)[prop] = (props as any)[prop]
);
if (props)
for (const prop in props) {
if (!GraphQLErrorExt.BASE_PROPS.has(prop)) {
(this as any)[prop] = (props as any)[prop];
}
}
}

@@ -40,16 +44,19 @@ this.name = code;

throw(): never { throw this }
toString() {
let output = `[${this.code}] ${printError(this as any)}`
const causes = (this as any).causes
throw(): never {
throw this;
}
toString(): string {
let output = `[${this.code}] ${super.toString()}`;
const causes = (this as any).causes;
if (causes && causes.length) {
output += '\ncaused by:'
output += "\ncaused by:";
for (const cause of (this as any).causes || []) {
if (!cause) continue
output += '\n\n - '
output += cause.toString().split('\n').join('\n ')
if (!cause) continue;
output += "\n\n - ";
output += cause.toString().split("\n").join("\n ");
}
}
return output
return output;
}

@@ -60,3 +67,3 @@ }

* Return a GraphQLError with a code and arbitrary set of properties.
*
*
* This mainly helps deal with the very long list of parameters that GraphQLError's constructor

@@ -66,13 +73,20 @@ * can take. It also ensures that all errors have a code, and provides a return typing that

* these errors to be a tagged union.
*
* @param code
* @param props
* @returns
*
* @param code
* @param props
* @returns
*/
export function err<C extends string, P extends Props>(code: C, props: P | string): GraphQLErrorExt<C> & P {
const message = typeof props === 'string' ? props : props.message
const error = new GraphQLErrorExt(code, message, typeof props === 'string' ? undefined : props)
return error as any
export function err<C extends string, P extends Props>(
code: C,
props: P | string
): GraphQLErrorExt<C> & P {
const message = typeof props === "string" ? props : props.message;
const error = new GraphQLErrorExt(
code,
message,
typeof props === "string" ? undefined : props
);
return error as any;
}
export default err
export default err;

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