Commit 1ec0a72a authored by aleclofabbro's avatar aleclofabbro
Browse files

removed Knows

parent 34857bfa
interface Glyph {
_id: ID!
}
# Knows
union KnowsSubject = User
union KnowsObject = User
type Knows implements Glyph {
_id: ID!
_subj: [KnowsSubject!]!
_obj: [KnowsObject!]!
}
# User
union UserRelation = Knows
type User implements Glyph {
type User {
_id: ID!
_rel: [UserRelation!]!
username: String!
}
......@@ -32,5 +16,4 @@ input CreateUserInput {
}
type Mutation {
createUser(user: CreateUserInput!): User
createKnows(from: ID!, to: ID!): Knows
}
......@@ -9,8 +9,8 @@
"subscriptionType": null,
"types": [
{
"kind": "INTERFACE",
"name": "Glyph",
"kind": "OBJECT",
"name": "User",
"description": null,
"fields": [
{
......@@ -28,73 +28,9 @@
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": [
{
"kind": "OBJECT",
"name": "Knows",
"ofType": null
},
{
"kind": "OBJECT",
"name": "User",
"ofType": null
}
]
},
{
"kind": "SCALAR",
"name": "ID",
"description": "The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": null
},
{
"kind": "UNION",
"name": "KnowsSubject",
"description": null,
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": [
{
"kind": "OBJECT",
"name": "User",
"ofType": null
}
]
},
{
"kind": "UNION",
"name": "KnowsObject",
"description": null,
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": [
{
"kind": "OBJECT",
"name": "User",
"ofType": null
}
]
},
{
"kind": "OBJECT",
"name": "Knows",
"description": null,
"fields": [
{
"name": "_id",
"name": "username",
"description": null,
"args": [],
"type": {
......@@ -102,160 +38,27 @@
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "_subj",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "UNION",
"name": "KnowsSubject",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "_obj",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "UNION",
"name": "KnowsObject",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
{
"kind": "INTERFACE",
"name": "Glyph",
"ofType": null
}
],
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "UNION",
"name": "UserRelation",
"description": null,
"kind": "SCALAR",
"name": "ID",
"description": "The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID.",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": [
{
"kind": "OBJECT",
"name": "Knows",
"ofType": null
}
]
},
{
"kind": "OBJECT",
"name": "User",
"description": null,
"fields": [
{
"name": "_id",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "_rel",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "UNION",
"name": "UserRelation",
"ofType": null
}
}
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "username",
"description": null,
"args": [],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
{
"kind": "INTERFACE",
"name": "Glyph",
"ofType": null
}
],
"enumValues": null,
"possibleTypes": null
},
{
......@@ -359,47 +162,6 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createKnows",
"description": null,
"args": [
{
"name": "from",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
},
{
"name": "to",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "ID",
"ofType": null
}
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "Knows",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
......
import { ObjectID } from 'mongodb'
import { toMongoRelation } from '../../../gql-graph/mongo/mappers'
import { graphCollection } from '../../../mongo/collection'
import { Knows, MutationResolvers } from '../../types'
export const createKnows: MutationResolvers['createKnows'] = async (_parent, args) => {
const newKnows = toMongoRelation<Knows>(
{
__typename: 'Knows',
},
new ObjectID(args.to),
new ObjectID(args.from)
)
const c = await graphCollection<Knows>()
await c.insertOne(newKnows)
return null //{ ...newKnows, _id: newKnows._id.toHexString(), _obj: [], _subj: [] }
}
import { graphCollection } from '../../../mongo/collection'
import { toMongoNode } from '../../../gql-graph/mongo/mappers'
import { MutationResolvers, User } from '../../types'
import { graphCollection } from '../../../mongo/collection'
import { MutationResolvers } from '../../types'
export const createUser: MutationResolvers['createUser'] = async (
_parent,
args /* , context, info */
) => {
const newUser = toMongoNode<User>({
const newUser = toMongoNode<any>({
__typename: 'User',
username: args.user.username,
})
const c = await graphCollection<User>()
const c = await graphCollection<any>()
await c.insertOne(newUser)
return null //{ ...newUser, _id: newUser._id.toHexString(), _rel: [] }
}
import { MutationResolvers } from '../../types'
import { createKnows } from './createKnows'
import { createUser } from './createUser'
export const Mutation: MutationResolvers = {
createUser,
createKnows,
}
......@@ -2,12 +2,6 @@ import { defaultGraphFieldResolver } from '../../../gql-graph/graphqlResolver'
export const Types = {
User: {
_id: defaultGraphFieldResolver(),
_rel: defaultGraphFieldResolver(),
username: defaultGraphFieldResolver(),
},
Knows: {
_id: defaultGraphFieldResolver(),
_subj: defaultGraphFieldResolver(),
_obj: defaultGraphFieldResolver(),
},
}
import { ShallowRelation } from '../../gql-graph/types'
import * as Types from '../types'
export const Knows = (tag: string): ShallowRelation<Types.Knows> => ({
__typename: 'Knows',
_id: `_id[${tag}]`,
})
import { Knows } from './Knows'
import { User } from './User'
export type ShallowTypeMocks = typeof ShallowTypeMocks
export const ShallowTypeMocks = {
User,
Knows,
}
......@@ -2,7 +2,6 @@ import { GraphQLResolveInfo } from 'graphql';
import { Context, RootValue } from './';
export type Maybe<T> = T | null;
export type Exact<T extends { [key: string]: unknown }> = { [K in keyof T]: T[K] };
export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
export type RequireFields<T, K extends keyof T> = { [X in Exclude<keyof T, K>]?: T[X] } & { [P in K]-?: NonNullable<T[P]> };
/** All built-in and custom scalars, mapped to their actual values */
export type Scalars = {
......@@ -13,27 +12,9 @@ export type Scalars = {
Float: number;
};
export type Glyph = {
_id: Scalars['ID'];
};
export type KnowsSubject = User;
export type KnowsObject = User;
export type Knows = Glyph & {
__typename: 'Knows';
_id: Scalars['ID'];
_subj: Array<KnowsSubject>;
_obj: Array<KnowsObject>;
};
export type UserRelation = Knows;
export type User = Glyph & {
export type User = {
__typename: 'User';
_id: Scalars['ID'];
_rel: Array<UserRelation>;
username: Scalars['String'];
};
......@@ -49,7 +30,6 @@ export type CreateUserInput = {
export type Mutation = {
__typename: 'Mutation';
createUser: Maybe<User>;
createKnows: Maybe<Knows>;
};
......@@ -58,12 +38,6 @@ export type MutationCreateUserArgs = {
};
export type MutationCreateKnowsArgs = {
from: Scalars['ID'];
to: Scalars['ID'];
};
export type ResolverTypeWrapper<T> = Promise<T> | T;
......@@ -141,13 +115,8 @@ export type DirectiveResolverFn<TResult = {}, TParent = {}, TContext = {}, TArgs
/** Mapping between all available schema types and the resolvers types */
export type ResolversTypes = {
Glyph: ResolversTypes['Knows'] | ResolversTypes['User'];
User: ResolverTypeWrapper<User>;
ID: ResolverTypeWrapper<Scalars['ID']>;
KnowsSubject: ResolversTypes['User'];
KnowsObject: ResolversTypes['User'];
Knows: ResolverTypeWrapper<Omit<Knows, '_subj' | '_obj'> & { _subj: Array<ResolversTypes['KnowsSubject']>, _obj: Array<ResolversTypes['KnowsObject']> }>;
UserRelation: ResolversTypes['Knows'];
User: ResolverTypeWrapper<Omit<User, '_rel'> & { _rel: Array<ResolversTypes['UserRelation']> }>;
String: ResolverTypeWrapper<Scalars['String']>;
Query: ResolverTypeWrapper<RootValue>;
CreateUserInput: CreateUserInput;
......@@ -157,13 +126,8 @@ export type ResolversTypes = {
/** Mapping between all available schema types and the resolvers parents */
export type ResolversParentTypes = {
Glyph: ResolversParentTypes['Knows'] | ResolversParentTypes['User'];
User: User;
ID: Scalars['ID'];
KnowsSubject: ResolversParentTypes['User'];
KnowsObject: ResolversParentTypes['User'];
Knows: Omit<Knows, '_subj' | '_obj'> & { _subj: Array<ResolversParentTypes['KnowsSubject']>, _obj: Array<ResolversParentTypes['KnowsObject']> };
UserRelation: ResolversParentTypes['Knows'];
User: Omit<User, '_rel'> & { _rel: Array<ResolversParentTypes['UserRelation']> };
String: Scalars['String'];
Query: RootValue;
CreateUserInput: CreateUserInput;
......@@ -171,33 +135,8 @@ export type ResolversParentTypes = {
Boolean: Scalars['Boolean'];
};
export type GlyphResolvers<ContextType = Context, ParentType extends ResolversParentTypes['Glyph'] = ResolversParentTypes['Glyph']> = {
__resolveType: TypeResolveFn<'Knows' | 'User', ParentType, ContextType>;
_id: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
};
export type KnowsSubjectResolvers<ContextType = Context, ParentType extends ResolversParentTypes['KnowsSubject'] = ResolversParentTypes['KnowsSubject']> = {
__resolveType: TypeResolveFn<'User', ParentType, ContextType>;
};
export type KnowsObjectResolvers<ContextType = Context, ParentType extends ResolversParentTypes['KnowsObject'] = ResolversParentTypes['KnowsObject']> = {
__resolveType: TypeResolveFn<'User', ParentType, ContextType>;
};
export type KnowsResolvers<ContextType = Context, ParentType extends ResolversParentTypes['Knows'] = ResolversParentTypes['Knows']> = {
_id: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
_subj: Resolver<Array<ResolversTypes['KnowsSubject']>, ParentType, ContextType>;
_obj: Resolver<Array<ResolversTypes['KnowsObject']>, ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
export type UserRelationResolvers<ContextType = Context, ParentType extends ResolversParentTypes['UserRelation'] = ResolversParentTypes['UserRelation']> = {
__resolveType: TypeResolveFn<'Knows', ParentType, ContextType>;
};
export type UserResolvers<ContextType = Context, ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User']> = {
_id: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
_rel: Resolver<Array<ResolversTypes['UserRelation']>, ParentType, ContextType>;
username: Resolver<ResolversTypes['String'], ParentType, ContextType>;
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
};
......@@ -208,15 +147,9 @@ export type QueryResolvers<ContextType = Context, ParentType extends ResolversPa
export type MutationResolvers<ContextType = Context, ParentType extends ResolversParentTypes['Mutation'] = ResolversParentTypes['Mutation']> = {
createUser: Resolver<Maybe<ResolversTypes['User']>, ParentType, ContextType, RequireFields<MutationCreateUserArgs, 'user'>>;
createKnows: Resolver<Maybe<ResolversTypes['Knows']>, ParentType, ContextType, RequireFields<MutationCreateKnowsArgs, 'from' | 'to'>>;
};
export type Resolvers<ContextType = Context> = {
Glyph: GlyphResolvers<ContextType>;
KnowsSubject: KnowsSubjectResolvers<ContextType>;
KnowsObject: KnowsObjectResolvers<ContextType>;
Knows: KnowsResolvers<ContextType>;
UserRelation: UserRelationResolvers<ContextType>;
User: UserResolvers<ContextType>;
Query: QueryResolvers<ContextType>;
Mutation: MutationResolvers<ContextType>;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment