Socket
Socket
Sign inDemoInstall

graphql-genie

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-genie - npm Package Compare versions

Comparing version 0.4.13 to 0.4.14

70

lib/GraphQLGenie.js

@@ -9,4 +9,4 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

};
import { GenerateUpdate } from './GenerateUpdate';
import { GraphQLObjectType, getNamedType, getNullableType, introspectionFromSchema, isEnumType, isListType, isObjectType, isScalarType, printType } from 'graphql';
import { GenerateUpsert } from './GenerateUpsert';
import FortuneGraph from './FortuneGraph';

@@ -18,3 +18,3 @@ import { GenerateConnections } from './GenerateConnections';

import { assign, forOwn, get, isArray, isEmpty, isFunction, isPlainObject, isString, set } from 'lodash';
import { GenerateUpdate } from './GenerateUpdate';
import { GenerateUpsert } from './GenerateUpsert';
import { GraphQLSchemaBuilder } from './GraphQLSchemaBuilder';

@@ -26,2 +26,3 @@ import { getReturnType } from './GraphQLUtils';

import { GenerateMigrations } from './GenerateMigrations';
import { isNumber } from 'util';
export class GraphQLGenie {

@@ -251,2 +252,28 @@ constructor(options) {

object.id = object.id || this.graphQLFortune.computeId(typeName);
// make sure we parse the values
const schemaType = this.schema.getType(typeName);
const fieldMap = schemaType.getFields();
const objectFields = Object.keys(object);
objectFields.forEach(fieldName => {
const schemaField = fieldMap[fieldName];
if (schemaField) {
const namedType = getNamedType(schemaField.type);
if (isScalarType(namedType)) {
let currVal = object[fieldName];
const scalarType = this.schema.getType(namedType.name);
if (isArray(currVal) && !isEmpty(currVal)) {
currVal = currVal.map((val) => {
if (val && isString(val)) {
val = scalarType.parseValue(val);
}
return val;
});
}
else if (isString(currVal)) {
currVal = scalarType.parseValue(currVal);
}
object[fieldName] = currVal;
}
}
});
return object;

@@ -443,3 +470,40 @@ });

types.forEach(typeName => {
promises.push(this.graphQLFortune.find(typeName, undefined, undefined, meta));
promises.push(new Promise((resolve, reject) => {
this.graphQLFortune.find(typeName, undefined, undefined, meta).then(fortuneData => {
// make sure we serialize the values
const schemaType = this.getSchema().getType(typeName);
const fieldMap = schemaType.getFields();
if (isEmpty(fortuneData)) {
resolve(fortuneData);
return;
}
fortuneData = fortuneData.map((record) => {
const objectFields = Object.keys(record);
objectFields.forEach(fieldName => {
const schemaField = fieldMap[fieldName];
if (schemaField) {
const namedType = getNamedType(schemaField.type);
let currVal = record[fieldName];
if (isScalarType(namedType)) {
const scalarType = this.getSchema().getType(namedType.name);
if (isArray(currVal)) {
currVal = currVal.map((val) => {
if (val && !isString(val) && !isNumber(val)) {
val = scalarType.serialize(val);
}
return val;
});
}
else if (currVal && !isString(currVal) && !isNumber(currVal)) {
currVal = scalarType.serialize(currVal);
}
record[fieldName] = currVal;
}
}
});
return record;
});
resolve(fortuneData);
}).catch(reason => { reject(reason); });
}));
});

@@ -446,0 +510,0 @@ const allData = yield Promise.all(promises);

2

