Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add componentInstances to componentVersion #97

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/api/graphql/gqlgen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ models:
resolver: true
issues:
resolver: true
componentInstances:
resolver: true
Service:
fields:
owners:
Expand Down
10 changes: 7 additions & 3 deletions internal/api/graphql/graph/baseResolver/component_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func ComponentInstanceBaseResolver(app app.Heureka, ctx context.Context, filter

var imId []*int64
var serviceId []*int64
var copmonentVersionId []*int64
if parent != nil {
parentId := parent.Parent.GetID()
pid, err := ParseCursor(&parentId)
Expand All @@ -80,6 +81,8 @@ func ComponentInstanceBaseResolver(app app.Heureka, ctx context.Context, filter
imId = []*int64{pid}
case model.ServiceNodeName:
serviceId = []*int64{pid}
case model.ComponentVersionNodeName:
copmonentVersionId = []*int64{pid}
}
}

Expand All @@ -88,9 +91,10 @@ func ComponentInstanceBaseResolver(app app.Heureka, ctx context.Context, filter
}

f := &entity.ComponentInstanceFilter{
Paginated: entity.Paginated{First: first, After: afterId},
IssueMatchId: imId,
ServiceId: serviceId,
Paginated: entity.Paginated{First: first, After: afterId},
IssueMatchId: imId,
ServiceId: serviceId,
ComponentVersionId: copmonentVersionId,
}

opt := GetListOptions(requestedFields)
Expand Down
149 changes: 144 additions & 5 deletions internal/api/graphql/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions internal/api/graphql/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ query ($filter: ComponentVersionFilter, $first: Int, $after: String) {
nextPageAfter
}
}
componentInstances {
totalCount
edges {
node {
id
ccrn
componentVersionId
}
}
}
}
cursor
}
Expand Down
8 changes: 8 additions & 0 deletions internal/api/graphql/graph/resolver/component_version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type ComponentVersion implements Node {
componentId: String
component: Component
issues(first: Int, after: String): IssueConnection
componentInstances(first: Int, after: String): ComponentInstanceConnection
}

input ComponentVersionInput {
Expand Down
2 changes: 2 additions & 0 deletions internal/database/mariadb/component_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func (s *SqlDatabase) getComponentInstanceFilterString(filter *entity.ComponentI
fl = append(fl, buildFilterQuery(filter.Id, "CI.componentinstance_id = ?", OP_OR))
fl = append(fl, buildFilterQuery(filter.IssueMatchId, "IM.issuematch_id = ?", OP_OR))
fl = append(fl, buildFilterQuery(filter.ServiceId, "CI.componentinstance_service_id = ?", OP_OR))
fl = append(fl, buildFilterQuery(filter.ComponentVersionId, "CI.componentinstance_component_version_id = ?", OP_OR))
fl = append(fl, "CI.componentinstance_deleted_at IS NULL")

filterStr := combineFilterQueries(fl, OP_AND)
Expand Down Expand Up @@ -113,6 +114,7 @@ func (s *SqlDatabase) buildComponentInstanceStatement(baseQuery string, filter *
filterParameters = buildQueryParameters(filterParameters, filter.Id)
filterParameters = buildQueryParameters(filterParameters, filter.IssueMatchId)
filterParameters = buildQueryParameters(filterParameters, filter.ServiceId)
filterParameters = buildQueryParameters(filterParameters, filter.ComponentVersionId)
if withCursor {
filterParameters = append(filterParameters, cursor.Value)
filterParameters = append(filterParameters, cursor.Limit)
Expand Down
26 changes: 26 additions & 0 deletions internal/database/mariadb/component_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@ var _ = Describe("ComponentInstance - ", Label("database", "ComponentInstance"),
Expect(entries[0]).To(BeEquivalentTo(ciId))
})
})
It("can filter by a single componentVersion id that does exist", func() {
// select a component version
cvRow := seedCollection.ComponentVersionRows[rand.Intn(len(seedCollection.ComponentVersionRows))]

// collect all componentInstance ids that belong to the component version
ciIds := []int64{}
for _, ciRow := range seedCollection.ComponentInstanceRows {
if ciRow.ComponentVersionId.Int64 == cvRow.Id.Int64 {
ciIds = append(ciIds, ciRow.ServiceId.Int64)
}
}

filter := &entity.ComponentInstanceFilter{
ComponentVersionId: []*int64{&cvRow.Id.Int64},
}

entries, err := db.GetAllComponentInstanceIds(filter)

By("throwing no error", func() {
Expect(err).To(BeNil())
})

By("returning expected elements", func() {
Expect(len(entries)).To(BeEquivalentTo(len(ciIds)))
})
})
})
})
})
Expand Down
8 changes: 8 additions & 0 deletions internal/e2e/component_version_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ var _ = Describe("Getting ComponentVersions via API", Label("e2e", "ComponentVer
Expect(issueFound).To(BeTrue(), "attached issue does exist and belongs to componentVersion")
}

for _, ci := range cv.Node.ComponentInstances.Edges {
Expect(ci.Node.ID).ToNot(BeNil(), "componentInstance has a ID set")
Expect(ci.Node.Ccrn).ToNot(BeNil(), "componentInstance has ccrn set")

Expect(*ci.Node.ComponentVersionID).To(BeEquivalentTo(cv.Node.ID))

}

if cv.Node.Component != nil {
Expect(cv.Node.Component.ID).ToNot(BeNil(), "component has a ID set")
Expect(cv.Node.Component.Name).ToNot(BeNil(), "component has a name set")
Expand Down
7 changes: 4 additions & 3 deletions internal/entity/component_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import "time"

type ComponentInstanceFilter struct {
Paginated
IssueMatchId []*int64 `json:"issue_match_id"`
ServiceId []*int64 `json:"service_id"`
Id []*int64 `json:"id"`
IssueMatchId []*int64 `json:"issue_match_id"`
ServiceId []*int64 `json:"service_id"`
ComponentVersionId []*int64 `json:"component_version_id"`
Id []*int64 `json:"id"`
}

type ComponentInstanceAggregations struct{}
Expand Down
Loading