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

graphql-anywhere

Package Overview
Dependencies
Maintainers
3
Versions
139
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-anywhere - npm Package Compare versions

Comparing version 1.1.2 to 2.0.0

4

CHANGELOG.md
# Change log
### v2.0.0
Change typings from `typed-graphql` to `@types/graphql`.
### v1.1.2

@@ -4,0 +8,0 @@

6

lib/src/directives.d.ts

@@ -1,5 +0,5 @@

/// <reference types="typed-graphql" />
import { Selection } from 'graphql';
export declare function shouldInclude(selection: Selection, variables?: {
/// <reference types="graphql" />
import { SelectionNode } from 'graphql';
export declare function shouldInclude(selection: SelectionNode, variables?: {
[name: string]: any;
}): Boolean;

@@ -1,14 +0,14 @@

/// <reference types="typed-graphql" />
import { Document, OperationDefinition, FragmentDefinition } from 'graphql';
export declare function getMutationDefinition(doc: Document): OperationDefinition;
export declare function checkDocument(doc: Document): void;
export declare function getOperationName(doc: Document): string;
export declare function getFragmentDefinitions(doc: Document): FragmentDefinition[];
export declare function getQueryDefinition(doc: Document): OperationDefinition;
export declare function getFragmentDefinition(doc: Document): FragmentDefinition;
/// <reference types="graphql" />
import { DocumentNode, OperationDefinitionNode, FragmentDefinitionNode } from 'graphql';
export declare function getMutationDefinition(doc: DocumentNode): OperationDefinitionNode;
export declare function checkDocument(doc: DocumentNode): void;
export declare function getOperationName(doc: DocumentNode): string;
export declare function getFragmentDefinitions(doc: DocumentNode): FragmentDefinitionNode[];
export declare function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode;
export declare function getFragmentDefinition(doc: DocumentNode): FragmentDefinitionNode;
export interface FragmentMap {
[fragmentName: string]: FragmentDefinition;
[fragmentName: string]: FragmentDefinitionNode;
}
export declare function createFragmentMap(fragments?: FragmentDefinition[]): FragmentMap;
export declare function addFragmentsToDocument(queryDoc: Document, fragments: FragmentDefinition[]): Document;
export declare function getMainDefinition(queryDoc: Document): OperationDefinition | FragmentDefinition;
export declare function createFragmentMap(fragments?: FragmentDefinitionNode[]): FragmentMap;
export declare function addFragmentsToDocument(queryDoc: DocumentNode, fragments: FragmentDefinitionNode[]): DocumentNode;
export declare function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode;

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

/// <reference types="typed-graphql" />
import { Document } from 'graphql';
/// <reference types="graphql" />
import { DocumentNode } from 'graphql';
import { FragmentMap } from './getFromAST';

@@ -29,2 +29,2 @@ export { filter, check, propType } from './utilities';

};
export default function graphql(resolver: Resolver, document: Document, rootValue?: any, contextValue?: any, variableValues?: VariableMap, execOptions?: ExecOptions): any;
export default function graphql(resolver: Resolver, document: DocumentNode, rootValue?: any, contextValue?: any, variableValues?: VariableMap, execOptions?: ExecOptions): any;

@@ -1,7 +0,7 @@

/// <reference types="typed-graphql" />
import { Field, InlineFragment, Selection, GraphQLResult } from 'graphql';
export declare function argumentsObjectFromField(field: Field, variables: Object): Object;
export declare function resultKeyNameFromField(field: Field): string;
export declare function isField(selection: Selection): selection is Field;
export declare function isInlineFragment(selection: Selection): selection is InlineFragment;
export declare function graphQLResultHasError(result: GraphQLResult): number;
/// <reference types="graphql" />
import { FieldNode, InlineFragmentNode, SelectionNode, ExecutionResult } from 'graphql';
export declare function argumentsObjectFromField(field: FieldNode, variables: Object): Object;
export declare function resultKeyNameFromField(field: FieldNode): string;
export declare function isField(selection: SelectionNode): selection is FieldNode;
export declare function isInlineFragment(selection: SelectionNode): selection is InlineFragmentNode;
export declare function graphQLResultHasError(result: ExecutionResult): number;

@@ -1,5 +0,5 @@

/// <reference types="typed-graphql" />
import { Document } from 'graphql';
export declare function filter(doc: Document, data: any): any;
export declare function check(doc: Document, data: any): void;
/// <reference types="graphql" />
import { DocumentNode } from 'graphql';
export declare function filter(doc: DocumentNode, data: any): any;
export declare function check(doc: DocumentNode, data: any): void;
export declare function propType(doc: any): any;
{
"name": "graphql-anywhere",
"version": "1.1.2",
"version": "2.0.0",
"description": "Run GraphQL queries with no schema and just one resolver",

@@ -42,2 +42,3 @@ "main": "./lib/src/index.js",

"@types/react-dom": "^0.14.18",
"@types/graphql": "^0.8.0",
"async": "^2.0.0",

@@ -58,5 +59,4 @@ "chai": "^3.5.0",

"tslint": "3.15.1",
"typed-graphql": "^1.0.2",
"typescript": "^2.0.0"
}
}

