Strategizer Server moved to old repos

This commit is contained in:
Luis Fernando Molina committed 2020-11-20 19:38:56 +01:00
1 parent dc50cfa303
commit b91b7a20dd
36 files changed

No files matched your search

@@ -0,0 +1,13 @@
import {
GraphQLSchema,
} from 'graphql';
import Mutation from './mutations';
import RootQuery from './queries';
const Schema = new GraphQLSchema({
query: RootQuery,
mutation: Mutation,
});
export default Schema;
@@ -0,0 +1,42 @@
import {
GraphQLNonNull,
GraphQLString,
} from 'graphql';
import { TradingSystemType } from '../types';
import { TradingSystem } from '../../models';
import { TradingSystemInputType } from '../types/input';
import defaultTradingSystem from '../../templates/tradingSystemTemplate';
export const args = {
fbSlug: { type: new GraphQLNonNull(GraphQLString) },
tradingSystem: { type: TradingSystemInputType },
};
const resolve = (parent, { fbSlug, tradingSystem }) => {
if (tradingSystem === undefined) {
tradingSystem = defaultTradingSystem;
}
tradingSystem.fbSlug = fbSlug;
tradingSystem.history = [];
const newTradingSystem = new TradingSystem(tradingSystem);
return new Promise((res, rej) => {
newTradingSystem.save((err) => {
if (err) {
rej(err);
return;
}
res(newTradingSystem);
});
});
};
const mutation = {
createTradingSystem: {
type: TradingSystemType,
args,
resolve,
},
};
export default mutation;
@@ -0,0 +1,47 @@
import {
GraphQLNonNull,
GraphQLID,
} from 'graphql';
import { TradingSystemType } from '../types';
import { TradingSystem } from '../../models';
import { TradingSystemInputType } from '../types/input';
const args = {
id: { type: new GraphQLNonNull(GraphQLID) },
tradingSystem: { type: new GraphQLNonNull(TradingSystemInputType) },
};
const resolve = (parent, { id: _id, tradingSystem: editedTradingSystem }) => new Promise((res, rej) => {
TradingSystem.findOne({ _id }).exec((err, tradingSystem) => {
if (err) {
rej(err);
return;
}
if (!tradingSystem) {
rej(err);
return;
}
tradingSystem.history.push({
updatedAt: tradingSystem.updatedAt,
data: tradingSystem.data,
});
tradingSystem.data = editedTradingSystem.data;
tradingSystem.save((error) => {
if (error) {
rej(error);
return;
}
res(tradingSystem);
});
});
});
const mutation = {
editTradingSystem: {
type: TradingSystemType,
args,
resolve,
},
};
export default mutation;
@@ -0,0 +1,16 @@
import {
GraphQLObjectType,
} from 'graphql';
import CreateTradingSystemMutation from './CreateTradingSystem';
import EditTradingSystemMutation from './EditTradingSystem';
const Mutation = new GraphQLObjectType({
name: 'Mutation',
fields: Object.assign(
CreateTradingSystemMutation,
EditTradingSystemMutation,
),
});
export default Mutation;
@@ -0,0 +1,35 @@
import {
GraphQLNonNull,
GraphQLString,
} from 'graphql';
import { DatabaseError } from '../../errors';
import { TradingSystemType } from '../types';
import { TradingSystem } from '../../models';
const args = {
fbSlug: { type: new GraphQLNonNull(GraphQLString) },
};
const resolve = (parent, { fbSlug }) => new Promise((res, rej) => {
TradingSystem.findOne({ fbSlug }).exec((err, tradingSystem) => {
if (err) {
rej(err);
return;
}
if (!tradingSystem) {
rej(new DatabaseError('None of the tradingSystem are linked to that fbSlug'));
return;
}
res(tradingSystem);
});
});
const query = {
tradingSystemByFb: {
type: TradingSystemType,
args,
resolve,
},
};
export default query;
@@ -0,0 +1,35 @@
import {
GraphQLNonNull,
GraphQLString,
} from 'graphql';
import { DatabaseError } from '../../errors';
import { TradingSystemType } from '../types';
import { TradingSystem } from '../../models';
const args = {
id: { type: new GraphQLNonNull(GraphQLString) },
};
const resolve = (parent, { id }) => new Promise((res, rej) => {
TradingSystem.findOne({ _id: id }).exec((err, tradingSystem) => {
if (err) {
rej(err);
return;
}
if (!tradingSystem) {
rej(new DatabaseError('None of the tradingSystem are linked to that id'));
return;
}
res(tradingSystem);
});
});
const query = {
tradingSystemById: {
type: TradingSystemType,
args,
resolve,
},
};
export default query;
@@ -0,0 +1,16 @@
import {
GraphQLObjectType,
} from 'graphql';
import TradingSystemByFbQuery from './TradingSystemByFB';
import TradingSystemByIdQuery from './TradingSystemById';
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: Object.assign(
TradingSystemByFbQuery,
TradingSystemByIdQuery,
),
});
export default RootQuery;
@@ -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;
@@ -0,0 +1,18 @@
import {
GraphQLObjectType,
GraphQLString,
GraphQLID,
} from 'graphql';
import GraphQLJSON from './GraphQLJSONObject';
const Type = new GraphQLObjectType({
name: 'TradingSystem',
description: 'Everything you need to know about a trading system',
fields: () => ({
id: { type: GraphQLID },
fbSlug: { type: GraphQLString },
data: { type: GraphQLJSON },
}),
});
export default Type;
Whitespace-only changes.
@@ -0,0 +1,6 @@
import TradingSystemType from './TradingSystem';
export {
// eslint-disable-next-line import/prefer-default-export
TradingSystemType,
};
@@ -0,0 +1,14 @@
import {
GraphQLInputObjectType,
} from 'graphql';
import GraphQLJSON from '../GraphQLJSONObject';
const Type = new GraphQLInputObjectType({
name: 'TradingSystemInput',
description: 'Payload for trading system input',
fields: () => ({
data: { type: GraphQLJSON },
}),
});
export default Type;
@@ -0,0 +1,6 @@
import TradingSystemInputType from './TradingSystem';
export {
// eslint-disable-next-line import/prefer-default-export
TradingSystemInputType,
};