package.json
{
"name": "graphql-genie",
"version": "0.4.13",
"version": "0.4.14",
"description": "GraphQL Genie",

@@ -5,0 +5,0 @@ "browser": "./lib/browser.umd.js",

@@ -42,3 +42,3 @@ import commonjs from 'rollup-plugin-commonjs';

namedExports: {
'node_modules/lodash/lodash.js': ['isFunction', 'toString', 'values', 'find', 'eq', 'difference', 'union', 'uniq', 'pick', 'isDate', 'startsWith', 'includes', 'omitBy', 'omit', 'set', 'has', 'isString', 'isEqual', 'findIndex', 'concat', 'forOwn', 'keyBy', 'assign', 'each', 'get', 'merge', 'pickBy', 'endsWith', 'isEmpty', 'isArray', 'isObject', 'map', 'keys', 'mapKeys', 'mapValues'],
'node_modules/lodash/lodash.js': ['isFunction', 'camelCase', 'values', 'find', 'eq', 'difference', 'union', 'uniq', 'pick', 'isDate', 'startsWith', 'includes', 'omitBy', 'omit', 'set', 'has', 'isString', 'isNumber', 'isEqual', 'findIndex', 'concat', 'forOwn', 'keyBy', 'assign', 'each', 'get', 'merge', 'pickBy', 'endsWith', 'isEmpty', 'isArray', 'isObject', 'map', 'keys', 'mapKeys', 'mapValues'],
'node_modules/graphql-tools/dist/index.js': [ 'SchemaDirectiveVisitor', 'makeExecutableSchema', 'addResolveFunctionsToSchema' ],

@@ -45,0 +45,0 @@ 'node_modules/graphql-type-json/lib/index.js': ['GraphQLJSON'],

@@ -36,3 +36,3 @@ import commonjs from 'rollup-plugin-commonjs';

namedExports: {
'node_modules/lodash/lodash.js': ['isFunction', 'camelCase', 'values', 'find', 'eq', 'difference', 'union', 'uniq', 'pick', 'isDate', 'startsWith', 'includes', 'omitBy', 'omit', 'set', 'has', 'isString', 'isEqual', 'findIndex', 'concat', 'forOwn', 'keyBy', 'assign', 'each', 'get', 'merge', 'pickBy', 'endsWith', 'isEmpty', 'isArray', 'isObject', 'map', 'keys', 'mapKeys', 'mapValues'],
'node_modules/lodash/lodash.js': ['isFunction', 'camelCase', 'values', 'find', 'eq', 'difference', 'union', 'uniq', 'pick', 'isDate', 'startsWith', 'includes', 'omitBy', 'omit', 'set', 'has', 'isString', 'isNumber', 'isEqual', 'findIndex', 'concat', 'forOwn', 'keyBy', 'assign', 'each', 'get', 'merge', 'pickBy', 'endsWith', 'isEmpty', 'isArray', 'isObject', 'map', 'keys', 'mapKeys', 'mapValues'],
'node_modules/graphql-tools/dist/index.js': [ 'SchemaDirectiveVisitor', 'makeExecutableSchema', 'addResolveFunctionsToSchema' ],

@@ -39,0 +39,0 @@ 'node_modules/graphql-type-json/lib/index.js': ['GraphQLJSON'],

import { GraphQLFieldResolver, GraphQLInputObjectType, GraphQLObjectType, GraphQLSchema, IntrospectionObjectType, IntrospectionQuery, IntrospectionType, getNamedType, getNullableType, introspectionFromSchema, isEnumType, isListType, isObjectType, isScalarType, printType } from 'graphql';
import { GenerateUpsert } from './GenerateUpsert';
import { GenerateUpdate } from './GenerateUpdate';
import { GraphQLFieldResolver, GraphQLInputObjectType, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, IntrospectionObjectType, IntrospectionQuery, IntrospectionType, getNamedType, getNullableType, introspectionFromSchema, isEnumType, isListType, isObjectType, isScalarType, printType } from 'graphql';
import FortuneGraph from './FortuneGraph';

@@ -10,3 +10,3 @@ import { GenerateConnections } from './GenerateConnections';

import { assign, forOwn, get, isArray, isEmpty, isFunction, isPlainObject, isString, set } from 'lodash';
import { GenerateUpdate } from './GenerateUpdate';
import { GenerateUpsert } from './GenerateUpsert';
import { DataResolver, FortuneOptions, GenerateConfig, GenericObject, GeniePlugin, GraphQLGenieOptions, TypeGenerator } from './GraphQLGenieInterfaces';

@@ -19,2 +19,3 @@ import { GraphQLSchemaBuilder } from './GraphQLSchemaBuilder';

import { GenerateMigrations } from './GenerateMigrations';
import { isNumber } from 'util';

@@ -306,2 +307,28 @@ export class GraphQLGenie {

object.id = object.id || this.graphQLFortune.computeId(typeName);
// make sure we parse the values
const schemaType = <GraphQLObjectType>this.schema.getType(typeName);
const fieldMap = schemaType.getFields();
const objectFields = Object.keys(object);
objectFields.forEach(fieldName => {
const schemaField = fieldMap[fieldName];
if (schemaField) {
const namedType = getNamedType(schemaField.type);
if (isScalarType(namedType)) {
let currVal = object[fieldName];
const scalarType = <GraphQLScalarType>this.schema.getType(namedType.name);
if (isArray(currVal) && !isEmpty(currVal)) {
currVal = currVal.map((val) => {
if (val && isString(val)) {
val = scalarType.parseValue(val);
}
return val;
});
} else if (isString(currVal)) {
currVal = scalarType.parseValue(currVal);
}
object[fieldName] = currVal;
}
}
});
return object;

@@ -453,3 +480,3 @@ });

} else {
update[fieldName] = isListType(getNullableType(schemaField.type)) ? {set: currValue} : currValue;
update[fieldName] = isListType(getNullableType(schemaField.type)) ? { set: currValue } : currValue;
}

@@ -506,3 +533,41 @@ }

