Skip to content

Commit

Permalink
feat(gql): (re-)implemented some commits & re-organized gql tests
Browse files Browse the repository at this point in the history
  • Loading branch information
didimitrie committed Jul 19, 2020
1 parent 13b6ccb commit 9715129
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 187 deletions.
35 changes: 31 additions & 4 deletions modules/core/graph/resolvers/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const {
createCommitByBranchId,
updateCommit,
deleteCommit,
getCommitById,
getCommitsByBranchId,
getCommitsByBranchName,
getCommitsByUserId,
Expand All @@ -26,33 +27,59 @@ const {
module.exports = {
Query: {},
Stream: {

async commit( parent, args, context, info ) {
throw new ApolloError( 'not implemented' )
}

},
User: {

async commits( parent, args, context, info ) {
// TODO
throw new ApolloError( 'not implemented' )
}

},
Branch: {

async commits( parent, args, context, info ) {
throw new ApolloError( 'not implemented' )
}

},
Mutation: {

async commitCreate( parent, args, context, info ) {
throw new ApolloError('not implemented')
await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'streams:write' )
await authorizeResolver( context.userId, args.commit.streamId, 'stream:contributor' )

return await createCommitByBranchName( { ...args.commit, authorId: context.userId } )
},

async commitUpdate( parent, args, context, info ) {
throw new ApolloError('not implemented')
await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'streams:write' )
await authorizeResolver( context.userId, args.commit.streamId, 'stream:contributor' )

let commit = await getCommitById( { id: args.commit.id } )
if ( commit.author !== context.userId )
throw new AuthorizationError( 'Only the author of a commit may update it.' )

return await updateCommit( { ...args.commit } )
},

async commitDelete( parent, args, context, info ) {
throw new ApolloError('not implemented')

await validateServerRole( context, 'server:user' )
await validateScopes( context.scopes, 'streams:write' )
await authorizeResolver( context.userId, args.commit.streamId, 'stream:contributor' )

let commit = await getCommitById( { id: args.commit.id } )
if ( commit.author !== context.userId )
throw new AuthorizationError( 'Only the author of a commit may delete it.' )

return await deleteCommit( { id: args.commit.id } )
}
}
}
3 changes: 2 additions & 1 deletion modules/core/graph/schemas/branchesAndCommits.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ input BranchDeleteInput {
input CommitCreateInput {
streamId: String!
branchName: String!
objectReference: String!
objectId: String!
message: String
previousCommitIds: [String]
}

input CommitUpdateInput {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/migrations/000-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,8 @@ exports.up = async knex => {
// - one ancestor (simple sequential push)
// - more ancestors (result of a merge)
await knex.schema.createTable( 'parent_commits', table => {
table.string( 'parent', 10 ).references( 'id' ).inTable( 'commits' ).notNullable( )
table.string( 'child', 10 ).references( 'id' ).inTable( 'commits' ).notNullable( )
table.string( 'parent', 10 ).references( 'id' ).inTable( 'commits' ).notNullable( ).onDelete( 'cascade' )
table.string( 'child', 10 ).references( 'id' ).inTable( 'commits' ).notNullable( ).onDelete( 'cascade' )
table.unique( [ 'parent', 'child' ], 'commit_parent_child_index' )
} )

Expand Down
5 changes: 4 additions & 1 deletion modules/core/services/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ module.exports = {
},

async updateStream( { streamId, name, description } ) {
let [ res ] = await Streams( ).returning( 'id' ).where( { id: streamId } ).update( { name, description } )
let [ res ] = await Streams( )
.returning( 'id' )
.where( { id: streamId } )
.update( { name, description } )
return res
},

Expand Down
Loading

0 comments on commit 9715129

Please sign in to comment.