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

@grapes-agency/apollo-link-local-schema

Package Overview
Dependencies
Maintainers
6
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@grapes-agency/apollo-link-local-schema - npm Package Compare versions

Comparing version 1.0.0-alpha.5 to 1.0.0-alpha.6

resolvers/buildSchemaResolver.d.ts

7

CHANGELOG.md

@@ -5,2 +5,9 @@ # Changelog

## [1.0.0-alpha.6](https://github.com/grapes-agency/apollo-link-local-schema/compare/v1.0.0-alpha.5...v1.0.0-alpha.6) (2020-10-08)
### Features
* introspection ([3da89b0](https://github.com/grapes-agency/apollo-link-local-schema/commit/3da89b07d919af617144c27d4bb15de295351786))
## [1.0.0-alpha.5](https://github.com/grapes-agency/apollo-link-local-schema/compare/v1.0.0-alpha.4...v1.0.0-alpha.5) (2020-10-07)

@@ -7,0 +14,0 @@

257

index.cjs.js

@@ -11,6 +11,21 @@ 'use strict';

const isObjectTypeDefinition = (node) => node.kind === 'ObjectTypeDefinition';
const isInterfaceTypeDefinition = (node) => node.kind === 'InterfaceTypeDefinition';
const isUnionTypeDefinition = (node) => node.kind === 'UnionTypeDefinition';
const isInputObjectTypeDefinition = (node) => node.kind === 'InputObjectTypeDefinition';
const isEnumTypeDefinition = (node) => node.kind === 'EnumTypeDefinition';
const isObjectTypeExtension = (node) => node.kind === 'ObjectTypeExtension';
const isScalarTypeDefinition = (node) => node.kind === 'ScalarTypeDefinition';
const isOperationDefinition = (node) => node.kind === 'OperationDefinition';
const isDirectiveDefinition = (node) => node.kind === 'DirectiveDefinition';
const isFragmentDefinition = (node) => node.kind === 'FragmentDefinition';
const isTypeDefinition = (node) => [
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
].includes(node.kind);
const isListType = (node) => node.kind === 'ListType';
const isNonNullType = (node) => node.kind === 'NonNullType';
const getTypeName = (type) => {

@@ -22,5 +37,5 @@ if (type.kind === 'NonNullType' || type.kind === 'ListType') {

};
const isListType = (type) => {
const isDeepListType = (type) => {
if (type.kind === 'NonNullType') {
return isListType(type.type);
return isDeepListType(type.type);
}

@@ -226,3 +241,3 @@ return type.kind === 'ListType';

}
if (isListType(selectionField.type)) {
if (isDeepListType(selectionField.type)) {
if (!Array.isArray(currentData)) {

@@ -257,3 +272,5 @@ return;

let stopped = false;
Promise.resolve(resolver.subscribe(root, args, context, info)).then(asyncIterator => {
let asyncIterator;
Promise.resolve(resolver.subscribe(root, args, context, info)).then(iterator => {
asyncIterator = iterator;
if (stopped) {

@@ -270,4 +287,6 @@ return;

observer.next({
[fieldName]: addTypesnames(Object.assign(Object.assign({}, info), { data: transformedValue, objectType,
typeMap })),
[fieldName]: objectType
? addTypesnames(Object.assign(Object.assign({}, info), { data: transformedValue, objectType,
typeMap }))
: transformedValue,
});

@@ -287,2 +306,4 @@ });

return () => {
var _a;
(_a = asyncIterator === null || asyncIterator === void 0 ? void 0 : asyncIterator.return) === null || _a === void 0 ? void 0 : _a.call(asyncIterator);
stopped = true;

@@ -325,11 +346,14 @@ };

const mergedArgs = Object.assign(Object.assign({}, defaultArgs), args);
const __typename = getTypeName(fieldDefinition.type);
const targetType = typeMap.get(__typename);
if (isSubscriptionResolver(fieldResolver)) {
return mapSubscription({ fieldName, resolver: fieldResolver, objectType: targetType, typeMap })(root, mergedArgs, context, info);
}
return Promise.resolve(fieldResolver(root, mergedArgs, context, info)).then(result => {
const __typename = getTypeName(fieldDefinition.type);
const targetType = typeMap.get(__typename);
if (isSubscriptionResolver(result)) {
return mapSubscription({ fieldName, resolver: result, objectType: targetType, typeMap })(root, mergedArgs, context, info);
}
if (!targetType) {
return result;
}
if (isSubscriptionResolver(result)) {
return mapSubscription({ fieldName, resolver: result, objectType: targetType, typeMap })(root, mergedArgs, context, info);
}
return addTypesnames(Object.assign(Object.assign({}, info), { data: result, objectType: targetType, typeMap }));

@@ -381,5 +405,2 @@ });

const processedData = {};
if (currentData.__typename) {
processedData.__typename = currentData.__typename;
}
selectionSet.selections.forEach(selection => {

@@ -425,3 +446,3 @@ var _a;

const typeName = fragment.typeCondition.name.value;
if (!typeMap.has(typeName)) {
if (!typeMap.has(typeName) && !typeName.startsWith('__')) {
throw new Error(`Unknown type "${typeName}".`);

@@ -435,3 +456,3 @@ }

const typeName = selection.typeCondition.name.value;
if (!typeMap.has(typeName)) {
if (!typeMap.has(typeName) && !typeName.startsWith('__')) {
throw new Error(`Unknown type "${typeName}".`);

@@ -448,3 +469,3 @@ }

}
if (selection.kind === 'Field' && selection.name.value !== '__typename') {
if (selection.kind === 'Field' && !selection.name.value.startsWith('__')) {
const field = (_a = type.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.name.value === selection.name.value);

@@ -471,4 +492,179 @@ if (!field) {

// https://github.com/graphql/graphql-spec/blob/master/spec/Section%204%20--%20Introspection.md
const specifiedDefinitions = graphql.specifiedScalarTypes.map(scalarType => (Object.assign({ kind: 'ScalarTypeDefinition', name: {
kind: 'Name',
value: scalarType.name,
} }, (scalarType.description
? {
description: {
kind: 'StringValue',
value: scalarType.description,
},
}
: {}))));
const getDeprecateDirective = (node) => { var _a; return (_a = node.directives) === null || _a === void 0 ? void 0 : _a.find(directive => directive.name.value === 'deprecated'); };
const isDeprecated = (node) => Boolean(getDeprecateDirective(node));
const getDeprecationReason = (node) => {
var _a;
const directive = getDeprecateDirective(node);
if (!directive) {
return null;
}
const reasonArg = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find(arg => arg.name.value === 'reason');
if (!reasonArg) {
return null;
}
return reasonArg.value.value;
};
const addSchemaResolver = (resolvers, typeDefs) => {
const allTypes = [...specifiedDefinitions, ...typeDefs.definitions].filter(isTypeDefinition);
const findType = (name) => allTypes.find(definition => { var _a; return 'name' in definition && ((_a = definition.name) === null || _a === void 0 ? void 0 : _a.value) === name; });
if (!resolvers.Query) {
resolvers.Query = {};
}
const schemaDefinition = typeDefs.definitions.find(definition => definition.kind === 'SchemaDefinition');
const findMainType = (name, fallbackName) => {
const queryOperation = schemaDefinition === null || schemaDefinition === void 0 ? void 0 : schemaDefinition.operationTypes.find(operationType => operationType.operation === name);
const typeName = (queryOperation === null || queryOperation === void 0 ? void 0 : queryOperation.type.name.value) || fallbackName;
const type = findType(typeName);
if (type) {
return {
__typename: '__Type',
node: type,
};
}
return null;
};
resolvers.Query.__schema = () => ({
__typename: '__Schema',
});
resolvers.Query.__type = (_root, { name }) => {
const type = findType(name);
if (type) {
return { __typename: '__Type', node: type };
}
return null;
};
resolvers.__Schema = {
description: () => { var _a; return ((_a = schemaDefinition === null || schemaDefinition === void 0 ? void 0 : schemaDefinition.description) === null || _a === void 0 ? void 0 : _a.value) || null; },
queryType: () => findMainType('query', 'Query'),
mutationType: () => findMainType('mutation', 'Mutation'),
subscriptionType: () => findMainType('subscription', 'Subscription'),
directives: () => typeDefs.definitions.filter(isDirectiveDefinition).map(node => ({ __typename: '__Directive', node })),
types: () => allTypes.map(type => ({ __typename: '__Type', node: type })),
};
resolvers.__Type = {
kind: ({ node }) => {
switch (node.kind) {
case 'ScalarTypeDefinition': {
return 'SCALAR';
}
case 'ObjectTypeDefinition': {
return 'OBJECT';
}
case 'InterfaceTypeDefinition': {
return 'INTERFACE';
}
case 'UnionTypeDefinition': {
return 'UNION';
}
case 'EnumTypeDefinition': {
return 'ENUM';
}
case 'InputObjectTypeDefinition': {
return 'INPUT_OBJECT';
}
case 'ListType': {
return 'LIST';
}
case 'NonNullType': {
return 'NON_NULL';
}
default: {
throw new Error(`Unknown kind ${node.kind}`);
}
}
},
name: ({ node }) => { var _a; return ('name' in node ? ((_a = node.name) === null || _a === void 0 ? void 0 : _a.value) || null : null); },
description: ({ node }) => { var _a; return ('description' in node ? ((_a = node.description) === null || _a === void 0 ? void 0 : _a.value) || null : null); },
fields: ({ node }, { includeDeprecated = false }) => {
var _a;
if (!(isObjectTypeDefinition(node) || isInterfaceTypeDefinition(node))) {
return null;
}
return (((_a = node.fields) === null || _a === void 0 ? void 0 : _a.filter(field => includeDeprecated || isDeprecated(field)).map(field => ({ __typename: '__Field', node: field }))) || []);
},
interfaces: ({ node }) => {
var _a;
if (!(isObjectTypeDefinition(node) || isInterfaceTypeDefinition(node))) {
return null;
}
return ((_a = node.interfaces) === null || _a === void 0 ? void 0 : _a.map(iface => ({ __typename: '__Type', node: iface }))) || [];
},
possibleTypes: ({ node }) => {
var _a;
if (!isUnionTypeDefinition(node)) {
return null;
}
// @todo add interface type here
return ((_a = node.types) === null || _a === void 0 ? void 0 : _a.map(type => ({ __typename: '__Type', node: findType(type.name.value) }))) || [];
},
enumValues: ({ node }, { includeDeprecated = false }) => {
var _a;
if (!isEnumTypeDefinition(node)) {
return null;
}
return (((_a = node.values) === null || _a === void 0 ? void 0 : _a.filter(value => includeDeprecated || isDeprecated(value)).map(value => ({ __typename: '__EnumValue', node: value }))) || []);
},
inputFields: ({ node }) => {
var _a;
if (!isInputObjectTypeDefinition(node)) {
return null;
}
return ((_a = node.fields) === null || _a === void 0 ? void 0 : _a.map(field => ({ __typename: '__InputValue', node: field }))) || [];
},
ofType: ({ node }) => {
if (!(isListType(node) || isNonNullType(node))) {
return null;
}
return { __typename: '__Type', node: node.type.kind === 'NamedType' ? findType(node.type.name.value) : node.type };
},
};
resolvers.__Field = {
name: ({ node }) => node.name.value,
description: ({ node }) => { var _a; return ((_a = node.description) === null || _a === void 0 ? void 0 : _a.value) || null; },
args: ({ node }) => { var _a; return ((_a = node.arguments) === null || _a === void 0 ? void 0 : _a.map(arg => ({ __typename: '__InputValue', node: arg }))) || []; },
type: ({ node }) => ({
__typename: '__Type',
node: node.type.kind === 'NamedType' ? findType(node.type.name.value) : node.type,
}),
isDeprecated: ({ node }) => isDeprecated(node),
deprecationReason: ({ node }) => getDeprecationReason(node),
};
resolvers.__InputValue = {
name: ({ node }) => node.name.value,
description: ({ node }) => { var _a; return ((_a = node.description) === null || _a === void 0 ? void 0 : _a.value) || null; },
type: ({ node }) => ({
__typename: '__Type',
node: node.type.kind === 'NamedType' ? findType(node.type.name.value) : node.type,
}),
defaultValue: ({ node }) => node.defaultValue && ('value' in node.defaultValue ? String(node.defaultValue.value) : null),
};
resolvers.__EnumValue = {
name: ({ node }) => node.name.value,
description: ({ node }) => { var _a; return ((_a = node.description) === null || _a === void 0 ? void 0 : _a.value) || null; },
isDeprecated: ({ node }) => isDeprecated(node),
deprecationReason: ({ node }) => getDeprecationReason(node),
};
resolvers.__Directive = {
name: ({ node }) => node.name.value,
description: ({ node }) => { var _a; return ((_a = node.description) === null || _a === void 0 ? void 0 : _a.value) || null; },
locations: ({ node }) => node.locations.map(location => location.value),
args: ({ node }) => { var _a; return ((_a = node.arguments) === null || _a === void 0 ? void 0 : _a.map(arg => ({ __typename: '__InputValue', node: arg }))) || []; },
isRepeatable: ({ node }) => node.repeatable,
};
};
class LocalSchemaLink extends client.ApolloLink {
constructor({ typeDefs, resolvers, context, assumeLocal, validateQuery = true, discriminationDirective = 'local', }) {
constructor({ typeDefs, resolvers, context, assumeLocal, validateQuery = true, introspection = true, discriminationDirective = 'local', }) {
super();

@@ -479,3 +675,7 @@ this.localState = null;

this.assumeLocal = Boolean(assumeLocal);
const [mappedResolvers, typeMap] = mapResolvers(resolvers, mergeDocuments(Array.isArray(typeDefs) ? typeDefs : [typeDefs]));
const mergedTypeDefs = mergeDocuments(Array.isArray(typeDefs) ? typeDefs : [typeDefs]);
const [mappedResolvers, typeMap] = mapResolvers(resolvers, mergedTypeDefs);
if (introspection) {
addSchemaResolver(mappedResolvers, mergedTypeDefs);
}
this.resolvers = mappedResolvers;

@@ -540,3 +740,4 @@ this.typeMap = typeMap;

.then(({ data, errors }) => {
observer.next({ data: cleanResult({ data, document: localQuery }), errors });
const cleanedData = cleanResult({ data, document: localQuery });
observer.next({ data: cleanedData, errors });
observer.complete();

@@ -563,9 +764,15 @@ })

}
const observers = [];
const observables = [];
Object.entries(data).forEach(([key, observable]) => {
observers.push(observable.map(result => ({ [key]: result })));
observables.push(observable.map(result => ({ [key]: result })));
});
subscription = client.Observable.of({ data: {} })
.concat(...observers)
.subscribe(observer);
if (observables.length === 0) {
observer.complete();
return;
}
let observable = observables[0];
if (observables.length > 1) {
observable = observable.concat(...observables.slice(1));
}
subscription = observable.subscribe(observer);
})

@@ -572,0 +779,0 @@ .catch(error => {

3

LocalSchemaLink.d.ts

@@ -12,2 +12,3 @@ /// <reference types="zen-observable" />

validateQuery?: boolean;
introspection?: boolean;
}

@@ -23,3 +24,3 @@ export declare class LocalSchemaLink<Context = any> extends ApolloLink {

private discriminationDirective;
constructor({ typeDefs, resolvers, context, assumeLocal, validateQuery, discriminationDirective, }: LocalSchemaLinkOptions<Context>);
constructor({ typeDefs, resolvers, context, assumeLocal, validateQuery, introspection, discriminationDirective, }: LocalSchemaLinkOptions<Context>);
private getLocalState;

@@ -26,0 +27,0 @@ private splitDocumentByDirective;

@@ -10,5 +10,7 @@ import { ApolloLink, Observable } from '@apollo/client';

import './utils/index.js';
import { addSchemaResolver } from './resolvers/buildSchemaResolver.js';
import './resolvers/index.js';
class LocalSchemaLink extends ApolloLink {
constructor({ typeDefs, resolvers, context, assumeLocal, validateQuery = true, discriminationDirective = 'local', }) {
constructor({ typeDefs, resolvers, context, assumeLocal, validateQuery = true, introspection = true, discriminationDirective = 'local', }) {
super();

@@ -19,3 +21,7 @@ this.localState = null;

this.assumeLocal = Boolean(assumeLocal);
const [mappedResolvers, typeMap] = mapResolvers(resolvers, mergeDocuments(Array.isArray(typeDefs) ? typeDefs : [typeDefs]));
const mergedTypeDefs = mergeDocuments(Array.isArray(typeDefs) ? typeDefs : [typeDefs]);
const [mappedResolvers, typeMap] = mapResolvers(resolvers, mergedTypeDefs);
if (introspection) {
addSchemaResolver(mappedResolvers, mergedTypeDefs);
}
this.resolvers = mappedResolvers;

@@ -80,3 +86,4 @@ this.typeMap = typeMap;

.then(({ data, errors }) => {
observer.next({ data: cleanResult({ data, document: localQuery }), errors });
const cleanedData = cleanResult({ data, document: localQuery });
observer.next({ data: cleanedData, errors });
observer.complete();

@@ -103,9 +110,15 @@ })

}
const observers = [];
const observables = [];
Object.entries(data).forEach(([key, observable]) => {
observers.push(observable.map(result => ({ [key]: result })));
observables.push(observable.map(result => ({ [key]: result })));
});
subscription = Observable.of({ data: {} })
.concat(...observers)
.subscribe(observer);
if (observables.length === 0) {
observer.complete();
return;
}
let observable = observables[0];
if (observables.length > 1) {
observable = observable.concat(...observables.slice(1));
}
subscription = observable.subscribe(observer);
})

@@ -112,0 +125,0 @@ .catch(error => {

{
"name": "@grapes-agency/apollo-link-local-schema",
"version": "1.0.0-alpha.5",
"version": "1.0.0-alpha.6",
"description": "Lightweight local schema resolver for @apollo/client",

@@ -5,0 +5,0 @@ "main": "index.cjs.js",

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

import { getTypeName, isListType } from './node.js';
import { getTypeName, isDeepListType } from './node.js';
import { extendSelection } from './extendSelection.js';

@@ -27,3 +27,3 @@

}
if (isListType(selectionField.type)) {
if (isDeepListType(selectionField.type)) {
if (!Array.isArray(currentData)) {

@@ -30,0 +30,0 @@ return;

@@ -14,5 +14,2 @@ import { isOperationDefinition, isFragmentDefinition } from './node.js';

const processedData = {};
if (currentData.__typename) {
processedData.__typename = currentData.__typename;
}
selectionSet.selections.forEach(selection => {

@@ -19,0 +16,0 @@ var _a;

@@ -7,1 +7,2 @@ export * from './mergeDocuments';

export * from './validate';
export * from './node';

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

export { getTypeName, isDeepListType, isDirectiveDefinition, isEnumTypeDefinition, isFragmentDefinition, isInputObjectTypeDefinition, isInterfaceTypeDefinition, isListType, isNamedType, isNonNullType, isObjectTypeDefinition, isObjectTypeExtension, isOperationDefinition, isScalarTypeDefinition, isTypeDefinition, isUnionTypeDefinition } from './node.js';
export { mergeDocuments } from './mergeDocuments.js';

@@ -2,0 +3,0 @@ export { splitDocumentByDirective } from './splitDocumentByDirective.js';

@@ -38,11 +38,14 @@ import { print } from 'graphql';

const mergedArgs = Object.assign(Object.assign({}, defaultArgs), args);
const __typename = getTypeName(fieldDefinition.type);
const targetType = typeMap.get(__typename);
if (isSubscriptionResolver(fieldResolver)) {
return mapSubscription({ fieldName, resolver: fieldResolver, objectType: targetType, typeMap })(root, mergedArgs, context, info);
}
return Promise.resolve(fieldResolver(root, mergedArgs, context, info)).then(result => {
const __typename = getTypeName(fieldDefinition.type);
const targetType = typeMap.get(__typename);
if (isSubscriptionResolver(result)) {
return mapSubscription({ fieldName, resolver: result, objectType: targetType, typeMap })(root, mergedArgs, context, info);
}
if (!targetType) {
return result;
}
if (isSubscriptionResolver(result)) {
return mapSubscription({ fieldName, resolver: result, objectType: targetType, typeMap })(root, mergedArgs, context, info);
}
return addTypesnames(Object.assign(Object.assign({}, info), { data: result, objectType: targetType, typeMap }));

@@ -49,0 +52,0 @@ });

@@ -11,3 +11,3 @@ import { ObjectTypeDefinitionNode } from 'graphql';

resolver: SubscriptionResolver<T>;
objectType: ObjectTypeDefinitionNode;
objectType?: ObjectTypeDefinitionNode;
typeMap: Map<string, ObjectTypeDefinitionNode>;

@@ -14,0 +14,0 @@ }

@@ -9,3 +9,5 @@ import { Observable } from '@apollo/client';

let stopped = false;
Promise.resolve(resolver.subscribe(root, args, context, info)).then(asyncIterator => {
let asyncIterator;
Promise.resolve(resolver.subscribe(root, args, context, info)).then(iterator => {
asyncIterator = iterator;
if (stopped) {

@@ -22,4 +24,6 @@ return;

observer.next({
[fieldName]: addTypesnames(Object.assign(Object.assign({}, info), { data: transformedValue, objectType,
typeMap })),
[fieldName]: objectType
? addTypesnames(Object.assign(Object.assign({}, info), { data: transformedValue, objectType,
typeMap }))
: transformedValue,
});

@@ -39,2 +43,4 @@ });

return () => {
var _a;
(_a = asyncIterator === null || asyncIterator === void 0 ? void 0 : asyncIterator.return) === null || _a === void 0 ? void 0 : _a.call(asyncIterator);
stopped = true;

@@ -41,0 +47,0 @@ };

@@ -1,18 +0,17 @@

import { TypeNode, ObjectTypeExtensionNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, OperationDefinitionNode, FragmentDefinitionNode } from 'graphql';
export declare const isObjectTypeDefinition: (node: {
kind: string;
}) => node is ObjectTypeDefinitionNode;
export declare const isObjectTypeExtension: (node: {
kind: string;
}) => node is ObjectTypeExtensionNode;
export declare const isScalarTypeDefinition: (node: {
kind: string;
}) => node is ScalarTypeDefinitionNode;
export declare const isOperationDefinition: (node: {
kind: string;
}) => node is OperationDefinitionNode;
export declare const isFragmentDefinition: (node: {
kind: string;
}) => node is FragmentDefinitionNode;
import { TypeNode, NamedTypeNode, ObjectTypeExtensionNode, ObjectTypeDefinitionNode, ScalarTypeDefinitionNode, OperationDefinitionNode, FragmentDefinitionNode, EnumTypeDefinitionNode, DirectiveDefinitionNode, InputObjectTypeDefinitionNode, ASTNode, InterfaceTypeDefinitionNode, ListTypeNode, NonNullTypeNode, TypeDefinitionNode, UnionTypeDefinitionNode } from 'graphql';
export declare const isObjectTypeDefinition: (node: ASTNode) => node is ObjectTypeDefinitionNode;
export declare const isInterfaceTypeDefinition: (node: ASTNode) => node is InterfaceTypeDefinitionNode;
export declare const isUnionTypeDefinition: (node: ASTNode) => node is UnionTypeDefinitionNode;
export declare const isInputObjectTypeDefinition: (node: ASTNode) => node is InputObjectTypeDefinitionNode;
export declare const isEnumTypeDefinition: (node: ASTNode) => node is EnumTypeDefinitionNode;
export declare const isObjectTypeExtension: (node: ASTNode) => node is ObjectTypeExtensionNode;
export declare const isScalarTypeDefinition: (node: ASTNode) => node is ScalarTypeDefinitionNode;
export declare const isOperationDefinition: (node: ASTNode) => node is OperationDefinitionNode;
export declare const isDirectiveDefinition: (node: ASTNode) => node is DirectiveDefinitionNode;
export declare const isFragmentDefinition: (node: ASTNode) => node is FragmentDefinitionNode;
export declare const isTypeDefinition: (node: ASTNode) => node is TypeDefinitionNode;
export declare const isNamedType: (node: TypeNode) => node is NamedTypeNode;
export declare const isListType: (node: ASTNode) => node is ListTypeNode;
export declare const isNonNullType: (node: ASTNode) => node is NonNullTypeNode;
export declare const getTypeName: (type: TypeNode) => string;
export declare const isListType: (type: TypeNode) => boolean;
export declare const isDeepListType: (type: TypeNode) => boolean;
const isObjectTypeDefinition = (node) => node.kind === 'ObjectTypeDefinition';
const isInterfaceTypeDefinition = (node) => node.kind === 'InterfaceTypeDefinition';
const isUnionTypeDefinition = (node) => node.kind === 'UnionTypeDefinition';
const isInputObjectTypeDefinition = (node) => node.kind === 'InputObjectTypeDefinition';
const isEnumTypeDefinition = (node) => node.kind === 'EnumTypeDefinition';
const isObjectTypeExtension = (node) => node.kind === 'ObjectTypeExtension';
const isScalarTypeDefinition = (node) => node.kind === 'ScalarTypeDefinition';
const isOperationDefinition = (node) => node.kind === 'OperationDefinition';
const isDirectiveDefinition = (node) => node.kind === 'DirectiveDefinition';
const isFragmentDefinition = (node) => node.kind === 'FragmentDefinition';
const isTypeDefinition = (node) => [
'ScalarTypeDefinition',
'ObjectTypeDefinition',
'InterfaceTypeDefinition',
'UnionTypeDefinition',
'EnumTypeDefinition',
'InputObjectTypeDefinition',
].includes(node.kind);
const isNamedType = (node) => node.kind === 'NonNullType';
const isListType = (node) => node.kind === 'ListType';
const isNonNullType = (node) => node.kind === 'NonNullType';
const getTypeName = (type) => {

@@ -12,5 +28,5 @@ if (type.kind === 'NonNullType' || type.kind === 'ListType') {

};
const isListType = (type) => {
const isDeepListType = (type) => {
if (type.kind === 'NonNullType') {
return isListType(type.type);
return isDeepListType(type.type);
}

@@ -20,3 +36,3 @@ return type.kind === 'ListType';

export { getTypeName, isFragmentDefinition, isListType, isObjectTypeDefinition, isObjectTypeExtension, isOperationDefinition, isScalarTypeDefinition };
export { getTypeName, isDeepListType, isDirectiveDefinition, isEnumTypeDefinition, isFragmentDefinition, isInputObjectTypeDefinition, isInterfaceTypeDefinition, isListType, isNamedType, isNonNullType, isObjectTypeDefinition, isObjectTypeExtension, isOperationDefinition, isScalarTypeDefinition, isTypeDefinition, isUnionTypeDefinition };
//# sourceMappingURL=node.js.map

@@ -11,3 +11,3 @@ import { isOperationDefinition, isFragmentDefinition, getTypeName } from './node.js';

const typeName = fragment.typeCondition.name.value;
if (!typeMap.has(typeName)) {
if (!typeMap.has(typeName) && !typeName.startsWith('__')) {
throw new Error(`Unknown type "${typeName}".`);

@@ -21,3 +21,3 @@ }

const typeName = selection.typeCondition.name.value;
if (!typeMap.has(typeName)) {
if (!typeMap.has(typeName) && !typeName.startsWith('__')) {
throw new Error(`Unknown type "${typeName}".`);

@@ -34,3 +34,3 @@ }

}
if (selection.kind === 'Field' && selection.name.value !== '__typename') {
if (selection.kind === 'Field' && !selection.name.value.startsWith('__')) {
const field = (_a = type.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.name.value === selection.name.value);

@@ -37,0 +37,0 @@ if (!field) {

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

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