datum-focus
Version:
Data shape, model, metadata, JSON, JSON Schema, GraphQL, MongoDB query and aggregations, iterator generators
121 lines (109 loc) • 2.83 kB
text/typescript
import {
GraphQLBoolean,
GraphQLList,
GraphQLObjectType,
GraphQLString
} from "graphql";
import { $eq } from './bson/expression/comparison';
import { $gt, $in, $lt } from './bson/query/comparison';
import { Constraint, ConstraintTuple } from './bson/constraint';
interface Human {
age: number;
name: string;
}
const k: Human = {
age: 33,
name: "ss",
};
const filter1: Constraint<Human> = {
$not: {
age: { $gt: 2, $lte: 99 },
name: [$eq, "lucas"],
},
};
const filter11: Constraint<Human> = {
$not: {
$or: [
{
age: { $gt: 2, $lte: 99 },
name: [$eq, "lucas"],
},
{
age: { $gt: 2, $lte: 99 },
name: [$eq, "martinez"],
},
],
},
};
const filter2: Constraint<Human> = {
$or: [
{
age: { $gt: 42, $lte: 99 },
name: [$eq, "lucas"],
},
{
age: { $gt: 20, $lte: 56 },
name: [$eq, "martinez"],
},
],
};
export const expr: Constraint<Human> = {
$or: [
[$eq, "age", 5],
[$gt, "age", 5],
[$lt, "age", 6],
[$in, "name", "lucas", "martinez"],
],
};
const tuple: ConstraintTuple<Human, "name"> = ["$in", "name", "lucas", "martinez"];
// import { couponSchema } from './dbSchemas';
export const cuponType = new GraphQLObjectType({
name: "couponType",
description: "Coupon schema",
fields: {
couponCode: { type: new GraphQLList(GraphQLString) },
description: { type: GraphQLString },
discountType: { type: GraphQLString },
discountAmount: { type: GraphQLString },
minimumAmount: { type: GraphQLString },
singleUseOnly: { type: GraphQLBoolean },
createdAt: { type: GraphQLString },
updatedAt: { type: GraphQLString },
expirationDate: { type: GraphQLString },
isMassPromo: { type: GraphQLBoolean },
couponBatchId: { type: GraphQLString },
maximumAmount: { type: GraphQLString },
isPublished: { type: GraphQLBoolean },
},
});
const quizType = new GraphQLObjectType({
name: "quizType",
description: "quiz type for customer",
fields: {
message: { type: GraphQLString },
updatedAt: { type: GraphQLString },
createdAt: { type: GraphQLString },
},
});
export const customerType = new GraphQLObjectType({
name: "customerType",
description: "Customer schema",
fields: {
createdAt: { type: GraphQLString },
updatedAt: { type: GraphQLString },
firstName: { type: GraphQLString },
lastName: { type: GraphQLString },
email: { type: GraphQLString },
quiz: { type: new GraphQLList(quizType) },
subscription: {
type: new GraphQLObjectType({
name: "subscription",
fields: () => ({
status: { type: GraphQLString },
plan: { type: GraphQLString },
products: { type: new GraphQLList(GraphQLString) },
}),
}),
},
},
});