feat: asset url query

This commit is contained in:
Wyatt Johnson
2018-07-10 13:11:32 -06:00
parent 093e4fd736
commit c0da4e97aa
5 changed files with 144 additions and 47 deletions
@@ -1,8 +1,15 @@
import DataLoader from "dataloader";
import TenantContext from "talk-server/graph/tenant/context";
import { Asset, retrieveManyAssets } from "talk-server/models/asset";
import {
Asset,
findOrCreateAsset,
FindOrCreateAssetInput,
retrieveManyAssets,
} from "talk-server/models/asset";
export default (ctx: TenantContext) => ({
findOrCreate: (input: FindOrCreateAssetInput) =>
findOrCreateAsset(ctx.db, ctx.tenant.id, input),
asset: new DataLoader<string, Asset | null>(ids =>
retrieveManyAssets(ctx.db, ctx.tenant.id, ids)
),
@@ -4,6 +4,7 @@ import Context from "talk-server/graph/tenant/context";
import {
AssetToCommentsArgs,
CommentToRepliesArgs,
GQLCOMMENT_SORT,
} from "talk-server/graph/tenant/schema/__generated__/types";
import {
retrieveCommentAssetConnection,
@@ -15,14 +16,33 @@ export default (ctx: Context) => ({
comment: new DataLoader((ids: string[]) =>
retrieveManyComments(ctx.db, ctx.tenant.id, ids)
),
forAsset: (assetID: string, input: AssetToCommentsArgs) =>
retrieveCommentAssetConnection(ctx.db, ctx.tenant.id, assetID, input),
forParent: (assetID: string, parentID: string, input: CommentToRepliesArgs) =>
retrieveCommentRepliesConnection(
ctx.db,
ctx.tenant.id,
assetID,
parentID,
input
),
forAsset: (
assetID: string,
// Apply the graph schema defaults at the loader.
{
first = 10,
orderBy = GQLCOMMENT_SORT.CREATED_AT_DESC,
after,
}: AssetToCommentsArgs
) =>
retrieveCommentAssetConnection(ctx.db, ctx.tenant.id, assetID, {
first,
orderBy,
after,
}),
forParent: (
assetID: string,
parentID: string,
// Apply the graph schema defaults at the loader.
{
first = 10,
orderBy = GQLCOMMENT_SORT.CREATED_AT_DESC,
after,
}: CommentToRepliesArgs
) =>
retrieveCommentRepliesConnection(ctx.db, ctx.tenant.id, assetID, parentID, {
first,
orderBy,
after,
}),
});
@@ -1,7 +1,7 @@
import { GQLQueryTypeResolver } from "talk-server/graph/tenant/schema/__generated__/types";
const Query: GQLQueryTypeResolver<void> = {
asset: (source, args, ctx) => ctx.loaders.Assets.asset.load(args.id),
asset: (source, args, ctx) => ctx.loaders.Assets.findOrCreate(args),
settings: (parent, args, ctx) => ctx.tenant,
};
@@ -382,8 +382,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
}
@@ -459,8 +459,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
@@ -533,7 +533,7 @@ type Query {
"""
asset is the Asset specified by its ID.
"""
asset(id: ID!): Asset
asset(id: ID, url: String!): Asset
"""
me is the current logged in User.