@@ -47,2 +47,44 @@ # graphql-anywhere

## Utilities
See http://dev.apollodata.com/react/fragments.html for examples of how you might use these.
```js
import { filter } from 'graphql-anywhere'
filter(doc, data);
```
- `doc`: a GraphQL document, as generated by the template literal from `graphql-tag`, typically either a query or a fragment.
- `data`: an object of data to be filtered by the `doc`
Filter `data` according to `doc`.
```js
import { check } from 'graphql-anywhere'
check(doc, data);
```
- `doc`: a GraphQL document, as generated by the template literal from `graphql-tag`, typically either a query or a fragment.
- `data`: an object of data, as may have been filtered by `doc`.
Check that `data` is of the form defined by the query or fragment. Throw an exception if not.
```js
import { propType } from 'graphql-anywhere'
X.propTypes = {
foo: propType(doc),
bar: propType(doc).isRequired,
}
```
- `doc`: a GraphQL document, as generated by the template literal from `graphql-tag`, typically either a query or a fragment.
Generate a React `propType` checking function to ensure that the passed prop is in the right form.
### Supported GraphQL features

@@ -49,0 +91,0 @@

// Provides the methods that allow QueryManager to handle
// the `skip` and `include` directives within GraphQL.
import {
Selection,
Variable,
BooleanValue,
SelectionNode,
VariableNode,
BooleanValueNode,
} from 'graphql';
export function shouldInclude(selection: Selection, variables?: { [name: string]: any }): Boolean {
export function shouldInclude(selection: SelectionNode, variables?: { [name: string]: any }): Boolean {
if (!variables) {

@@ -47,3 +47,3 @@ variables = {};

} else {
evaledValue = variables[(ifValue as Variable).name.value];
evaledValue = variables[(ifValue as VariableNode).name.value];
if (evaledValue === undefined) {

@@ -54,3 +54,3 @@ throw new Error(`Invalid variable referenced in @${directiveName} directive.`);

} else {
evaledValue = (ifValue as BooleanValue).value;
evaledValue = (ifValue as BooleanValueNode).value;
}

@@ -57,0 +57,0 @@

import {
Document,
OperationDefinition,
FragmentDefinition,
DocumentNode,
OperationDefinitionNode,
FragmentDefinitionNode,
} from 'graphql';
export function getMutationDefinition(doc: Document): OperationDefinition {
export function getMutationDefinition(doc: DocumentNode): OperationDefinitionNode {
checkDocument(doc);
let mutationDef: OperationDefinition = null;
let mutationDef: OperationDefinitionNode = null;
doc.definitions.forEach((definition) => {
if (definition.kind === 'OperationDefinition'
&& (definition as OperationDefinition).operation === 'mutation') {
mutationDef = definition as OperationDefinition;
&& (definition as OperationDefinitionNode).operation === 'mutation') {
mutationDef = definition as OperationDefinitionNode;
}

@@ -26,3 +26,3 @@ });

// Checks the document for errors and throws an exception if there is an error.
export function checkDocument(doc: Document) {
export function checkDocument(doc: DocumentNode) {
if (doc.kind !== 'Document') {

@@ -43,8 +43,8 @@ throw new Error(`Expecting a parsed GraphQL document. Perhaps you need to wrap the query \

export function getOperationName(doc: Document): string {
export function getOperationName(doc: DocumentNode): string {
let res: string = '';
doc.definitions.forEach((definition) => {
if (definition.kind === 'OperationDefinition'
&& (definition as OperationDefinition).name) {
res = (definition as OperationDefinition).name.value;
&& (definition as OperationDefinitionNode).name) {
res = (definition as OperationDefinitionNode).name.value;
}

@@ -56,4 +56,4 @@ });

// Returns the FragmentDefinitions from a particular document as an array
export function getFragmentDefinitions(doc: Document): FragmentDefinition[] {
let fragmentDefinitions: FragmentDefinition[] = doc.definitions.filter((definition) => {
export function getFragmentDefinitions(doc: DocumentNode): FragmentDefinitionNode[] {
let fragmentDefinitions: FragmentDefinitionNode[] = doc.definitions.filter((definition) => {
if (definition.kind === 'FragmentDefinition') {

@@ -64,3 +64,3 @@ return true;

}
}) as FragmentDefinition[];
}) as FragmentDefinitionNode[];

@@ -70,10 +70,10 @@ return fragmentDefinitions;

export function getQueryDefinition(doc: Document): OperationDefinition {
export function getQueryDefinition(doc: DocumentNode): OperationDefinitionNode {
checkDocument(doc);
let queryDef: OperationDefinition = null;
let queryDef: OperationDefinitionNode = null;
doc.definitions.map((definition) => {
if (definition.kind === 'OperationDefinition'
&& (definition as OperationDefinition).operation === 'query') {
queryDef = definition as OperationDefinition;
&& (definition as OperationDefinitionNode).operation === 'query') {
queryDef = definition as OperationDefinitionNode;
}

@@ -89,3 +89,3 @@ });

export function getFragmentDefinition(doc: Document): FragmentDefinition {
export function getFragmentDefinition(doc: DocumentNode): FragmentDefinitionNode {
if (doc.kind !== 'Document') {

@@ -100,3 +100,3 @@ throw new Error(`Expecting a parsed GraphQL document. Perhaps you need to wrap the query \

const fragmentDef = doc.definitions[0] as FragmentDefinition;
const fragmentDef = doc.definitions[0] as FragmentDefinitionNode;

@@ -107,7 +107,7 @@ if (fragmentDef.kind !== 'FragmentDefinition') {

return fragmentDef as FragmentDefinition;
return fragmentDef as FragmentDefinitionNode;
}
export interface FragmentMap {
[fragmentName: string]: FragmentDefinition;
[fragmentName: string]: FragmentDefinitionNode;
}

@@ -117,3 +117,3 @@

// that maps the name of the fragment to the fragment definition.
export function createFragmentMap(fragments: FragmentDefinition[] = []): FragmentMap {
export function createFragmentMap(fragments: FragmentDefinitionNode[] = []): FragmentMap {
const symTable: FragmentMap = {};

@@ -129,4 +129,4 @@ fragments.forEach((fragment) => {

// document.
export function addFragmentsToDocument(queryDoc: Document,
fragments: FragmentDefinition[]): Document {
export function addFragmentsToDocument(queryDoc: DocumentNode,
fragments: FragmentDefinitionNode[]): DocumentNode {
checkDocument(queryDoc);

@@ -136,6 +136,6 @@ return {

definitions: queryDoc.definitions.concat(fragments),
} as Document;
} as DocumentNode;
}
export function getMainDefinition(queryDoc: Document): OperationDefinition | FragmentDefinition {
export function getMainDefinition(queryDoc: DocumentNode): OperationDefinitionNode | FragmentDefinitionNode {
checkDocument(queryDoc);

@@ -142,0 +142,0 @@

import {
Document,
SelectionSet,
Field,
FragmentDefinition,
InlineFragment,
DocumentNode,
SelectionSetNode,
FieldNode,
FragmentDefinitionNode,
InlineFragmentNode,
} from 'graphql';

@@ -76,3 +76,3 @@

resolver: Resolver,
document: Document,
document: DocumentNode,
rootValue?: any,

@@ -110,3 +110,3 @@ contextValue?: any,

function executeSelectionSet(
selectionSet: SelectionSet,
selectionSet: SelectionSetNode,
rootValue: any,

@@ -142,3 +142,3 @@ execContext: ExecContext

} else {
let fragment: InlineFragment | FragmentDefinition;
let fragment: InlineFragmentNode | FragmentDefinitionNode;

@@ -178,3 +178,3 @@ if (isInlineFragment(selection)) {

function executeField(
field: Field,
field: FieldNode,
rootValue: any,

@@ -181,0 +181,0 @@ execContext: ExecContext

import {
Field,
IntValue,
FloatValue,
StringValue,
BooleanValue,
ObjectValue,
ListValue,
EnumValue,
Variable,
InlineFragment,
Value,
Selection,
GraphQLResult,
Name,
FieldNode,
IntValueNode,
FloatValueNode,
StringValueNode,
BooleanValueNode,
ObjectValueNode,
ListValueNode,
EnumValueNode,
VariableNode,
InlineFragmentNode,
ValueNode,
SelectionNode,
ExecutionResult,
NameNode,
} from 'graphql';
type ScalarValue = StringValue | BooleanValue | EnumValue;
type ScalarValue = StringValueNode | BooleanValueNode | EnumValueNode;
function isScalarValue(value: Value): value is ScalarValue {
function isScalarValue(value: ValueNode): value is ScalarValue {
const SCALAR_TYPES = {

@@ -30,5 +30,5 @@ StringValue: 1,

type NumberValue = IntValue | FloatValue;
type NumberValue = IntValueNode | FloatValueNode;
function isNumberValue(value: Value): value is NumberValue {
function isNumberValue(value: ValueNode): value is NumberValue {
const NUMBER_TYPES = {

@@ -42,15 +42,15 @@ IntValue: 1,

function isVariable(value: Value): value is Variable {
function isVariable(value: ValueNode): value is VariableNode {
return value.kind === 'Variable';
}
function isObject(value: Value): value is ObjectValue {
function isObject(value: ValueNode): value is ObjectValueNode {
return value.kind === 'ObjectValue';
}
function isList(value: Value): value is ListValue {
function isList(value: ValueNode): value is ListValueNode {
return value.kind === 'ListValue';
}
function valueToObjectRepresentation(argObj: any, name: Name, value: Value, variables?: Object) {
function valueToObjectRepresentation(argObj: any, name: NameNode, value: ValueNode, variables?: Object) {
if (isNumberValue(value)) {

@@ -84,3 +84,3 @@ argObj[name.value] = Number(value.value);

export function argumentsObjectFromField(field: Field, variables: Object): Object {
export function argumentsObjectFromField(field: FieldNode, variables: Object): Object {
if (field.arguments && field.arguments.length) {

@@ -96,3 +96,3 @@ const argObj: Object = {};

export function resultKeyNameFromField(field: Field): string {
export function resultKeyNameFromField(field: FieldNode): string {
return field.alias ?

@@ -103,12 +103,12 @@ field.alias.value :

export function isField(selection: Selection): selection is Field {
export function isField(selection: SelectionNode): selection is FieldNode {
return selection.kind === 'Field';
}
export function isInlineFragment(selection: Selection): selection is InlineFragment {
export function isInlineFragment(selection: SelectionNode): selection is InlineFragmentNode {
return selection.kind === 'InlineFragment';
}
export function graphQLResultHasError(result: GraphQLResult) {
export function graphQLResultHasError(result: ExecutionResult) {
return result.errors && result.errors.length;
}
import {
Document,
DocumentNode,
} from 'graphql';

@@ -7,3 +7,3 @@

export function filter(doc: Document, data: any): any {
export function filter(doc: DocumentNode, data: any): any {
const resolver = (

@@ -26,3 +26,3 @@ fieldName: string,

// are using this like that, but in the future, who knows?
export function check(doc: Document, data: any): void {
export function check(doc: DocumentNode, data: any): void {
const resolver = (

@@ -29,0 +29,0 @@ fieldName: string,

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

/// <reference types="typed-graphql" />
/// <reference types="mocha" />

@@ -10,3 +9,3 @@

declare module 'graphql-tag/parser' {
import { Source, ParseOptions, Document } from 'graphql';
import { Source, ParseOptions, DocumentNode } from 'graphql';
// XXX figure out how to directly export this method

@@ -16,3 +15,3 @@ function parse(

options?: ParseOptions
): Document;
): DocumentNode;
}

@@ -19,0 +18,0 @@

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