Commit 261cbb76 authored by aleclofabbro's avatar aleclofabbro
Browse files

renaming stuff

parent 24ec7e11
interface Glyph {
_id: ID!
id: ID!
}
input StringMatch {
eq: String
gt: String
lt: String
input StringMatchInput {
_eq: String
_gt: String
_lt: String
}
input PageArg {
input PageInput {
limit: Int
after: ID
}
......@@ -14,70 +14,69 @@ input PageArg {
# Knows
union Knower = User
union Knowable = User
input KnowSubjectQuery {
User: UserQuery
input KnowsSubjectQueryInput {
User: UserQueryInput
}
input KnowObjectQuery {
User: UserQuery
input KnowsObjectQueryInput {
User: UserQueryInput
}
input KnowsQuery {
and: [KnowsQuery!]
or: [KnowsQuery!]
_page: PageArg
input KnowsQueryInput {
_and: [KnowsQueryInput!]
_or: [KnowsQueryInput!]
id: [ID!]
}
type Knows implements Glyph {
_id: ID!
_subj(query: KnowSubjectQuery): [Knower!]!
_obj(query: KnowObjectQuery): [Knowable!]!
id: ID!
_subj(query: KnowsSubjectQueryInput, page: PageInput): [Knower!]!
_obj(query: KnowsObjectQueryInput, page: PageInput): [Knowable!]!
}
# Follows
union Follower = User
union Followable = User
input FollowObjectQuery {
User: UserQuery
input FollowObjectQueryInput {
User: UserQueryInput
}
input FollowSubjectQuery {
User: UserQuery
input FollowSubjectQueryInput {
User: UserQueryInput
}
input FollowsQuery {
and: [FollowsQuery!]
or: [FollowsQuery!]
_page: PageArg
input FollowsQueryInput {
_and: [FollowsQueryInput!]
_or: [FollowsQueryInput!]
id: [ID!]
}
type Follows implements Glyph {
_id: ID!
_subj(query: FollowSubjectQuery): [Follower!]!
_obj(query: FollowObjectQuery): [Followable!]!
id: ID!
_subj(query: FollowSubjectQueryInput, page: PageInput): [Follower!]!
_obj(query: FollowObjectQueryInput, page: PageInput): [Followable!]!
}
# User
input UserQuery {
and: [UserQuery!]
or: [UserQuery!]
_id: ID
username: StringMatch
_page: PageArg
input UserQueryInput {
_and: [UserQueryInput!]
_or: [UserQueryInput!]
id: [ID!]
username: StringMatchInput
}
input UserRelationQuery {
Follows: FollowsQuery
Knows: KnowsQuery
input UserRelationQueryInput {
Follows: FollowsQueryInput
Knows: KnowsQueryInput
}
union UserRelation = Knows | Follows
type User implements Glyph {
_id: ID!
_rel(query: UserRelationQuery): [UserRelation!]!
id: ID!
_rel(query: UserRelationQueryInput, page: PageInput): [UserRelation!]!
username: String!
}
# Main
type Query {
user(query: UserQuery): [User!]!
user(query: UserQueryInput): [User!]!
}
input CreateUserInput {
......
import { ObjectID } from 'mongodb'
import { GqlNode, GqlRelation, ShallowEntity } from '../types'
export type MongoNode<T extends GqlNode> = Omit<T, '_id' | '_rel'> & { _id: ObjectID }
export type MongoRelation<T extends GqlRelation> = Omit<T, '_id' | '_subj' | '_obj'> & {
export type MongoNode<T extends GqlNode> = Omit<T, 'id' | '_rel'> & { _id: ObjectID }
export type MongoRelation<T extends GqlRelation> = Omit<T, 'id' | '_subj' | '_obj'> & {
_id: ObjectID
_obj: ObjectID
_subj: ObjectID
}
export const toMongoNode = <N extends GqlNode>(
node: ShallowEntity<N> | Omit<ShallowEntity<N>, '_id'>
gql_node: ShallowEntity<N> | Omit<ShallowEntity<N>, 'id'>
): MongoNode<N> => {
const _id = '_id' in node ? new ObjectID(node._id) : new ObjectID()
const _id = 'id' in gql_node ? new ObjectID(gql_node.id) : new ObjectID()
const mongo_node = Object.entries(node).reduce(
(_mongo_node, [key, val]) => {
if (['_id', '_rel'].includes(key)) {
return _mongo_node
const mongo_node = Object.entries(gql_node).reduce(
(constructing_mongo_node, [key, val]) => {
if (['id', '_rel'].includes(key)) {
return constructing_mongo_node
}
return {
..._mongo_node,
...constructing_mongo_node,
[key]: val,
}
},
......
import { GraphQuery } from '../types'
import { GraphQuery, GraphQueryObj } from '../types'
export const buildQuery = (root: GraphQuery) => {
return root.qObj.traverse.reduce((resultStages, gqo) => {
if (!(gqo.select.length || gqo.select.length)) {
return _buildUnionQuery([root.qObj])
}
const _buildUnionQuery = (qObjs: GraphQueryObj[]) => {
// const groupedTraversesByAlias = traversingGQObj.traverse.reduce((_grouped, groupingQObj) => {
// const slots = _grouped[groupingQObj.alias] || (_grouped[groupingQObj.alias] = [])
// slots.push(groupingQObj)
// return groupingQObj
// }, {} as Record<string, GraphQueryObj[]>)
const stages: any[] = []
// const stages = [
// {
// $match: { $and: [{ __typename: { $in: qObjs.map((_) => _.__typename) } }, gqo.query.match] },
// },
// ...getTraverse,
// { $limit: gqo.query.page?.limit || 15 },
// ]
return qObjs.map((qObj) =>
qObj.traverse.reduce((resultStages, traversingGQObj) => {
if (!(traversingGQObj.select.length || traversingGQObj.traverse.length)) {
return resultStages
}
const stages = [
{ $match: { $and: [{ __typename: gqo.__typename }, gqo.query.match] } },
{ $limit: gqo.query.page.limit || 15 },
]
return [...resultStages, ...stages]
}, [] as any[])
)
}
......@@ -3,7 +3,7 @@ import { ObjectID } from 'mongodb'
export type ShallowEntity<T> = Omit<T, '_rel'>
export type ShallowRelation<T> = Omit<T, '_obj' | '_subj'>
export type GqlType = { _id: string; __typename: string }
export type GqlType = { id: string; __typename: string }
export type GqlNode = GqlType & { _rel: any[] }
export type GqlRelation = GqlType & { _obj: any; _subj: any }
......
......@@ -14,7 +14,7 @@
"description": null,
"fields": [
{
"name": "_id",
"name": "id",
"description": null,
"args": [],
"type": {
......@@ -63,12 +63,12 @@
},
{
"kind": "INPUT_OBJECT",
"name": "StringMatch",
"name": "StringMatchInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "eq",
"name": "_eq",
"description": null,
"type": {
"kind": "SCALAR",
......@@ -78,7 +78,7 @@
"defaultValue": null
},
{
"name": "gt",
"name": "_gt",
"description": null,
"type": {
"kind": "SCALAR",
......@@ -88,7 +88,7 @@
"defaultValue": null
},
{
"name": "lt",
"name": "_lt",
"description": null,
"type": {
"kind": "SCALAR",
......@@ -114,7 +114,7 @@
},
{
"kind": "INPUT_OBJECT",
"name": "PageArg",
"name": "PageInput",
"description": null,
"fields": null,
"inputFields": [
......@@ -187,7 +187,7 @@
},
{
"kind": "INPUT_OBJECT",
"name": "KnowSubjectQuery",
"name": "KnowsSubjectQueryInput",
"description": null,
"fields": null,
"inputFields": [
......@@ -196,7 +196,7 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"name": "UserQueryInput",
"ofType": null
},
"defaultValue": null
......@@ -208,7 +208,7 @@
},
{
"kind": "INPUT_OBJECT",
"name": "KnowObjectQuery",
"name": "KnowsObjectQueryInput",
"description": null,
"fields": null,
"inputFields": [
......@@ -217,7 +217,7 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"name": "UserQueryInput",
"ofType": null
},
"defaultValue": null
......@@ -229,12 +229,12 @@
},
{
"kind": "INPUT_OBJECT",
"name": "KnowsQuery",
"name": "KnowsQueryInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "and",
"name": "_and",
"description": null,
"type": {
"kind": "LIST",
......@@ -244,7 +244,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "KnowsQuery",
"name": "KnowsQueryInput",
"ofType": null
}
}
......@@ -252,7 +252,7 @@
"defaultValue": null
},
{
"name": "or",
"name": "_or",
"description": null,
"type": {
"kind": "LIST",
......@@ -262,7 +262,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "KnowsQuery",
"name": "KnowsQueryInput",
"ofType": null
}
}
......@@ -270,12 +270,20 @@
"defaultValue": null
},
{
"name": "_page",
"name": "id",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "PageArg",
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
}
......@@ -290,7 +298,7 @@
"description": null,
"fields": [
{
"name": "_id",
"name": "id",
"description": null,
"args": [],
"type": {
......@@ -314,7 +322,17 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "KnowSubjectQuery",
"name": "KnowsSubjectQueryInput",
"ofType": null
},
"defaultValue": null
},
{
"name": "page",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "PageInput",
"ofType": null
},
"defaultValue": null
......@@ -349,7 +367,17 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "KnowObjectQuery",
"name": "KnowsObjectQueryInput",
"ofType": null
},
"defaultValue": null
},
{
"name": "page",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "PageInput",
"ofType": null
},
"defaultValue": null
......@@ -421,7 +449,7 @@
},
{
"kind": "INPUT_OBJECT",
"name": "FollowObjectQuery",
"name": "FollowObjectQueryInput",
"description": null,
"fields": null,
"inputFields": [
......@@ -430,7 +458,7 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"name": "UserQueryInput",
"ofType": null
},
"defaultValue": null
......@@ -442,7 +470,7 @@
},
{
"kind": "INPUT_OBJECT",
"name": "FollowSubjectQuery",
"name": "FollowSubjectQueryInput",
"description": null,
"fields": null,
"inputFields": [
......@@ -451,7 +479,7 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"name": "UserQueryInput",
"ofType": null
},
"defaultValue": null
......@@ -463,12 +491,12 @@
},
{
"kind": "INPUT_OBJECT",
"name": "FollowsQuery",
"name": "FollowsQueryInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "and",
"name": "_and",
"description": null,
"type": {
"kind": "LIST",
......@@ -478,7 +506,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "FollowsQuery",
"name": "FollowsQueryInput",
"ofType": null
}
}
......@@ -486,7 +514,7 @@
"defaultValue": null
},
{
"name": "or",
"name": "_or",
"description": null,
"type": {
"kind": "LIST",
......@@ -496,7 +524,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "FollowsQuery",
"name": "FollowsQueryInput",
"ofType": null
}
}
......@@ -504,12 +532,20 @@
"defaultValue": null
},
{
"name": "_page",
"name": "id",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "PageArg",
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
}
......@@ -524,7 +560,7 @@
"description": null,
"fields": [
{
"name": "_id",
"name": "id",
"description": null,
"args": [],
"type": {
......@@ -548,7 +584,17 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "FollowSubjectQuery",
"name": "FollowSubjectQueryInput",
"ofType": null
},
"defaultValue": null
},
{
"name": "page",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "PageInput",
"ofType": null
},
"defaultValue": null
......@@ -583,7 +629,17 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "FollowObjectQuery",
"name": "FollowObjectQueryInput",
"ofType": null
},
"defaultValue": null
},
{
"name": "page",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "PageInput",
"ofType": null
},
"defaultValue": null
......@@ -623,12 +679,12 @@
},
{
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"name": "UserQueryInput",
"description": null,
"fields": null,
"inputFields": [
{
"name": "and",
"name": "_and",
"description": null,
"type": {
"kind": "LIST",
......@@ -638,7 +694,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"name": "UserQueryInput",
"ofType": null
}
}
......@@ -646,7 +702,7 @@
"defaultValue": null
},
{
"name": "or",
"name": "_or",
"description": null,
"type": {
"kind": "LIST",
......@@ -656,7 +712,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"name": "UserQueryInput",
"ofType": null
}
}
......@@ -664,12 +720,20 @@
"defaultValue": null
},
{
"name": "_id",
"name": "id",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
}
},
"defaultValue": null
},
......@@ -678,17 +742,7 @@
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "StringMatch",
"ofType": null
},
"defaultValue": null
},
{
"name": "_page",
"description": null,
"type": {
"kind": "INPUT_OBJECT",