Skip to content

Commit

Permalink
feat: add filtering and pagination to subjects
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailswift committed Oct 12, 2022
1 parent 984c8d3 commit c2bda49
Show file tree
Hide file tree
Showing 9 changed files with 975 additions and 117 deletions.
62 changes: 28 additions & 34 deletions cmd/archivistctl/cmd/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,13 @@ func init() {
}

func printSubjects(results retrieveSubjectResults) {
for _, edge := range results.Dsses.Edges {
for _, subject := range edge.Node.Statement.Subjects {
digestStrings := make([]string, 0, len(subject.SubjectDigest))
for _, digest := range subject.SubjectDigest {
digestStrings = append(digestStrings, fmt.Sprintf("%s:%s", digest.Algorithm, digest.Value))
}

fmt.Printf("Name: %s\nDigests: %s\n", subject.Name, strings.Join(digestStrings, ", "))
for _, edge := range results.Subjects.Edges {
digestStrings := make([]string, 0, len(edge.Node.SubjectDigests))
for _, digest := range edge.Node.SubjectDigests {
digestStrings = append(digestStrings, fmt.Sprintf("%s:%s", digest.Algorithm, digest.Value))
}

fmt.Printf("Name: %s\nDigests: %s\n", edge.Node.Name, strings.Join(digestStrings, ", "))
}
}

Expand All @@ -103,41 +101,37 @@ type retrieveSubjectVars struct {
}

type retrieveSubjectResults struct {
Dsses struct {
Subjects struct {
Edges []struct {
Node struct {
Statement struct {
Subjects []struct {
Name string `json:"name"`
SubjectDigest []struct {
Algorithm string `json:"algorithm"`
Value string `json:"value"`
} `json:"subject_digest"`
} `json:"subjects"`
} `json:"statement"`
Name string `json:"name"`
SubjectDigests []struct {
Algorithm string `json:"algorithm"`
Value string `json:"value"`
} `json:"subjectDigests"`
} `json:"node"`
} `json:"edges"`
} `json:"dsses"`
} `json:"subjects"`
}

const retrieveSubjectsQuery = `query($gitoid: String!) {
dsses(
subjects(
where: {
gitoidSha256: $gitoid
hasStatementWith:{
hasDsseWith:{
gitoidSha256: $gitoid
}
}
}
) {
edges {
node {
statement {
subjects {
name
subject_digest {
algorithm
value
}
}
}
}
}
}
node{
name
subjectDigests{
algorithm
value
}
}
}
}
}`
8 changes: 4 additions & 4 deletions cmd/archivistctl/cmd/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ type searchResults struct {
Dsses struct {
Edges []struct {
Node struct {
GitoidSha256 string `json:"gitoid_sha256"`
GitoidSha256 string `json:"gitoidSha256"`
Statement struct {
AttestationCollection struct {
Name string `json:"name"`
Attestations []struct {
Type string `json:"type"`
} `json:"attestations"`
} `json:"attestation_collection"`
} `json:"attestationCollections"`
} `json:"statement"`
} `json:"node"`
} `json:"edges"`
Expand All @@ -124,9 +124,9 @@ const searchQuery = `query($algo: String!, $digest: String!) {
) {
edges {
node {
gitoid_sha256
gitoidSha256
statement {
attestation_collection {
attestationCollections {
name
attestations {
type
Expand Down
49 changes: 48 additions & 1 deletion ent.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ type Query {
"""Filtering options for Dsses returned from the connection."""
where: DsseWhereInput
): DsseConnection!
subjects(
"""Returns the elements in the list that come after the specified cursor."""
after: Cursor

"""Returns the first _n_ elements from the list."""
first: Int

"""Returns the elements in the list that come before the specified cursor."""
before: Cursor

"""Returns the last _n_ elements from the list."""
last: Int

"""Filtering options for Subjects returned from the connection."""
where: SubjectWhereInput
): SubjectConnection!
}
type Signature implements Node {
id: ID!
Expand Down Expand Up @@ -338,7 +354,22 @@ input SignatureWhereInput {
type Statement implements Node {
id: ID!
predicate: String!
subjects: [Subject!]
subjects(
"""Returns the elements in the list that come after the specified cursor."""
after: Cursor

"""Returns the first _n_ elements from the list."""
first: Int

"""Returns the elements in the list that come before the specified cursor."""
before: Cursor

"""Returns the last _n_ elements from the list."""
last: Int

"""Filtering options for Subjects returned from the connection."""
where: SubjectWhereInput
): SubjectConnection!
attestationCollections: AttestationCollection
dsse: [Dsse!]
}
Expand Down Expand Up @@ -389,6 +420,15 @@ type Subject implements Node {
subjectDigests: [SubjectDigest!]
statement: Statement
}
"""A connection to a list of items."""
type SubjectConnection {
"""A list of edges."""
edges: [SubjectEdge]
"""Information to aid in pagination."""
pageInfo: PageInfo!
"""Identifies the total count of items in the connection."""
totalCount: Int!
}
type SubjectDigest implements Node {
id: ID!
algorithm: String!
Expand Down Expand Up @@ -444,6 +484,13 @@ input SubjectDigestWhereInput {
hasSubject: Boolean
hasSubjectWith: [SubjectWhereInput!]
}
"""An edge in a connection."""
type SubjectEdge {
"""The item at the end of the edge."""
node: Subject
"""A cursor for use in pagination."""
cursor: Cursor!
}
"""
SubjectWhereInput is used for filtering Subject objects.
Input was generated by ent.
Expand Down
18 changes: 18 additions & 0 deletions ent.resolvers.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// Copyright 2022 The Archivist Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package archivist

// This file will be automatically regenerated based on the schema, any resolver implementations
Expand All @@ -21,6 +35,10 @@ func (r *queryResolver) Dsses(ctx context.Context, after *ent.Cursor, first *int
return r.client.Dsse.Query().Paginate(ctx, after, first, before, last, ent.WithDsseFilter(where.Filter))
}

func (r *queryResolver) Subjects(ctx context.Context, after *ent.Cursor, first *int, before *ent.Cursor, last *int, where *ent.SubjectWhereInput) (*ent.SubjectConnection, error) {
return r.client.Subject.Query().Paginate(ctx, after, first, before, last, ent.WithSubjectFilter(where.Filter))
}

// Query returns QueryResolver implementation.
func (r *Resolver) Query() QueryResolver { return &queryResolver{r} }

Expand Down
93 changes: 92 additions & 1 deletion ent/gql_collection.go

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

Loading

0 comments on commit c2bda49

Please sign in to comment.