types.forEach(typeName => {
promises.push(this.graphQLFortune.find(typeName, undefined, undefined, meta));
promises.push(
new Promise((resolve, reject) => {
this.graphQLFortune.find(typeName, undefined, undefined, meta).then(fortuneData => {
// make sure we serialize the values
const schemaType = <GraphQLObjectType>this.getSchema().getType(typeName);
const fieldMap = schemaType.getFields();
if (isEmpty(fortuneData)) {
resolve(fortuneData);
return;
}
fortuneData = fortuneData.map((record) => {
const objectFields = Object.keys(record);
objectFields.forEach(fieldName => {
const schemaField = fieldMap[fieldName];
if (schemaField) {
const namedType = getNamedType(schemaField.type);
let currVal = record[fieldName];
if (isScalarType(namedType)) {
const scalarType = <GraphQLScalarType>this.getSchema().getType(namedType.name);
if (isArray(currVal)) {
currVal = currVal.map((val) => {
if (val && !isString(val) && !isNumber(val)) {
val = scalarType.serialize(val);
}
return val;
});
} else if (currVal && !isString(currVal) && !isNumber(currVal)) {
currVal = scalarType.serialize(currVal);
}
record[fieldName] = currVal;
}
}
});
return record;
});
resolve(fortuneData);
}).catch(reason => { reject(reason); });
})
);
});

@@ -509,0 +574,0 @@ const allData = await Promise.all(promises);

import { ApolloClient } from 'apollo-client';
import gql from 'graphql-tag';
import { genie, getClient } from '../setupTests';
import { GraphQLScalarType } from '../../../plugins/genie-persistence/node_modules/@types/graphql';
let client: ApolloClient<any>;

@@ -1096,2 +1097,44 @@ beforeAll(async () => {

test('genie - export query and import mutation with date', async () => {
const exportData = gql`
{
exportData(types: ["Comment"])
}
`;
let result: any = await client.query({
query: exportData
});
expect(result.data['exportData']).not.toBeNull();
const dataCopy = JSON.parse(JSON.stringify(result.data['exportData']));
const date = new Date();
dataCopy[0]['text'] = 'Import Data';
dataCopy[0]['updated'] = date;
const dataString = JSON.stringify(dataCopy).replace(/\"([^(\")"]+)\":/g, '$1:'); // This will remove all the quotes around props
const importData = gql`
mutation {
importData(data: ${dataString}, merge: true) {
data
unalteredData
missingData
}
}
`;
result = await client.mutate({
mutation: importData
});
expect(result.data['importData'].data.length).toBeGreaterThan(0);
client.cache['data'].data = {};
result = await client.query({
query: exportData
});
expect(result.data['exportData']).not.toBeNull();
expect(result.data['exportData'][0]['text']).toBe('Import Data');
const dateScalar = <GraphQLScalarType>genie.getSchema().getType('DateTime');
expect(result.data['exportData'][0]['updated']).toEqual(dateScalar.serialize(date));
});
test('genie - disconnect', async () => {

@@ -1098,0 +1141,0 @@ const disconReturn = await genie.disconnect();

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

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