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.0 to 0.2.1

8

CHANGELOG.md

@@ -5,2 +5,10 @@ # CHANGELOG

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.
- _Nothing to see here. Stay tuned._
## v0.2.1
- Add support for graphql@16 [PR #19](https://github.com/apollographql/core-schema-js/pull/19)
## v0.2.0

@@ -7,0 +15,0 @@

3

dist/is.d.ts

@@ -12,3 +12,4 @@ export declare type Template = Parameters<typeof String.raw>;

import type { ASTKindToNode, ASTNode, DirectiveNode, NameNode } from 'graphql';
export declare function isAst<K extends ASTNode["kind"]>(obj: any, ...kinds: K[]): obj is ASTKindToNode[K];
import { Kind } from 'graphql';
export declare function isAst<K extends Kind>(obj: any, ...kinds: Kind[]): obj is ASTKindToNode[K];
export declare const hasName: (node: any) => node is ASTNode & {

@@ -15,0 +16,0 @@ name: NameNode;

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

exports.isEmpty = isEmpty;
const graphql_1 = require("graphql");
function isAst(obj, ...kinds) {

@@ -34,3 +35,3 @@ return kinds.indexOf(obj === null || obj === void 0 ? void 0 : obj.kind) !== -1;

exports.isAst = isAst;
const hasName = (node) => isAst(node === null || node === void 0 ? void 0 : node.name, 'Name');
const hasName = (node) => isAst(node === null || node === void 0 ? void 0 : node.name, graphql_1.Kind.NAME);
exports.hasName = hasName;

@@ -37,0 +38,0 @@ const hasDirectives = (node) => Array.isArray(node === null || node === void 0 ? void 0 : node.directives);

@@ -50,2 +50,7 @@ import { ASTNode, DirectiveNode, DocumentNode, GraphQLDirective, SchemaDefinitionNode, Source } from 'graphql';

}
declare module 'graphql' {
interface GraphQLDirectiveExtensions {
specifiedBy: string;
}
}
//# sourceMappingURL=schema.d.ts.map

@@ -112,3 +112,3 @@ "use strict";

const [prefix] = (0, names_1.getPrefix)(node.name.value);
if (prefix || (0, is_1.isAst)(node, 'Directive', 'DirectiveDefinition')) {
if (prefix || (0, is_1.isAst)(node, graphql_1.Kind.DIRECTIVE, graphql_1.Kind.DIRECTIVE_DEFINITION)) {
return this.names.get(prefix !== null && prefix !== void 0 ? prefix : node.name.value);

@@ -137,2 +137,7 @@ }

exports.schema = schema;
function isCoreArgs(maybeCoreArgs) {
return (typeof maybeCoreArgs === "object" &&
maybeCoreArgs != null &&
"feature" in maybeCoreArgs);
}
function features() {

@@ -146,10 +151,15 @@ var _a, _b, _c, _d;

for (const d of schema.directives || []) {
if (!coreFeature)
if (!coreFeature) {
try {
const candidate = (0, values_1.getArgumentValues)($core, d);
if (CORE_VERSIONS.has(candidate.feature) &&
d.name.value === ((_b = candidate.as) !== null && _b !== void 0 ? _b : 'core')) {
const url = feature_url_1.default.parse(candidate.feature);
coreFeature = new features_1.Feature(url, (_c = candidate.as) !== null && _c !== void 0 ? _c : url.name, d);
const coreArgs = (0, values_1.getArgumentValues)($core, d);
if (isCoreArgs(coreArgs)) {
if (CORE_VERSIONS.has(coreArgs.feature) &&
d.name.value === ((_b = coreArgs.as) !== null && _b !== void 0 ? _b : "core")) {
const url = feature_url_1.default.parse(coreArgs.feature);
coreFeature = new features_1.Feature(url, (_c = coreArgs.as) !== null && _c !== void 0 ? _c : url.name, d);
}
}
else {
throw new Error("Invalid arguments provided to core feature.");
}
}

@@ -159,7 +169,13 @@ catch (err) {

}
if (coreFeature && d.name.value === coreFeature.name)
}
if (coreFeature && d.name.value === coreFeature.name) {
try {
const values = (0, values_1.getArgumentValues)($core, d);
const url = feature_url_1.default.parse(values.feature);
features.add(new features_1.Feature(url, (_d = values.as) !== null && _d !== void 0 ? _d : url.name, d, values.for));
const coreArgs = (0, values_1.getArgumentValues)($core, d);
if (isCoreArgs(coreArgs)) {
const url = feature_url_1.default.parse(coreArgs.feature);
features.add(new features_1.Feature(url, (_d = coreArgs.as) !== null && _d !== void 0 ? _d : url.name, d, coreArgs.for));
}
else {
throw new Error("Invalid arguments provided to core feature.");
}
}

@@ -169,2 +185,3 @@ catch (err) {

}
}
}

@@ -210,11 +227,11 @@ if (!coreFeature)

const $core = new graphql_1.GraphQLDirective({
name: '@core',
name: "core",
args: {
feature: { type: (0, graphql_1.GraphQLNonNull)(graphql_1.GraphQLString), },
feature: { type: new graphql_1.GraphQLNonNull(graphql_1.GraphQLString) },
as: { type: graphql_1.GraphQLString },
'for': { type: Purpose }
for: { type: Purpose },
},
locations: ['SCHEMA'],
locations: [graphql_1.DirectiveLocation.SCHEMA],
isRepeatable: true,
});
//# sourceMappingURL=schema.js.map
{
"name": "@apollo/core-schema",
"version": "0.2.0",
"version": "0.2.1",
"description": "Apollo Core Schema processing library",

@@ -33,12 +33,13 @@ "main": "dist/index.js",

"peerDependencies": {
"graphql": "^15.7.2"
"graphql": "^15.7.2 || ^16.0.0"
},
"devDependencies": {
"@types/jest": "27.0.2",
"graphql": "15.7.2",
"jest": "27.3.1",
"prettier": "2.4.1",
"ts-jest": "27.0.7",
"typescript": "4.4.4"
"@types/jest": "27.0.3",
"graphql": "16.0.1",
"jest": "27.4.4",
"jest-config": "27.0.3",
"prettier": "2.5.1",
"ts-jest": "27.1.1",
"typescript": "4.5.3"
}
}
import {
DirectiveLocation,
GraphQLDirective,

@@ -153,4 +154,4 @@ GraphQLInt,

const other = new GraphQLDirective({
name: "@other",
locations: ["OBJECT", "FIELD_DEFINITION"],
name: "other",
locations: [DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION],
args: {

@@ -165,4 +166,4 @@ input: { type: GraphQLString },

const another = new GraphQLDirective({
name: "@other",
locations: ["OBJECT", "FIELD_DEFINITION"],
name: "other",
locations: [DirectiveLocation.OBJECT, DirectiveLocation.FIELD_DEFINITION],
args: {

@@ -169,0 +170,0 @@ value: { type: GraphQLInt },

@@ -40,4 +40,5 @@ export type Template = Parameters<typeof String.raw>

import type { ASTKindToNode, ASTNode, DirectiveNode, NameNode } from 'graphql'
import { Kind } from 'graphql';
export function isAst<K extends ASTNode["kind"]>(obj: any, ...kinds: K[]): obj is ASTKindToNode[K] {
export function isAst<K extends Kind>(obj: any, ...kinds: Kind[]): obj is ASTKindToNode[K] {
return kinds.indexOf(obj?.kind) !== -1

@@ -47,3 +48,3 @@ }

export const hasName = (node: any): node is ASTNode & { name: NameNode } =>
isAst(node?.name, 'Name')
isAst(node?.name, Kind.NAME)

@@ -50,0 +51,0 @@ export const hasDirectives = (node: any): node is ASTNode & { directives: DirectiveNode[] } =>

@@ -1,2 +0,2 @@

import { ASTNode, DirectiveNode, DocumentNode, GraphQLDirective, GraphQLEnumType, GraphQLNonNull, GraphQLString, parse, SchemaDefinitionNode, Source } from 'graphql'
import { ASTNode, DirectiveLocation, DirectiveNode, DocumentNode, GraphQLDirective, GraphQLEnumType, GraphQLNonNull, GraphQLString, Kind, parse, SchemaDefinitionNode, Source } from 'graphql'
import { getArgumentValues } from 'graphql/execution/values'

@@ -99,4 +99,4 @@ import Core, { CoreFn, Context, Immutable } from './core'

const [prefix] = getPrefix(node.name.value)
if (prefix || isAst(node, 'Directive', 'DirectiveDefinition')) {
return this.names.get(prefix ?? node.name.value)
if (prefix || isAst(node, Kind.DIRECTIVE, Kind.DIRECTIVE_DEFINITION)) {
return this.names.get(prefix ?? node.name.value);
}

@@ -125,2 +125,16 @@ return

interface CoreArgs {
feature: string;
for?: "SECURITY" | "EXECUTION";
as?: string;
}
function isCoreArgs(maybeCoreArgs: unknown): maybeCoreArgs is CoreArgs {
return (
typeof maybeCoreArgs === "object" &&
maybeCoreArgs != null &&
"feature" in maybeCoreArgs
);
}
export function features(this: CoreSchemaContext): Features {

@@ -133,19 +147,35 @@ const schema = this.schema

for (const d of schema.directives || []) {
if (!coreFeature) try {
const candidate = getArgumentValues($core, d)
if (CORE_VERSIONS.has(candidate.feature) &&
d.name.value === (candidate.as ?? 'core')) {
const url = FeatureUrl.parse(candidate.feature)
coreFeature = new Feature(url, candidate.as ?? url.name, d)
if (!coreFeature) {
try {
const coreArgs = getArgumentValues($core, d);
if (isCoreArgs(coreArgs)) {
if (
CORE_VERSIONS.has(coreArgs.feature) &&
d.name.value === (coreArgs.as ?? "core")
) {
const url = FeatureUrl.parse(coreArgs.feature);
coreFeature = new Feature(url, coreArgs.as ?? url.name, d);
}
} else {
throw new Error("Invalid arguments provided to core feature.");
}
} catch (err) {
noCoreErrors.push(err as Error);
}
} catch (err) {
noCoreErrors.push(err as Error)
}
if (coreFeature && d.name.value === coreFeature.name) try {
const values = getArgumentValues($core, d)
const url = FeatureUrl.parse(values.feature)
features.add(new Feature(url, values.as ?? url.name, d, values.for))
} catch (err) {
this.report(ErrBadFeature(d, err as Error))
if (coreFeature && d.name.value === coreFeature.name) {
try {
const coreArgs = getArgumentValues($core, d);
if (isCoreArgs(coreArgs)) {
const url = FeatureUrl.parse(coreArgs.feature);
features.add(
new Feature(url, coreArgs.as ?? url.name, d, coreArgs.for)
);
} else {
throw new Error("Invalid arguments provided to core feature.");
}
} catch (err) {
this.report(ErrBadFeature(d, err as Error));
}
}

@@ -200,10 +230,16 @@ }

const $core = new GraphQLDirective({
name: '@core',
name: "core",
args: {
feature: { type: GraphQLNonNull(GraphQLString), },
feature: { type: new GraphQLNonNull(GraphQLString) },
as: { type: GraphQLString },
'for': { type: Purpose }
for: { type: Purpose },
},
locations: ['SCHEMA'],
locations: [DirectiveLocation.SCHEMA],
isRepeatable: true,
})
});
declare module 'graphql' {
interface GraphQLDirectiveExtensions {
specifiedBy: string;
}
}

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