graphql-genie
Advanced tools
Comparing version 0.2.19 to 0.2.20
@@ -0,3 +1,18 @@ | ||
import { GraphQLError } from 'graphql'; | ||
export declare const typeIsList: (type: any) => boolean; | ||
export declare const getReturnType: (type: any) => string; | ||
export declare class FindByUniqueError extends Error implements GraphQLError { | ||
extensions: Record<string, any>; | ||
readonly name: any; | ||
readonly locations: any; | ||
readonly path: any; | ||
readonly source: any; | ||
readonly positions: any; | ||
readonly nodes: any; | ||
readonly arg: any; | ||
readonly typename: any; | ||
originalError: any; | ||
[key: string]: any; | ||
constructor(message: string, code?: string, properties?: Record<string, any>); | ||
} | ||
//# sourceMappingURL=GraphQLUtils.d.ts.map |
@@ -24,1 +24,18 @@ import { isListType, isNonNullType } from 'graphql'; | ||
}; | ||
export class FindByUniqueError extends Error { | ||
constructor(message, code, properties) { | ||
super(message); | ||
if (properties) { | ||
Object.keys(properties).forEach(key => { | ||
this[key] = properties[key]; | ||
}); | ||
} | ||
// if no name provided, use the default. defineProperty ensures that it stays non-enumerable | ||
if (!this.name) { | ||
Object.defineProperty(this, 'name', { value: 'ApolloError' }); | ||
} | ||
// extensions are flattened to be included in the root of GraphQLError's, so | ||
// don't add properties to extensions | ||
this.extensions = { code }; | ||
} | ||
} |
@@ -9,6 +9,6 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { GraphQLError, GraphQLList, defaultFieldResolver, getNamedType, isEnumType, isInterfaceType, isObjectType, isScalarType, isUnionType } from 'graphql'; | ||
import { GraphQLList, defaultFieldResolver, getNamedType, isEnumType, isInterfaceType, isObjectType, isScalarType, isUnionType } from 'graphql'; | ||
import { difference, each, eq, find, get, isArray, isEmpty, isObject, keys, map, set, union } from 'lodash'; | ||
import pluralize from 'pluralize'; | ||
import { getReturnType, typeIsList } from './GraphQLUtils'; | ||
import { FindByUniqueError, getReturnType, typeIsList } from './GraphQLUtils'; | ||
export class Relation { | ||
@@ -229,6 +229,6 @@ constructor($type, $field, $field0isList) { | ||
const argTypeName = pluralize.singular(argKey).toLowerCase(); | ||
const matchingType = find(_info.schema.getTypeMap(), type => { | ||
argReturnRootType = find(_info.schema.getTypeMap(), type => { | ||
return type.name.toLowerCase() === argTypeName; | ||
}); | ||
promises.push(mutateResolver(mutation, dataResolver)(currRecord, arg[argKey], _context, _info, index, argName, matchingType)); | ||
promises.push(mutateResolver(mutation, dataResolver)(currRecord, arg[argKey], _context, _info, index, argName, argReturnRootType)); | ||
} | ||
@@ -287,3 +287,3 @@ } | ||
if (!currRecord || isEmpty(currRecord)) { | ||
throw new Error(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`); | ||
throw new FindByUniqueError(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`, 'update', { arg: whereArgs, typename: returnTypeName }); | ||
} | ||
@@ -410,3 +410,3 @@ } | ||
else { | ||
reject(new Error('tried to connect using unique value that does not exist ' + JSON.stringify(connectArg))); | ||
reject(new FindByUniqueError('tried to connect using unique value that does not exist ', 'connect', { arg: connectArg, typename: returnTypeName })); | ||
} | ||
@@ -437,3 +437,3 @@ }).catch(reason => { | ||
else { | ||
reject(); | ||
reject(new FindByUniqueError('tried to disconnect using unique value that does not exist ', 'disconnect', { arg: disconnectArg, typename: returnTypeName })); | ||
} | ||
@@ -473,3 +473,3 @@ }).catch(reason => { | ||
if (!currRecord || isEmpty(currRecord)) { | ||
throw new GraphQLError(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`); | ||
throw new FindByUniqueError(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`, 'delete', { arg: whereArgs, typename: returnTypeName }); | ||
} | ||
@@ -488,3 +488,4 @@ dataResolver.delete(currRecord.__typename, [currRecord.id], { context: _context, info: _info }).then(() => { | ||
deletePromises.push(new Promise((resolve, reject) => { | ||
dataResolver.getValueByUnique(dataResolver.getLink(currRecord.__typename, key), deleteArg, { context: _context, info: _info }).then(data => { | ||
const deleteTypeName = dataResolver.getLink(currRecord.__typename, key); | ||
dataResolver.getValueByUnique(deleteTypeName, deleteArg, { context: _context, info: _info }).then(data => { | ||
if (data && data['id']) { | ||
@@ -494,3 +495,3 @@ resolve(data['id']); | ||
else { | ||
reject(); | ||
reject(new FindByUniqueError(`${deleteTypeName} does not exist with where args ${JSON.stringify(deleteArg)}`, 'delete', { arg: deleteArg, typename: deleteTypeName })); | ||
} | ||
@@ -497,0 +498,0 @@ }).catch(reason => { |
{ | ||
"name": "graphql-genie", | ||
"version": "0.2.19", | ||
"version": "0.2.20", | ||
"description": "GraphQL Genie", | ||
@@ -5,0 +5,0 @@ "browser": "./lib/browser.umd.js", |
@@ -92,3 +92,3 @@ <h1 align="center"> | ||
See the [yoga redis example](https://github.com/genie-team/graphql-genie/tree/master/examples/graphql-yoga-redis-authentication) for session authentication with users stored in the database. Would be simple to adapt to returning a JWT on login as well. | ||
See the [yoga redis example](https://github.com/genie-team/graphql-genie/tree/master/examples/graphql-yoga-redis-authentication) for session authentication with users stored in the database. | ||
@@ -95,0 +95,0 @@ See the [yoga redis firebase example](https://github.com/genie-team/graphql-genie/tree/master/examples/graphql-yoga-redis-firebase-auth) for using firebase authentication to login and control access from an external JWT provider. |
@@ -1,2 +0,2 @@ | ||
import { isListType, isNonNullType } from 'graphql'; | ||
import { GraphQLError, isListType, isNonNullType } from 'graphql'; | ||
@@ -25,1 +25,39 @@ export const typeIsList = (type) => { | ||
}; | ||
export class FindByUniqueError extends Error implements GraphQLError { | ||
public extensions: Record<string, any>; | ||
readonly name; | ||
readonly locations; | ||
readonly path; | ||
readonly source; | ||
readonly positions; | ||
readonly nodes; | ||
readonly arg; | ||
readonly typename; | ||
public originalError; | ||
[key: string]: any; | ||
constructor( | ||
message: string, | ||
code?: string, | ||
properties?: Record<string, any>, | ||
) { | ||
super(message); | ||
if (properties) { | ||
Object.keys(properties).forEach(key => { | ||
this[key] = properties[key]; | ||
}); | ||
} | ||
// if no name provided, use the default. defineProperty ensures that it stays non-enumerable | ||
if (!this.name) { | ||
Object.defineProperty(this, 'name', { value: 'ApolloError' }); | ||
} | ||
// extensions are flattened to be included in the root of GraphQLError's, so | ||
// don't add properties to extensions | ||
this.extensions = { code }; | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
import { GraphQLArgument, GraphQLError, GraphQLInputObjectType, GraphQLList, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema, GraphQLType, IntrospectionObjectType, IntrospectionType, defaultFieldResolver, getNamedType, isEnumType, isInterfaceType, isObjectType, isScalarType, isUnionType } from 'graphql'; | ||
import { GraphQLArgument, GraphQLInputObjectType, GraphQLList, GraphQLNamedType, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo, GraphQLSchema, GraphQLType, IntrospectionObjectType, IntrospectionType, defaultFieldResolver, getNamedType, isEnumType, isInterfaceType, isObjectType, isScalarType, isUnionType } from 'graphql'; | ||
import { difference, each, eq, find, get, isArray, isEmpty, isObject, keys, map, set, union } from 'lodash'; | ||
import pluralize from 'pluralize'; | ||
import { Connection, DataResolver } from './GraphQLGenieInterfaces'; | ||
import { getReturnType, typeIsList } from './GraphQLUtils'; | ||
import { FindByUniqueError, getReturnType, typeIsList } from './GraphQLUtils'; | ||
export class Relation { | ||
@@ -247,6 +247,6 @@ public type0: string; | ||
const argTypeName = pluralize.singular(argKey).toLowerCase(); | ||
const matchingType = <GraphQLOutputType> find(_info.schema.getTypeMap(), type => { | ||
argReturnRootType = <GraphQLOutputType> find(_info.schema.getTypeMap(), type => { | ||
return type.name.toLowerCase() === argTypeName; | ||
}); | ||
promises.push(mutateResolver(mutation, dataResolver)(currRecord, arg[argKey], _context, _info, index, argName, matchingType)); | ||
promises.push(mutateResolver(mutation, dataResolver)(currRecord, arg[argKey], _context, _info, index, argName, argReturnRootType)); | ||
@@ -321,3 +321,3 @@ } | ||
if (!currRecord || isEmpty(currRecord)) { | ||
throw new Error(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`); | ||
throw new FindByUniqueError(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`, 'update', {arg: whereArgs, typename: returnTypeName}); | ||
} | ||
@@ -446,3 +446,3 @@ } | ||
} else { | ||
reject(new Error('tried to connect using unique value that does not exist ' + JSON.stringify(connectArg))); | ||
reject(new FindByUniqueError('tried to connect using unique value that does not exist ', 'connect', {arg: connectArg, typename: returnTypeName})); | ||
} | ||
@@ -472,3 +472,3 @@ }).catch(reason => { | ||
} else { | ||
reject(); | ||
reject(new FindByUniqueError('tried to disconnect using unique value that does not exist ', 'disconnect', {arg: disconnectArg, typename: returnTypeName})); | ||
} | ||
@@ -510,3 +510,3 @@ }).catch(reason => { | ||
if (!currRecord || isEmpty(currRecord)) { | ||
throw new GraphQLError(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`); | ||
throw new FindByUniqueError(`${returnTypeName} does not exist with where args ${JSON.stringify(whereArgs)}`, 'delete', {arg: whereArgs, typename: returnTypeName}); | ||
} | ||
@@ -524,7 +524,8 @@ dataResolver.delete(currRecord.__typename, [currRecord.id], {context: _context, info: _info}).then(() => { | ||
deletePromises.push(new Promise((resolve, reject) => { | ||
dataResolver.getValueByUnique(dataResolver.getLink(currRecord.__typename, key), deleteArg, {context: _context, info: _info}).then(data => { | ||
const deleteTypeName = dataResolver.getLink(currRecord.__typename, key); | ||
dataResolver.getValueByUnique(deleteTypeName, deleteArg, {context: _context, info: _info}).then(data => { | ||
if (data && data['id']) { | ||
resolve(data['id']); | ||
} else { | ||
reject(); | ||
reject(new FindByUniqueError(`${deleteTypeName} does not exist with where args ${JSON.stringify(deleteArg)}`, 'delete', {arg: deleteArg, typename: deleteTypeName})); | ||
} | ||
@@ -531,0 +532,0 @@ }).catch(reason => { |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
977565
21814