Commit 6181a1b3 authored by aleclofabbro's avatar aleclofabbro
Browse files

there you go

parent ef3c0200
......@@ -14,66 +14,81 @@ input PageArg {
after: ID
}
# Knows
union Knower = User
union Knowable = User
input KnowsFilter {
and: [KnowsFilter!]
or: [KnowsFilter!]
_subj: [UserFilter!]
_obj: [UserFilter!]
input KnowSubjectQuery {
User: UserQuery
}
input KnowObjectQuery {
User: UserQuery
}
input KnowsQuery {
and: [KnowsQuery!]
or: [KnowsQuery!]
_page: PageArg
}
type Knows implements Glyph {
_id: ID!
_subj: [Knower!]!
_obj: [Knowable!]!
_subj(query: KnowSubjectQuery): [Knower!]!
_obj(query: KnowObjectQuery): [Knowable!]!
}
# Follows
union Follower = User
union Followable = User
input FollowsFilter {
and: [FollowsFilter!]
or: [FollowsFilter!]
_subj: [UserFilter!]
_obj: [UserFilter!]
input FollowObjectQuery {
User: UserQuery
}
input FollowSubjectQuery {
User: UserQuery
}
input FollowsQuery {
and: [FollowsQuery!]
or: [FollowsQuery!]
_page: PageArg
}
type Follows implements Glyph {
_id: ID!
_subj: [Follower!]!
_obj: [Followable!]!
_subj(query: FollowSubjectQuery): [Follower!]!
_obj(query: FollowObjectQuery): [Followable!]!
}
input UserFilter {
and: [UserFilter!]
or: [UserFilter!]
# User
input UserQuery {
and: [UserQuery!]
or: [UserQuery!]
_id: ID
username: StringMatch
_rel: [UserRelationFilter!]
_page: PageArg
}
input UserRelationFilter {
alias: String!
follows: FollowsFilter
knows: KnowsFilter
input UserRelationQuery {
Follows: FollowsQuery
Knows: KnowsQuery
}
union UserRelation = Knows | Follows
type User implements Glyph {
_id: ID!
_rel(page: PageArg): [UserRelation!]!
_rel(query: UserRelationQuery): [UserRelation!]!
username: String!
}
# Main
type Query {
user(match: UserFilter): [User!]! @graphEntry
user(query: UserQuery): [User!]! @graphEntry
da: Query!
}
input UserInput {
input CreateUserInput {
username: String!
}
type Mutation {
createUser(user: UserInput!): User!
createUser(user: CreateUserInput!): User!
}
enum Role {
......
......@@ -187,48 +187,54 @@
},
{
"kind": "INPUT_OBJECT",
"name": "KnowsFilter",
"name": "KnowSubjectQuery",
"description": null,
"fields": null,
"inputFields": [
{
"name": "and",
"name": "User",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "KnowsFilter",
"ofType": null
}
}
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"ofType": null
},
"defaultValue": null
},
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "KnowObjectQuery",
"description": null,
"fields": null,
"inputFields": [
{
"name": "or",
"name": "User",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "KnowsFilter",
"ofType": null
}
}
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"ofType": null
},
"defaultValue": null
},
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "KnowsQuery",
"description": null,
"fields": null,
"inputFields": [
{
"name": "_subj",
"name": "and",
"description": null,
"type": {
"kind": "LIST",
......@@ -238,7 +244,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "KnowsQuery",
"ofType": null
}
}
......@@ -246,7 +252,7 @@
"defaultValue": null
},
{
"name": "_obj",
"name": "or",
"description": null,
"type": {
"kind": "LIST",
......@@ -256,7 +262,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "KnowsQuery",
"ofType": null
}
}
......@@ -302,7 +308,18 @@
{
"name": "_subj",
"description": null,
"args": [],
"args": [
{
"name": "query",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "KnowSubjectQuery",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
......@@ -326,7 +343,18 @@
{
"name": "_obj",
"description": null,
"args": [],
"args": [
{
"name": "query",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "KnowObjectQuery",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
......@@ -393,48 +421,54 @@
},
{
"kind": "INPUT_OBJECT",
"name": "FollowsFilter",
"name": "FollowObjectQuery",
"description": null,
"fields": null,
"inputFields": [
{
"name": "and",
"name": "User",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "FollowsFilter",
"ofType": null
}
}
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"ofType": null
},
"defaultValue": null
},
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "FollowSubjectQuery",
"description": null,
"fields": null,
"inputFields": [
{
"name": "or",
"name": "User",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "FollowsFilter",
"ofType": null
}
}
"kind": "INPUT_OBJECT",
"name": "UserQuery",
"ofType": null
},
"defaultValue": null
},
}
],
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "FollowsQuery",
"description": null,
"fields": null,
"inputFields": [
{
"name": "_subj",
"name": "and",
"description": null,
"type": {
"kind": "LIST",
......@@ -444,7 +478,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "FollowsQuery",
"ofType": null
}
}
......@@ -452,7 +486,7 @@
"defaultValue": null
},
{
"name": "_obj",
"name": "or",
"description": null,
"type": {
"kind": "LIST",
......@@ -462,7 +496,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "FollowsQuery",
"ofType": null
}
}
......@@ -508,7 +542,18 @@
{
"name": "_subj",
"description": null,
"args": [],
"args": [
{
"name": "query",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "FollowSubjectQuery",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
......@@ -532,7 +577,18 @@
{
"name": "_obj",
"description": null,
"args": [],
"args": [
{
"name": "query",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "FollowObjectQuery",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
......@@ -567,7 +623,7 @@
},
{
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "UserQuery",
"description": null,
"fields": null,
"inputFields": [
......@@ -582,7 +638,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "UserQuery",
"ofType": null
}
}
......@@ -600,7 +656,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "UserQuery",
"ofType": null
}
}
......@@ -627,24 +683,6 @@
},
"defaultValue": null
},
{
"name": "_rel",
"description": null,
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserRelationFilter",
"ofType": null
}
}
},
"defaultValue": null
},
{
"name": "_page",
"description": null,
......@@ -662,40 +700,26 @@
},
{
"kind": "INPUT_OBJECT",
"name": "UserRelationFilter",
"name": "UserRelationQuery",
"description": null,
"fields": null,
"inputFields": [
{
"name": "alias",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "follows",
"name": "Follows",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "FollowsFilter",
"name": "FollowsQuery",
"ofType": null
},
"defaultValue": null
},
{
"name": "knows",
"name": "Knows",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "KnowsFilter",
"name": "KnowsQuery",
"ofType": null
},
"defaultValue": null
......@@ -752,11 +776,11 @@
"description": null,
"args": [
{
"name": "page",
"name": "query",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "PageArg",
"name": "UserRelationQuery",
"ofType": null
},
"defaultValue": null
......@@ -820,11 +844,11 @@
"description": null,
"args": [
{
"name": "match",
"name": "query",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "UserFilter",
"name": "UserQuery",
"ofType": null
},
"defaultValue": null
......@@ -874,7 +898,7 @@
},
{
"kind": "INPUT_OBJECT",
"name": "UserInput",
"name": "CreateUserInput",
"description": null,
"fields": null,
"inputFields": [
......@@ -914,7 +938,7 @@
"name": null,
"ofType": {
"kind": "INPUT_OBJECT",
"name": "UserInput",
"name": "CreateUserInput",
"ofType": null
}
},
......
......@@ -5,6 +5,7 @@ import { defaultGraphFieldResolver } from '../types'
export const Query: QueryResolvers = {
// user: defaultGraphEntry<'user'>('User'),
da: defaultGraphFieldResolver(),
user: defaultGraphFieldResolver(),
}
......
......@@ -10,6 +10,7 @@ import {
} from 'graphql'
import { Context } from '../..'
import { getParent } from '../../../mongo/helpers/graphQuery'
import { GraphQueryObj } from '../../../mongo/types'
import { typeInfo } from '../../helpers/info'
import { ResolverFn, Resolvers, TypeResolveFn } from '../../types'
export const Types = {
......@@ -33,48 +34,40 @@ export const Types = {
export function defaultGraphFieldResolver(): ResolverFn<any, any, Context, any> {
return (parent, args, context, info) => {
if (!context.$graph) {
// throw new Error(`defaultFieldResolver no context.$graph`)
context.$graph = {
traverse: [],
__typename: 'Query',
alias: 'Query',
limit: -1,
match: [],
select: [],
qObj: {
typename: 'Query',
query: undefined,
traverse: [],
alias: 'Query',
select: [],
},
}
}
const { fieldName, parentType, returnType } = info
const { isList, isNullable, objs } = typeInfo(returnType)
const __typenames = objs.map((_) => _.name)
const isTop = !info.path.prev
// if (isTop) {
// // throw new Error(`defaultFieldResolver no context.$graph`)
// context.$graph.traverse.push({
// __typenames,
// limit: 100000,
// match: [],
// traverse: [],
// alias: `${info.path.key}`,
// })
// }
console.log(`defaultFieldResolver `, parent, parentType.name, fieldName)
const parentQ = getParent(info, context, info.parentType.name)
const parentQ = getParent(info, context)
console.log(`defaultFieldResolver `, {
parent,
parentTypeName: parentType.name,
fieldName,
path: info.path,
parentQ,
})
if (!parentQ) {
throw new Error('defaultFieldResolver no parentQ')
}
if (isTop || ['_rel', '_subj', '_obj'].includes(fieldName)) {
const __typenames = objs.map((_) => _.name)
parentQ.traverse.push(
...__typenames.map((__typename) => ({
limit: 500,