temporary including json object type directly in the code (TOFIX)

This commit is contained in:
nikolabjelo committed 2019-06-02 19:07:04 +02:00
1 parent 9989c11914
commit a8c13139e1
5 files changed
+85 -8

No files matched your search

-5
View File
@@ -3587,11 +3587,6 @@
"uuid": "^3.1.0"
}
},
"graphql-type-json": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/graphql-type-json/-/graphql-type-json-0.3.0.tgz",
"integrity": "sha512-lnxg5HiB95yxy+/5cDKtP6pZo0zgntsOmqsjeCBXFGJ4YoMF3+1YaSEKWJntNTu+VsAm3zf6lPxFpp1kxzofLA=="
},
"graphql-upload": {
"version": "8.0.6",
"resolved": "https://registry.npmjs.org/graphql-upload/-/graphql-upload-8.0.6.tgz",
-1
View File
@@ -34,7 +34,6 @@
"dotenv": "^6.0.0",
"express": "^4.16.3",
"graphql": "^0.13.2",
"graphql-type-json": "^0.3.0",
"mongoose": "^5.3.4"
}
}
+83
View File
@@ -0,0 +1,83 @@
/* eslint-disable no-void */
exports.__esModule = true;
exports.GraphQLJSONObject = void 0;
exports.default = void 0;
exports.GraphQLJSON = void 0;
const _graphql = require('graphql');
const _language = require('graphql/language');
function identity(value) {
return value;
}
function ensureObject(value) {
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
throw new TypeError(`JSONObject cannot represent non-object value: ${value}`);
}
return value;
}
function parseObject(ast, variables) {
const value = Object.create(null);
ast.fields.forEach((field) => {
// eslint-disable-next-line no-use-before-define
value[field.name.value] = parseLiteral(field.value, variables);
});
return value;
}
function parseLiteral(ast, variables) {
switch (ast.kind) {
case _language.Kind.STRING:
case _language.Kind.BOOLEAN:
return ast.value;
case _language.Kind.INT:
case _language.Kind.FLOAT:
return parseFloat(ast.value);
case _language.Kind.OBJECT:
return parseObject(ast, variables);
case _language.Kind.LIST:
return ast.values.map(n => parseLiteral(n, variables));
case _language.Kind.NULL:
return null;
case _language.Kind.VARIABLE:
{
const name = ast.name.value;
return variables ? variables[name] : undefined;
}
default:
return undefined;
}
} // This named export is intended for users of CommonJS. Users of ES modules
// should instead use the default export.
const GraphQLJSON = new _graphql.GraphQLScalarType({
name: 'JSON',
description: 'The `JSON` scalar type represents JSON values as specified by'
+ ' [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',
serialize: identity,
parseValue: identity,
parseLiteral,
});
exports.GraphQLJSON = GraphQLJSON;
const _default = GraphQLJSON;
exports.default = _default;
const GraphQLJSONObject = new _graphql.GraphQLScalarType({
name: 'JSONObject',
description: 'The `JSONObject` scalar type represents JSON objects as specified by'
+ ' [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).',
serialize: ensureObject,
parseValue: ensureObject,
parseLiteral: parseObject,
});
exports.GraphQLJSONObject = GraphQLJSONObject;
+1 -1
View File
@@ -3,7 +3,7 @@ import {
GraphQLString,
GraphQLID,
} from 'graphql';
import GraphQLJSON from 'graphql-type-json';
import GraphQLJSON from './GraphQLJSONObject';
const Type = new GraphQLObjectType({
name: 'TradingSystem',
+1 -1
View File
@@ -1,7 +1,7 @@
import {
GraphQLInputObjectType,
} from 'graphql';
import GraphQLJSON from 'graphql-type-json';
import GraphQLJSON from '../GraphQLJSONObject';
const Type = new GraphQLInputObjectType({
name: 'TradingSystemInput',