mirror of
https://github.com/wassname/talk.git
synced 2026-09-10 12:43:11 +08:00
feature: added generated graph types
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import Cursor from "../../common/scalars/cursor";
|
||||
import { GQLResolver } from "talk-server/graph/management/schema/__generated__/types";
|
||||
|
||||
export default {
|
||||
Cursor,
|
||||
};
|
||||
const Resolvers: GQLResolver = {};
|
||||
|
||||
export default Resolvers;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { IResolvers } from "graphql-tools";
|
||||
|
||||
import loadSchema from "talk-server/graph/common/schema";
|
||||
import resolvers from "talk-server/graph/management/resolvers";
|
||||
|
||||
export default function getManagementSchema() {
|
||||
return loadSchema("management", resolvers);
|
||||
return loadSchema("management", resolvers as IResolvers);
|
||||
}
|
||||
|
||||
@@ -7,27 +7,22 @@ Time represented as an ISO8601 string.
|
||||
"""
|
||||
scalar Time
|
||||
|
||||
"""
|
||||
Cursor represents a paginating cursor.
|
||||
"""
|
||||
scalar Cursor
|
||||
|
||||
################################################################################
|
||||
## Tenant
|
||||
################################################################################
|
||||
|
||||
type Tenant {
|
||||
id: ID!
|
||||
id: ID!
|
||||
|
||||
"""
|
||||
organizationName is the name of the organization.
|
||||
"""
|
||||
organizationName: String
|
||||
"""
|
||||
organizationName is the name of the organization.
|
||||
"""
|
||||
organizationName: String
|
||||
|
||||
"""
|
||||
organizationContactEmail is the email of the organization.
|
||||
"""
|
||||
organizationContactEmail: String
|
||||
"""
|
||||
organizationContactEmail is the email of the organization.
|
||||
"""
|
||||
organizationContactEmail: String
|
||||
}
|
||||
|
||||
################################################################################
|
||||
@@ -35,5 +30,5 @@ type Tenant {
|
||||
################################################################################
|
||||
|
||||
type Query {
|
||||
tenant(id: ID!): Tenant
|
||||
tenant(id: ID!): Tenant
|
||||
}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import DataLoader from "dataloader";
|
||||
|
||||
import Context from "talk-server/graph/tenant/context";
|
||||
import {
|
||||
ConnectionInput,
|
||||
AssetToCommentsArgs,
|
||||
CommentToRepliesArgs,
|
||||
} from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
import {
|
||||
retrieveAssetConnection,
|
||||
retrieveMany,
|
||||
retrieveRepliesConnection,
|
||||
@@ -11,8 +15,8 @@ export default (ctx: Context) => ({
|
||||
comment: new DataLoader((ids: string[]) =>
|
||||
retrieveMany(ctx.db, ctx.tenant.id, ids)
|
||||
),
|
||||
forAsset: (assetID: string, input: ConnectionInput) =>
|
||||
forAsset: (assetID: string, input: AssetToCommentsArgs) =>
|
||||
retrieveAssetConnection(ctx.db, ctx.tenant.id, assetID, input),
|
||||
forParent: (assetID: string, parentID: string, input: ConnectionInput) =>
|
||||
forParent: (assetID: string, parentID: string, input: CommentToRepliesArgs) =>
|
||||
retrieveRepliesConnection(ctx.db, ctx.tenant.id, assetID, parentID, input),
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import TenantContext from "talk-server/graph/tenant/context";
|
||||
import { CreateCommentInput } from "talk-server/graph/tenant/resolvers/mutation";
|
||||
import { GQLCreateCommentInput } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
import { Comment } from "talk-server/models/comment";
|
||||
import { create } from "talk-server/services/comments";
|
||||
|
||||
export default (ctx: TenantContext) => ({
|
||||
create: (input: CreateCommentInput): Promise<Comment> => {
|
||||
create: (input: GQLCreateCommentInput): Promise<Comment> => {
|
||||
// FIXME: remove tenant + user !
|
||||
return create(ctx.db, ctx.tenant!.id, {
|
||||
return create(ctx.db, ctx.tenant.id, {
|
||||
author_id: ctx.user!.id,
|
||||
asset_id: input.assetID,
|
||||
body: input.body,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import Context from "talk-server/graph/tenant/context";
|
||||
import { GQLAssetTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
import { Asset } from "talk-server/models/asset";
|
||||
import { ConnectionInput } from "talk-server/models/comment";
|
||||
|
||||
export default {
|
||||
comments: async (asset: Asset, input: ConnectionInput, ctx: Context) =>
|
||||
const Asset: GQLAssetTypeResolver<Asset> = {
|
||||
comments: (asset, input, ctx) =>
|
||||
ctx.loaders.Comments.forAsset(asset.id, input),
|
||||
// TODO: implement this.
|
||||
isClosed: () => false,
|
||||
};
|
||||
|
||||
export default Asset;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import Context from "talk-server/graph/tenant/context";
|
||||
import { Comment, ConnectionInput } from "talk-server/models/comment";
|
||||
import { GQLCommentTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
import { Comment } from "talk-server/models/comment";
|
||||
|
||||
export default {
|
||||
author: async (comment: Comment, _: any, ctx: Context) =>
|
||||
const Comment: GQLCommentTypeResolver<Comment> = {
|
||||
author: async (comment, args, ctx) =>
|
||||
ctx.loaders.Users.user.load(comment.author_id),
|
||||
replies: async (comment: Comment, input: ConnectionInput, ctx: Context) =>
|
||||
replies: async (comment, input, ctx) =>
|
||||
ctx.loaders.Comments.forParent(comment.asset_id, comment.id, input),
|
||||
};
|
||||
|
||||
export default Comment;
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
import Cursor from "../../common/scalars/cursor";
|
||||
import Cursor from "talk-server/graph/common/scalars/cursor";
|
||||
import { GQLResolver } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
|
||||
import Asset from "./asset";
|
||||
import Comment from "./comment";
|
||||
import Mutation from "./mutation";
|
||||
import Query from "./query";
|
||||
|
||||
export default {
|
||||
const Resolvers: GQLResolver = {
|
||||
Asset,
|
||||
Comment,
|
||||
Cursor,
|
||||
Query,
|
||||
Mutation,
|
||||
};
|
||||
|
||||
export default Resolvers;
|
||||
|
||||
@@ -1,23 +1,7 @@
|
||||
import { ClientMutationProps } from "talk-server/graph/common/resolvers/mutation";
|
||||
import TenantContext from "talk-server/graph/tenant/context";
|
||||
import { Comment } from "talk-server/models/comment";
|
||||
import { GQLMutationTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
|
||||
export interface CreateCommentInput extends ClientMutationProps {
|
||||
assetID: string;
|
||||
parentID?: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export interface CreateCommentPayload extends ClientMutationProps {
|
||||
comment: Comment;
|
||||
}
|
||||
|
||||
const Mutation = {
|
||||
createComment: async (
|
||||
source: void,
|
||||
input: CreateCommentInput,
|
||||
ctx: TenantContext
|
||||
): Promise<CreateCommentPayload> => ({
|
||||
const Mutation: GQLMutationTypeResolver<void> = {
|
||||
createComment: async (source, { input }, ctx) => ({
|
||||
comment: await ctx.mutators.Comment.create(input),
|
||||
clientMutationId: input.clientMutationId,
|
||||
}),
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import TenantContext from "talk-server/graph/tenant/context";
|
||||
import { GQLQueryTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types";
|
||||
|
||||
export default {
|
||||
asset: async (
|
||||
source: void,
|
||||
{ id }: { id: string; url: string },
|
||||
ctx: TenantContext
|
||||
) => ctx.loaders.Assets.asset.load(id),
|
||||
settings: async (parent: any, args: any, ctx: TenantContext) => ctx.tenant,
|
||||
const Query: GQLQueryTypeResolver<void> = {
|
||||
asset: (source, args, ctx) => ctx.loaders.Assets.asset.load(args.id),
|
||||
settings: (parent, args, ctx) => ctx.tenant,
|
||||
};
|
||||
|
||||
export default Query;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { IResolvers } from "graphql-tools";
|
||||
|
||||
import loadSchema from "talk-server/graph/common/schema";
|
||||
import resolvers from "talk-server/graph/tenant/resolvers";
|
||||
|
||||
export default function getTenantSchema() {
|
||||
return loadSchema("tenant", resolvers);
|
||||
return loadSchema("tenant", resolvers as IResolvers);
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ enum MODERATION_MODE {
|
||||
}
|
||||
|
||||
"""
|
||||
Wordlist describes all the available wordlists.
|
||||
WordlistSettings describes all the available wordlists.
|
||||
"""
|
||||
type Wordlist {
|
||||
type WordlistSettings {
|
||||
"""
|
||||
banned words will by default reject the comment if it is found.
|
||||
"""
|
||||
@@ -46,7 +46,20 @@ type Wordlist {
|
||||
}
|
||||
|
||||
# Settings stores the global settings for a given installation.
|
||||
|
||||
################################################################################
|
||||
## Settings
|
||||
################################################################################
|
||||
|
||||
"""
|
||||
Settings stores the global settings for a given Tenant.
|
||||
"""
|
||||
type Settings {
|
||||
"""
|
||||
domain is the domain that is associated with this Tenant.
|
||||
"""
|
||||
domain: String!
|
||||
|
||||
"""
|
||||
moderation is the moderation mode for all Asset's on the site.
|
||||
"""
|
||||
@@ -152,7 +165,7 @@ type Settings {
|
||||
"""
|
||||
wordlist will return a given list of words.
|
||||
"""
|
||||
wordlist: Wordlist!
|
||||
wordlist: WordlistSettings!
|
||||
|
||||
"""
|
||||
domains will return a given list of whitelisted domains.
|
||||
@@ -222,8 +235,8 @@ type Comment {
|
||||
replies will return the replies to this comment.
|
||||
"""
|
||||
replies(
|
||||
first: Int = 10
|
||||
orderBy: COMMENT_SORT = CREATED_AT_DESC
|
||||
first: Int! = 10
|
||||
orderBy: COMMENT_SORT! = CREATED_AT_DESC
|
||||
after: Cursor
|
||||
): CommentsConnection
|
||||
}
|
||||
@@ -299,8 +312,8 @@ type Asset {
|
||||
comments are the comments on the Asset.
|
||||
"""
|
||||
comments(
|
||||
first: Int = 10
|
||||
orderBy: COMMENT_SORT = CREATED_AT_DESC
|
||||
first: Int! = 10
|
||||
orderBy: COMMENT_SORT! = CREATED_AT_DESC
|
||||
after: Cursor
|
||||
): CommentsConnection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user