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 25433c8 commit e2f6a15
Show file tree
Hide file tree
Showing 7 changed files with 943 additions and 79 deletions.
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.

79 changes: 73 additions & 6 deletions ent/gql_edge.go

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

3 changes: 2 additions & 1 deletion ent/schema/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package schema

import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
Expand All @@ -36,7 +37,7 @@ func (Statement) Fields() []ent.Field {
// Edges of the Statement.
func (Statement) Edges() []ent.Edge {
return []ent.Edge{
edge.To("subjects", Subject.Type),
edge.To("subjects", Subject.Type).Annotations(entgql.RelayConnection()),
edge.To("attestation_collections", AttestationCollection.Type).Unique(),

edge.From("dsse", Dsse.Type).Ref("statement"),
Expand Down
9 changes: 9 additions & 0 deletions ent/schema/subject.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
package schema

import (
"entgo.io/contrib/entgql"
"entgo.io/ent"
"entgo.io/ent/schema"
"entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field"
"entgo.io/ent/schema/index"
Expand Down Expand Up @@ -49,3 +51,10 @@ func (Subject) Indexes() []ent.Index {
index.Fields("name"),
}
}

func (Subject) Annotations() []schema.Annotation {
return []schema.Annotation{
entgql.RelayConnection(),
entgql.QueryField(),
}
}
Loading

0 comments on commit e2f6a15

Please sign in to comment.