feat(gql): limits set to max=100 and default=25 for streams, users, branches & commits. Additional changes as per PR #14.
This commit is contained in:
Родитель
e51345cb9e
Коммит
64279a867d
|
@ -30,6 +30,8 @@ module.exports = {
|
|||
Stream: {
|
||||
|
||||
async branches( parent, args, context, info ) {
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 items, please use pagination.' )
|
||||
let { items, cursor, totalCount } = await getBranchesByStreamId( { streamId: parent.id, limit: args.limit, cursor: args.cursor } )
|
||||
|
||||
return { totalCount, cursor, items }
|
||||
|
|
|
@ -32,6 +32,8 @@ module.exports = {
|
|||
Stream: {
|
||||
|
||||
async commits( parent, args, context, info ) {
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 items, please use pagination.' )
|
||||
let { commits: items, cursor } = await getCommitsByStreamId( { streamId: parent.id, limit: args.limit, cursor: args.cursor } )
|
||||
let totalCount = await getCommitsTotalCountByStreamId( { streamId: parent.id } )
|
||||
|
||||
|
@ -47,9 +49,10 @@ module.exports = {
|
|||
User: {
|
||||
|
||||
async commits( parent, args, context, info ) {
|
||||
|
||||
let publicOnly = context.userId !== parent.id
|
||||
let totalCount = await getCommitsTotalCountByUserId( { userId: parent.id } )
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 items, please use pagination.' )
|
||||
let { commits: items, cursor } = await getCommitsByUserId( { userId: parent.id, limit: args.limit, cursor: args.cursor, publicOnly } )
|
||||
|
||||
return { items, cursor, totalCount }
|
||||
|
@ -58,6 +61,8 @@ module.exports = {
|
|||
},
|
||||
Branch: {
|
||||
async commits( parent, args, context, info ) {
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 items, please use pagination.' )
|
||||
let { commits, cursor } = await getCommitsByBranchId( { branchId: parent.id, limit: args.limit, cursor: args.cursor } )
|
||||
let totalCount = await getCommitsTotalCountByBranchId( { branchId: parent.id } )
|
||||
|
||||
|
|
|
@ -27,25 +27,13 @@ module.exports = {
|
|||
await validateScopes( context.scopes, 'streams:read' )
|
||||
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 results.' )
|
||||
throw new UserInputError( 'Cannot return more than 100 items, please use pagination.' )
|
||||
|
||||
let totalCount = await getUserStreamsCount( {userId: context.userId, publicOnly: false} )
|
||||
let totalCount = await getUserStreamsCount({userId: context.userId, publicOnly: false, searchQuery: args.query} )
|
||||
|
||||
let {cursor, streams} = await getUserStreams( {userId: context.userId, limit: args.limit, cursor: args.cursor, publicOnly: false} )
|
||||
let {cursor, streams} = await getUserStreams({userId: context.userId, limit: args.limit, cursor: args.cursor, publicOnly: false, searchQuery: args.query} )
|
||||
return {totalCount, cursor: cursor, items: streams}
|
||||
},
|
||||
async streamSearch( parent, args, context, info ) {
|
||||
await validateScopes( context.scopes, 'streams:read' )
|
||||
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 results.' )
|
||||
|
||||
let totalCount = await getUserStreamsCount( {userId: context.userId, publicOnly: false, searchQuery: args.query} )
|
||||
|
||||
let {cursor, streams} = await getUserStreams( {userId: context.userId, limit: args.limit, cursor: args.cursor, publicOnly: false, searchQuery: args.query} )
|
||||
return {totalCount, cursor: cursor, items: streams}
|
||||
}
|
||||
},
|
||||
Stream: {
|
||||
|
||||
async collaborators( parent, args, context, info ) {
|
||||
|
@ -58,7 +46,7 @@ module.exports = {
|
|||
|
||||
async streams( parent, args, context, info ) {
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 results.' )
|
||||
throw new UserInputError( 'Cannot return more than 100 items, please use pagination.' )
|
||||
// Return only the user's public streams if parent.id !== context.userId
|
||||
let publicOnly = parent.id !== context.userId
|
||||
let totalCount = await getUserStreamsCount( { userId: parent.id, publicOnly } )
|
||||
|
|
|
@ -39,7 +39,7 @@ module.exports = {
|
|||
|
||||
|
||||
if ( args.limit && args.limit > 100 )
|
||||
throw new UserInputError( 'Cannot return more than 100 results.' )
|
||||
throw new UserInputError( 'Cannot return more than 100 items, please use pagination.' )
|
||||
|
||||
let {cursor, users} = await searchUsers( args.query, args.limit, args.cursor )
|
||||
return {cursor: cursor, items: users}
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
extend type Stream {
|
||||
commits( limit: Int! = 20, cursor: String ): CommitCollection
|
||||
commits( limit: Int! = 25, cursor: String ): CommitCollection
|
||||
commit( id: String! ): Commit
|
||||
branches( limit: Int! = 100, cursor: String ): BranchCollection
|
||||
branches( limit: Int! = 25, cursor: String ): BranchCollection
|
||||
branch( name: String! ): Branch
|
||||
}
|
||||
|
||||
extend type User {
|
||||
commits( limit: Int! = 20, cursor: String ): CommitCollectionUser
|
||||
commits( limit: Int! = 25, cursor: String ): CommitCollectionUser
|
||||
}
|
||||
|
||||
type Branch {
|
||||
|
@ -14,7 +14,7 @@ type Branch {
|
|||
name: String!
|
||||
author: User!
|
||||
description: String!
|
||||
commits( limit: Int! = 20, cursor: String ): CommitCollection
|
||||
commits( limit: Int! = 25, cursor: String ): CommitCollection
|
||||
}
|
||||
|
||||
type Commit {
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
extend type Query {
|
||||
stream( id: String! ): Stream
|
||||
streams( limit: Int! = 100, cursor: String ): StreamCollection
|
||||
streamSearch( query: String!, limit: Int! = 100, cursor: String ): StreamCollection
|
||||
"""
|
||||
All the streams of the current user, pass in the `query` parameter to seach by name, description or ID.
|
||||
"""
|
||||
streams( query: String!, limit: Int! = 25, cursor: String ): StreamCollection
|
||||
}
|
||||
|
||||
type Stream {
|
||||
|
@ -18,7 +20,7 @@ extend type User {
|
|||
"""
|
||||
All the streams that a user has access to.
|
||||
"""
|
||||
streams( limit: Int! = 20, cursor: String ): StreamCollection
|
||||
streams( limit: Int! = 25, cursor: String ): StreamCollection
|
||||
}
|
||||
|
||||
type StreamCollaborator {
|
||||
|
|
|
@ -3,7 +3,7 @@ extend type Query {
|
|||
Gets the profile of a user. If no id argument is provided, will return the current authenticated user's profile (as extracted from the authorization header).
|
||||
"""
|
||||
user( id: String ): User
|
||||
userSearch( query: String!, limit: Int! = 100, cursor: String ): UserSearchResultCollection
|
||||
userSearch( query: String!, limit: Int! = 25, cursor: String ): UserSearchResultCollection
|
||||
userPwdStrength( pwd: String! ): JSONObject
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,6 @@ type UserSearchResult {
|
|||
company: String
|
||||
avatar: String
|
||||
verified: Boolean
|
||||
profiles: JSONObject
|
||||
role: String
|
||||
}
|
||||
|
||||
extend type Mutation {
|
||||
|
|
|
@ -6,50 +6,50 @@ exports.up = async knex => {
|
|||
debug( 'Setting up core module scopes.' )
|
||||
|
||||
let coreModuleScopes = [ {
|
||||
name: 'server:setup',
|
||||
description: 'Edit server information.'
|
||||
},
|
||||
{
|
||||
name: 'tokens:read',
|
||||
description: `Access your api tokens.`
|
||||
},
|
||||
{
|
||||
name: 'tokens:write',
|
||||
description: `Create and delete api tokens on your behalf.`
|
||||
},
|
||||
{
|
||||
name: 'apps:authorize',
|
||||
description: 'Grant third party applications access rights on your behalf to the api.'
|
||||
},
|
||||
{
|
||||
name: 'apps:create',
|
||||
description: 'Register a third party application.'
|
||||
},
|
||||
{
|
||||
name: 'streams:read',
|
||||
description: 'Read your streams & and any associated information (branches, tags, comments, objects, etc.)'
|
||||
},
|
||||
{
|
||||
name: 'streams:write',
|
||||
description: 'Create streams on your behalf and read your streams & any associated information (any associated information (branches, tags, comments, objects, etc.)'
|
||||
},
|
||||
{
|
||||
name: 'profile:read',
|
||||
description: `Read your profile information`
|
||||
},
|
||||
{
|
||||
name: 'profile:email',
|
||||
description: `Access your email.`
|
||||
},
|
||||
name: 'server:setup',
|
||||
description: 'Edit server information.'
|
||||
},
|
||||
{
|
||||
name: 'tokens:read',
|
||||
description: `Access your api tokens.`
|
||||
},
|
||||
{
|
||||
name: 'tokens:write',
|
||||
description: `Create and delete api tokens on your behalf.`
|
||||
},
|
||||
{
|
||||
name: 'apps:authorize',
|
||||
description: 'Grant third party applications access rights on your behalf to the api.'
|
||||
},
|
||||
{
|
||||
name: 'apps:create',
|
||||
description: 'Register a third party application.'
|
||||
},
|
||||
{
|
||||
name: 'streams:read',
|
||||
description: 'Read your streams & and any associated information (branches, tags, comments, objects, etc.)'
|
||||
},
|
||||
{
|
||||
name: 'streams:write',
|
||||
description: 'Create streams on your behalf and read your streams & any associated information (any associated information (branches, tags, comments, objects, etc.)'
|
||||
},
|
||||
{
|
||||
name: 'profile:read',
|
||||
description: `Read your profile information`
|
||||
},
|
||||
{
|
||||
name: 'profile:email',
|
||||
description: `Access your email.`
|
||||
},
|
||||
|
||||
{
|
||||
name: 'users:read',
|
||||
description: `Read other users' profile on your behalf.`
|
||||
},
|
||||
{
|
||||
name: 'users:email',
|
||||
description: 'Access the emails of other users.'
|
||||
}
|
||||
{
|
||||
name: 'users:read',
|
||||
description: `Read other users' profile on your behalf.`
|
||||
},
|
||||
{
|
||||
name: 'users:email',
|
||||
description: 'Access the emails of other users.'
|
||||
}
|
||||
]
|
||||
|
||||
await knex( 'scopes' ).insert( coreModuleScopes )
|
||||
|
|
|
@ -31,7 +31,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
async getBranchesByStreamId( { streamId, limit, cursor } ) {
|
||||
limit = limit || 100
|
||||
limit = limit || 25
|
||||
let query = Branches( ).select( '*' ).where( { streamId: streamId } )
|
||||
|
||||
if ( cursor )
|
||||
|
|
|
@ -15,7 +15,6 @@ const { getBranchesByStreamId, getBranchByNameAndStreamId } = require( './branch
|
|||
module.exports = {
|
||||
|
||||
async createCommitByBranchId( { streamId, branchId, objectId, authorId, message, previousCommitIds } ) {
|
||||
|
||||
// Create main table entry
|
||||
let [ id ] = await Commits( ).returning( 'id' ).insert( {
|
||||
id: crs( { length: 10 } ),
|
||||
|
@ -84,7 +83,7 @@ module.exports = {
|
|||
},
|
||||
|
||||
async getCommitsByBranchId( { branchId, limit, cursor } ) {
|
||||
limit = limit || 20
|
||||
limit = limit || 25
|
||||
let query = BranchCommits( ).columns( [ { id: 'commitId' }, 'message', 'referencedObject', { authorName: 'name' }, { authorId: 'users.id' }, 'commits.createdAt' ] ).select( )
|
||||
.join( 'commits', 'commits.id', 'branch_commits.commitId' )
|
||||
.join( 'users', 'commits.author', 'users.id' )
|
||||
|
@ -124,7 +123,7 @@ module.exports = {
|
|||
* @return {[type]} [description]
|
||||
*/
|
||||
async getCommitsByStreamId( { streamId, limit, cursor } ) {
|
||||
limit = limit || 20
|
||||
limit = limit || 25
|
||||
let query = StreamCommits( )
|
||||
.columns( [ { id: 'commitId' }, 'message', 'referencedObject', { authorName: 'name' }, { authorId: 'users.id' }, 'commits.createdAt' ] ).select( )
|
||||
.join( 'commits', 'commits.id', 'stream_commits.commitId' )
|
||||
|
@ -142,15 +141,15 @@ module.exports = {
|
|||
},
|
||||
|
||||
async getCommitsByUserId( { userId, limit, cursor, publicOnly } ) {
|
||||
limit = limit || 20
|
||||
limit = limit || 25
|
||||
publicOnly = publicOnly !== false
|
||||
|
||||
let query =
|
||||
Commits( )
|
||||
.columns( [ { id: 'commitId' }, 'message', 'referencedObject', 'commits.createdAt', { streamId: 'stream_commits.streamId' }, { streamName: 'streams.name' } ] ).select( )
|
||||
.join( 'stream_commits', 'commits.id', 'stream_commits.commitId' )
|
||||
.join( 'streams', 'stream_commits.streamId', 'streams.id' )
|
||||
.where( 'author', userId )
|
||||
.columns( [ { id: 'commitId' }, 'message', 'referencedObject', 'commits.createdAt', { streamId: 'stream_commits.streamId' }, { streamName: 'streams.name' } ] ).select( )
|
||||
.join( 'stream_commits', 'commits.id', 'stream_commits.commitId' )
|
||||
.join( 'streams', 'stream_commits.streamId', 'streams.id' )
|
||||
.where( 'author', userId )
|
||||
|
||||
if ( publicOnly )
|
||||
query.andWhere( 'streams.isPublic', true )
|
||||
|
|
|
@ -89,10 +89,10 @@ module.exports = {
|
|||
return await Streams( ).where( { id: streamId } ).del( )
|
||||
},
|
||||
|
||||
async getUserStreams( {userId, limit, cursor, publicOnly, searchQuery } ) {
|
||||
limit = limit || 100
|
||||
async getUserStreams( { userId, limit, cursor, publicOnly, searchQuery } ) {
|
||||
limit = limit || 25
|
||||
publicOnly = publicOnly !== false //defaults to true if not provided
|
||||
let likeQuery = "%" + searchQuery + "%"
|
||||
|
||||
let query = Acl( )
|
||||
.columns( [ { id: 'streams.id' }, 'name', 'description', 'isPublic', 'createdAt', 'updatedAt', 'role' ] ).select( )
|
||||
.join( 'streams', 'stream_acl.resourceId', 'streams.id' )
|
||||
|
@ -106,9 +106,9 @@ module.exports = {
|
|||
|
||||
if ( searchQuery )
|
||||
query.andWhere( function () {
|
||||
this.where( 'name', 'ILIKE', likeQuery )
|
||||
.orWhere( 'description', 'ILIKE', likeQuery )
|
||||
.orWhere( 'id', 'ILIKE', likeQuery ) //potentially useless?
|
||||
this.where( 'name', 'ILIKE', `%${ searchQuery }%` )
|
||||
.orWhere( 'description', 'ILIKE', `%${searchQuery}%` )
|
||||
.orWhere( 'id', 'ILIKE', `%${searchQuery}%` ) //potentially useless?
|
||||
} )
|
||||
|
||||
query.orderBy( 'streams.updatedAt', 'desc' ).limit( limit )
|
||||
|
@ -119,7 +119,7 @@ module.exports = {
|
|||
|
||||
async getUserStreamsCount( {userId, publicOnly, searchQuery } ) {
|
||||
publicOnly = publicOnly !== false //defaults to true if not provided
|
||||
let likeQuery = "%" + searchQuery + "%"
|
||||
|
||||
let query = Acl( ).count( )
|
||||
.join( 'streams', 'stream_acl.resourceId', 'streams.id' )
|
||||
.where( { userId: userId } )
|
||||
|
@ -129,9 +129,9 @@ module.exports = {
|
|||
|
||||
if ( searchQuery )
|
||||
query.andWhere( function () {
|
||||
this.where( 'name', 'ILIKE', likeQuery )
|
||||
.orWhere( 'description', 'ILIKE', likeQuery )
|
||||
.orWhere( 'id', 'ILIKE', likeQuery ) //potentially useless?
|
||||
this.where( 'name', 'ILIKE', `%${searchQuery}%` )
|
||||
.orWhere( 'description', 'ILIKE', `%${searchQuery}%` )
|
||||
.orWhere( 'id', 'ILIKE', `%${searchQuery}%` ) //potentially useless?
|
||||
} )
|
||||
|
||||
let [ res ] = await query
|
||||
|
|
|
@ -83,13 +83,14 @@ module.exports = {
|
|||
},
|
||||
|
||||
async searchUsers( searchQuery, limit, cursor ) {
|
||||
limit = limit || 100
|
||||
let likeQuery = "%" + searchQuery + "%"
|
||||
limit = limit || 25
|
||||
|
||||
let query = Users()
|
||||
.where( function () {
|
||||
this.where( {email: searchQuery} ) //match full email or partial username / name
|
||||
.orWhere( 'username', 'ILIKE', likeQuery )
|
||||
.orWhere( 'name', 'ILIKE', likeQuery )
|
||||
.select( 'id username name bio company verified avatar' )
|
||||
.where( queryBuilder => {
|
||||
queryBuilder.where( {email: searchQuery} ) //match full email or partial username / name
|
||||
queryBuilder.orWhere( 'username', 'ILIKE', `%${searchQuery}%` )
|
||||
queryBuilder.orWhere( 'name', 'ILIKE', `%${searchQuery}%` )
|
||||
} )
|
||||
|
||||
if ( cursor )
|
||||
|
|
Загрузка…
Ссылка в новой задаче