diff --git a/admin_api/admin_api.go b/admin_api/admin_api.go index 248c4a3..f09b9c3 100644 --- a/admin_api/admin_api.go +++ b/admin_api/admin_api.go @@ -92,25 +92,6 @@ func createSchema(db database.Database) (graphql.Schema, error) { return nil, nil }, }, - "createWebhook": &graphql.Field{ - Type: webhookType, - Description: "Create a new webhook", - Args: graphql.FieldConfigArgument{ - "type": &graphql.ArgumentConfig{ - Type: graphql.NewNonNull(graphql.String), - }, - }, - Resolve: func(params graphql.ResolveParams) (interface{}, error) { - webhook, err := db.CreateWebhook( - database.WebhookSender(params.Args["type"].(string)), - params.Source.(database.Pipeline).Id, - ) - if err != nil { - return nil, err - } - return webhook, nil - }, - }, "webhooks": &graphql.Field{ Type: graphql.NewNonNull(graphql.NewList(graphql.NewNonNull(webhookType))), Description: "The list of webhooks for the pipeline.", @@ -181,6 +162,34 @@ func createSchema(db database.Database) (graphql.Schema, error) { return pipeline, nil }, }, + "createWebhook": &graphql.Field{ + Type: webhookType, + Description: "Create a new webhook", + Args: graphql.FieldConfigArgument{ + "type": &graphql.ArgumentConfig{ + Type: graphql.NewNonNull(graphql.String), + }, + "pipeline_id": &graphql.ArgumentConfig{ + Type: graphql.NewNonNull(graphql.String), + }, + }, + Resolve: func(params graphql.ResolveParams) (interface{}, error) { + + id, err := uuid.Parse(params.Args["id"].(string)) + if err != nil { + return nil, err + } + + webhook, err := db.CreateWebhook( + database.WebhookSender(params.Args["type"].(string)), + id, + ) + if err != nil { + return nil, err + } + return webhook, nil + }, + }, }, })