graphql-anywhere
Advanced tools
Comparing version 1.0.0 to 1.1.0
# Change log | ||
### v1.1.0 | ||
Remove lodash, meaning this package now has zero direct dependencies (although you still need something that will provide a parsed GraphQL query to use it). | ||
### v1.0.0 | ||
@@ -4,0 +8,0 @@ |
@@ -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; |
"use strict"; | ||
var assign = require('lodash.assign'); | ||
var countBy = require('lodash.countby'); | ||
var identity = require('lodash.identity'); | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
function getMutationDefinition(doc) { | ||
@@ -24,7 +29,6 @@ checkDocument(doc); | ||
} | ||
var definitionTypes = doc.definitions.map(function (definition) { | ||
return definition.kind; | ||
}); | ||
var typeCounts = countBy(definitionTypes, identity); | ||
if (typeCounts['OperationDefinition'] > 1) { | ||
var numOpDefinitions = doc.definitions.filter(function (definition) { | ||
return definition.kind === 'OperationDefinition'; | ||
}).length; | ||
if (numOpDefinitions > 1) { | ||
throw new Error('Queries must have exactly one operation definition.'); | ||
@@ -97,5 +101,3 @@ } | ||
checkDocument(queryDoc); | ||
return assign({}, queryDoc, { | ||
definitions: queryDoc.definitions.concat(fragments), | ||
}); | ||
return __assign({}, queryDoc, { definitions: queryDoc.definitions.concat(fragments) }); | ||
} | ||
@@ -102,0 +104,0 @@ exports.addFragmentsToDocument = addFragmentsToDocument; |
@@ -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; |
"use strict"; | ||
var getFromAST_1 = require('./getFromAST'); | ||
var directives_1 = require('./directives'); | ||
var storeUtils_1 = require('./storeUtils'); | ||
var utilities_1 = require('./utilities'); | ||
var getFromAST_1 = require("./getFromAST"); | ||
var directives_1 = require("./directives"); | ||
var storeUtils_1 = require("./storeUtils"); | ||
var utilities_1 = require("./utilities"); | ||
exports.filter = utilities_1.filter; | ||
exports.check = utilities_1.check; | ||
exports.propType = utilities_1.propType; | ||
var isNull = require('lodash.isnull'); | ||
var isUndefined = require('lodash.isundefined'); | ||
var merge = require('lodash.merge'); | ||
function graphql(resolver, document, rootValue, contextValue, variableValues, execOptions) { | ||
@@ -80,3 +77,3 @@ if (execOptions === void 0) { execOptions = {}; } | ||
} | ||
if (isNull(result) || isUndefined(result)) { | ||
if (result === null || typeof result === 'undefined') { | ||
return result; | ||
@@ -91,3 +88,3 @@ } | ||
return result.map(function (item) { | ||
if (isNull(item)) { | ||
if (item === null) { | ||
return null; | ||
@@ -101,2 +98,22 @@ } | ||
} | ||
function merge(dest, src) { | ||
if (src === null || | ||
typeof src === 'undefined' || | ||
typeof src === 'string' || | ||
typeof src === 'number' || | ||
typeof src === 'boolean' || | ||
Array.isArray(src)) { | ||
return src; | ||
} | ||
Object.keys(dest).forEach(function (destKey) { | ||
if (src.hasOwnProperty(destKey)) { | ||
merge(dest[destKey], src[destKey]); | ||
} | ||
}); | ||
Object.keys(src).forEach(function (srcKey) { | ||
if (!dest.hasOwnProperty(srcKey)) { | ||
dest[srcKey] = src[srcKey]; | ||
} | ||
}); | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -1,8 +0,7 @@ | ||
/// <reference types="typed-graphql" /> | ||
/// <reference types="chai" /> | ||
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; |
"use strict"; | ||
var includes = require('lodash.includes'); | ||
function isScalarValue(value) { | ||
var SCALAR_TYPES = ['StringValue', 'BooleanValue', 'EnumValue']; | ||
return includes(SCALAR_TYPES, value.kind); | ||
var SCALAR_TYPES = { | ||
StringValue: 1, | ||
BooleanValue: 1, | ||
EnumValue: 1, | ||
}; | ||
return !!SCALAR_TYPES[value.kind]; | ||
} | ||
function isNumberValue(value) { | ||
var NUMBER_TYPES = ['IntValue', 'FloatValue']; | ||
return includes(NUMBER_TYPES, value.kind); | ||
var NUMBER_TYPES = { | ||
IntValue: 1, | ||
FloatValue: 1, | ||
}; | ||
return NUMBER_TYPES[value.kind]; | ||
} | ||
@@ -11,0 +17,0 @@ function isVariable(value) { |
@@ -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; |
"use strict"; | ||
var index_1 = require('./index'); | ||
var index_1 = require("./index"); | ||
function filter(doc, data) { | ||
@@ -41,6 +41,6 @@ var resolver = function (fieldName, root, args, context, info) { | ||
if (props[propName] === null) { | ||
return new PropTypeError(("The " + locationName + " `" + propFullName + "` is marked as required ") + | ||
return new PropTypeError("The " + locationName + " `" + propFullName + "` is marked as required " + | ||
("in `" + componentName + "`, but its value is `null`.")); | ||
} | ||
return new PropTypeError(("The " + locationName + " `" + propFullName + "` is marked as required in ") + | ||
return new PropTypeError("The " + locationName + " `" + propFullName + "` is marked as required in " + | ||
("`" + componentName + "`, but its value is `undefined`.")); | ||
@@ -47,0 +47,0 @@ } |
{ | ||
"name": "graphql-anywhere", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Run GraphQL queries with no schema and just one resolver", | ||
@@ -34,21 +34,2 @@ "main": "./lib/src/index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"lodash.assign": "^4.0.8", | ||
"lodash.clonedeep": "^4.3.2", | ||
"lodash.countby": "^4.4.0", | ||
"lodash.flatten": "^4.2.0", | ||
"lodash.forown": "^4.1.0", | ||
"lodash.has": "^4.3.1", | ||
"lodash.identity": "^3.0.0", | ||
"lodash.includes": "^4.1.2", | ||
"lodash.isequal": "^4.2.0", | ||
"lodash.isnull": "^3.0.0", | ||
"lodash.isnumber": "^3.0.3", | ||
"lodash.isobject": "^3.0.2", | ||
"lodash.isstring": "^4.0.1", | ||
"lodash.isundefined": "^3.0.1", | ||
"lodash.mapvalues": "^4.4.0", | ||
"lodash.merge": "^4.6.0", | ||
"lodash.pick": "^4.2.0" | ||
}, | ||
"devDependencies": { | ||
@@ -62,2 +43,3 @@ "@types/chai": "^3.4.34", | ||
"@types/react-dom": "^0.14.18", | ||
"@types/graphql": "^0.8.0", | ||
"async": "^2.0.0", | ||
@@ -72,5 +54,2 @@ "chai": "^3.5.0", | ||
"istanbul": "^0.4.5", | ||
"lodash": "^4.6.1", | ||
"lodash.mapvalues": "^4.3.0", | ||
"lodash.omit": "^4.2.1", | ||
"mocha": "^3.0.0", | ||
@@ -82,5 +61,4 @@ "react": "^15.3.1", | ||
"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: foo: 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'; | ||
import assign = require('lodash.assign'); | ||
import countBy = require('lodash.countby'); | ||
import identity = require('lodash.identity'); | ||
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; | ||
} | ||
@@ -30,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') { | ||
@@ -37,9 +33,8 @@ throw new Error(`Expecting a parsed GraphQL document. Perhaps you need to wrap the query \ | ||
const definitionTypes = doc.definitions.map((definition) => { | ||
return definition.kind; | ||
}); | ||
const typeCounts = countBy(definitionTypes, identity); | ||
const numOpDefinitions = doc.definitions.filter((definition) => { | ||
return definition.kind === 'OperationDefinition'; | ||
}).length; | ||
// can't have more than one operation definition per query | ||
if (typeCounts['OperationDefinition'] > 1) { | ||
if (numOpDefinitions > 1) { | ||
throw new Error('Queries must have exactly one operation definition.'); | ||
@@ -49,8 +44,8 @@ } | ||
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; | ||
} | ||
@@ -62,4 +57,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') { | ||
@@ -70,3 +65,3 @@ return true; | ||
} | ||
}) as FragmentDefinition[]; | ||
}) as FragmentDefinitionNode[]; | ||
@@ -76,10 +71,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; | ||
} | ||
@@ -95,3 +90,3 @@ }); | ||
export function getFragmentDefinition(doc: Document): FragmentDefinition { | ||
export function getFragmentDefinition(doc: DocumentNode): FragmentDefinitionNode { | ||
if (doc.kind !== 'Document') { | ||
@@ -106,3 +101,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; | ||
@@ -113,7 +108,7 @@ if (fragmentDef.kind !== 'FragmentDefinition') { | ||
return fragmentDef as FragmentDefinition; | ||
return fragmentDef as FragmentDefinitionNode; | ||
} | ||
export interface FragmentMap { | ||
[fragmentName: string]: FragmentDefinition; | ||
[fragmentName: string]: FragmentDefinitionNode; | ||
} | ||
@@ -123,3 +118,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 = {}; | ||
@@ -135,11 +130,12 @@ fragments.forEach((fragment) => { | ||
// document. | ||
export function addFragmentsToDocument(queryDoc: Document, | ||
fragments: FragmentDefinition[]): Document { | ||
export function addFragmentsToDocument(queryDoc: DocumentNode, | ||
fragments: FragmentDefinitionNode[]): DocumentNode { | ||
checkDocument(queryDoc); | ||
return assign({}, queryDoc, { | ||
return { | ||
...queryDoc, | ||
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); | ||
@@ -146,0 +142,0 @@ |
import { | ||
Document, | ||
SelectionSet, | ||
Field, | ||
FragmentDefinition, | ||
InlineFragment, | ||
DocumentNode, | ||
SelectionSetNode, | ||
FieldNode, | ||
FragmentDefinitionNode, | ||
InlineFragmentNode, | ||
} from 'graphql'; | ||
@@ -33,6 +33,2 @@ | ||
import isNull = require('lodash.isnull'); | ||
import isUndefined = require('lodash.isundefined'); | ||
import merge = require('lodash.merge'); | ||
export type Resolver = ( | ||
@@ -81,3 +77,3 @@ fieldName: string, | ||
resolver: Resolver, | ||
document: Document, | ||
document: DocumentNode, | ||
rootValue?: any, | ||
@@ -115,3 +111,3 @@ contextValue?: any, | ||
function executeSelectionSet( | ||
selectionSet: SelectionSet, | ||
selectionSet: SelectionSetNode, | ||
rootValue: any, | ||
@@ -147,3 +143,3 @@ execContext: ExecContext | ||
} else { | ||
let fragment: InlineFragment | FragmentDefinition; | ||
let fragment: InlineFragmentNode | FragmentDefinitionNode; | ||
@@ -183,3 +179,3 @@ if (isInlineFragment(selection)) { | ||
function executeField( | ||
field: Field, | ||
field: FieldNode, | ||
rootValue: any, | ||
@@ -211,3 +207,3 @@ execContext: ExecContext | ||
// query a GraphQLObjectType | ||
if (isNull(result) || isUndefined(result)) { | ||
if (result === null || typeof result === 'undefined') { | ||
// Basically any field in a GraphQL response can be null, or missing | ||
@@ -236,3 +232,3 @@ return result; | ||
// null value in array | ||
if (isNull(item)) { | ||
if (item === null) { | ||
return null; | ||
@@ -254,1 +250,29 @@ } | ||
} | ||
function merge(dest, src) { | ||
if ( | ||
src === null || | ||
typeof src === 'undefined' || | ||
typeof src === 'string' || | ||
typeof src === 'number' || | ||
typeof src === 'boolean' || | ||
Array.isArray(src) | ||
) { | ||
// These types just override whatever was in dest | ||
return src; | ||
} | ||
// Merge sub-objects | ||
Object.keys(dest).forEach((destKey) => { | ||
if (src.hasOwnProperty(destKey)) { | ||
merge(dest[destKey], src[destKey]); | ||
} | ||
}); | ||
// Add props only on src | ||
Object.keys(src).forEach((srcKey) => { | ||
if (! dest.hasOwnProperty(srcKey)) { | ||
dest[srcKey] = src[srcKey]; | ||
} | ||
}); | ||
} |
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'; | ||
import includes = require('lodash.includes'); | ||
type ScalarValue = StringValueNode | BooleanValueNode | EnumValueNode; | ||
type ScalarValue = StringValue | BooleanValue | EnumValue; | ||
function isScalarValue(value: ValueNode): value is ScalarValue { | ||
const SCALAR_TYPES = { | ||
StringValue: 1, | ||
BooleanValue: 1, | ||
EnumValue: 1, | ||
}; | ||
function isScalarValue(value: Value): value is ScalarValue { | ||
const SCALAR_TYPES = ['StringValue', 'BooleanValue', 'EnumValue']; | ||
return includes(SCALAR_TYPES, value.kind); | ||
return !! SCALAR_TYPES[value.kind]; | ||
} | ||
type NumberValue = IntValue | FloatValue; | ||
type NumberValue = IntValueNode | FloatValueNode; | ||
function isNumberValue(value: Value): value is NumberValue { | ||
const NUMBER_TYPES = ['IntValue', 'FloatValue']; | ||
return includes(NUMBER_TYPES, value.kind); | ||
function isNumberValue(value: ValueNode): value is NumberValue { | ||
const NUMBER_TYPES = { | ||
IntValue: 1, | ||
FloatValue: 1, | ||
}; | ||
return NUMBER_TYPES[value.kind]; | ||
} | ||
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)) { | ||
@@ -75,3 +82,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) { | ||
@@ -87,3 +94,3 @@ const argObj: Object = {}; | ||
export function resultKeyNameFromField(field: Field): string { | ||
export function resultKeyNameFromField(field: FieldNode): string { | ||
return field.alias ? | ||
@@ -94,12 +101,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, |
105
typings.d.ts
@@ -1,2 +0,1 @@ | ||
/// <reference types="typed-graphql" /> | ||
/// <reference types="mocha" /> | ||
@@ -6,102 +5,2 @@ | ||
LODASH | ||
*/ | ||
declare module 'lodash.isobject' { | ||
import main = require('lodash'); | ||
export = main.isObject; | ||
} | ||
declare module 'lodash.isequal' { | ||
import main = require('lodash'); | ||
export = main.isEqual; | ||
} | ||
declare module 'lodash.isnull' { | ||
import main = require('lodash'); | ||
export = main.isNull; | ||
} | ||
declare module 'lodash.isstring' { | ||
import main = require('lodash'); | ||
export = main.isString; | ||
} | ||
declare module 'lodash.has' { | ||
import main = require('lodash'); | ||
export = main.has; | ||
} | ||
declare module 'lodash.assign' { | ||
import main = require('lodash'); | ||
export = main.assign; | ||
} | ||
declare module 'lodash.merge' { | ||
import main = require('lodash'); | ||
export = main.merge; | ||
} | ||
declare module 'lodash.includes' { | ||
import main = require('lodash'); | ||
export = main.includes; | ||
} | ||
declare module 'lodash.isnumber' { | ||
import main = require('lodash'); | ||
export = main.isNumber; | ||
} | ||
declare module 'lodash.isboolean' { | ||
import main = require('lodash'); | ||
export = main.isBoolean; | ||
} | ||
declare module 'lodash.isundefined' { | ||
import main = require('lodash'); | ||
export = main.isUndefined; | ||
} | ||
declare module 'lodash.forown' { | ||
import main = require('lodash'); | ||
export = main.forOwn; | ||
} | ||
declare module 'lodash.omit' { | ||
import main = require('lodash'); | ||
export = main.omit; | ||
} | ||
declare module 'lodash.mapvalues' { | ||
import main = require('lodash'); | ||
export = main.mapValues; | ||
} | ||
declare module 'lodash.clonedeep' { | ||
import main = require('lodash'); | ||
export = main.cloneDeep; | ||
} | ||
declare module 'lodash.countby' { | ||
import main = require('lodash'); | ||
export = main.countBy; | ||
} | ||
declare module 'lodash.identity' { | ||
import main = require('lodash'); | ||
export = main.identity; | ||
} | ||
declare module 'lodash.flatten' { | ||
import main = require('lodash'); | ||
export = main.flatten; | ||
} | ||
declare module 'lodash.pick' { | ||
import main = require('lodash'); | ||
export = main.pick; | ||
} | ||
/* | ||
GRAPHQL | ||
@@ -111,3 +10,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 | ||
@@ -117,3 +16,3 @@ function parse( | ||
options?: ParseOptions | ||
): Document; | ||
): DocumentNode; | ||
} | ||
@@ -120,0 +19,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
24
337
65584
28
1137
- Removedlodash.assign@^4.0.8
- Removedlodash.clonedeep@^4.3.2
- Removedlodash.countby@^4.4.0
- Removedlodash.flatten@^4.2.0
- Removedlodash.forown@^4.1.0
- Removedlodash.has@^4.3.1
- Removedlodash.identity@^3.0.0
- Removedlodash.includes@^4.1.2
- Removedlodash.isequal@^4.2.0
- Removedlodash.isnull@^3.0.0
- Removedlodash.isnumber@^3.0.3
- Removedlodash.isobject@^3.0.2
- Removedlodash.isstring@^4.0.1
- Removedlodash.isundefined@^3.0.1
- Removedlodash.mapvalues@^4.4.0
- Removedlodash.merge@^4.6.0
- Removedlodash.pick@^4.2.0
- Removedlodash.assign@4.2.0(transitive)
- Removedlodash.clonedeep@4.5.0(transitive)
- Removedlodash.countby@4.6.0(transitive)
- Removedlodash.flatten@4.4.0(transitive)
- Removedlodash.forown@4.4.0(transitive)
- Removedlodash.has@4.5.2(transitive)
- Removedlodash.identity@3.0.0(transitive)
- Removedlodash.includes@4.3.0(transitive)
- Removedlodash.isequal@4.5.0(transitive)
- Removedlodash.isnull@3.0.0(transitive)
- Removedlodash.isnumber@3.0.3(transitive)
- Removedlodash.isobject@3.0.2(transitive)
- Removedlodash.isstring@4.0.1(transitive)
- Removedlodash.isundefined@3.0.1(transitive)
- Removedlodash.mapvalues@4.6.0(transitive)
- Removedlodash.merge@4.6.2(transitive)
- Removedlodash.pick@4.4.0(transitive)