Skip to content

Commit

Permalink
GraphQL: Add timestamps (#675)
Browse files Browse the repository at this point in the history
* feat: add timestamps to graphql types

* chore: add in a default page size of 25 and update graphql tests to include querying for timestamps.
  • Loading branch information
ericenns authored Jul 26, 2024
1 parent 05b7bc6 commit edfde24
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/graphql/irida_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class IridaSchema < GraphQL::Schema # rubocop:disable GraphQL/ObjectDescription

max_depth 15
max_complexity 550
default_page_size 25
default_max_page_size 100

# GraphQL-Ruby calls this when something goes wrong while running a query:
Expand Down
69 changes: 67 additions & 2 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ type Attachment implements Node {
byteSize: Int!

"""
Attachment creation date
Datetime of creation.
"""
createdAt: String!
createdAt: ISO8601DateTime!

"""
Attachment file name
Expand All @@ -91,6 +91,11 @@ type Attachment implements Node {
Persistent Unique Identifier of the attachment. For example, `INXT_ATT_AAAAAAAAAAAA`.
"""
puid: ID!

"""
Datetime of last update.
"""
updatedAt: ISO8601DateTime!
}

"""
Expand Down Expand Up @@ -257,6 +262,11 @@ type DirectUpload {
A group
"""
type Group implements Node {
"""
Datetime of creation.
"""
createdAt: ISO8601DateTime!

"""
List of descendant groups of this group.
"""
Expand Down Expand Up @@ -357,6 +367,11 @@ type Group implements Node {
`INXT_GRP_AAAAAAAAAA`.
"""
puid: ID!

"""
Datetime of last update.
"""
updatedAt: ISO8601DateTime!
}

"""
Expand Down Expand Up @@ -399,6 +414,11 @@ type GroupEdge {
node: Group
}

"""
An ISO 8601-encoded datetime
"""
scalar ISO8601DateTime @specifiedBy(url: "https://tools.ietf.org/html/rfc3339")

"""
Represents untyped JSON
"""
Expand Down Expand Up @@ -453,6 +473,11 @@ type Mutation {
A namespace
"""
type Namespace implements Node {
"""
Datetime of creation.
"""
createdAt: ISO8601DateTime!

"""
Description of the namespace.
"""
Expand Down Expand Up @@ -518,6 +543,11 @@ type Namespace implements Node {
`INXT_GRP_AAAAAAAAAA`.
"""
puid: ID!

"""
Datetime of last update.
"""
updatedAt: ISO8601DateTime!
}

"""
Expand Down Expand Up @@ -559,6 +589,11 @@ type PageInfo {
A project
"""
type Project implements Node {
"""
Datetime of creation.
"""
createdAt: ISO8601DateTime!

"""
Description of the project.
"""
Expand Down Expand Up @@ -623,6 +658,11 @@ type Project implements Node {
"""
last: Int
): SampleConnection

"""
Datetime of last update.
"""
updatedAt: ISO8601DateTime!
}

"""
Expand Down Expand Up @@ -890,6 +930,16 @@ type Sample implements Node {
last: Int
): AttachmentConnection

"""
Datetime when associated attachments were last updated.
"""
attachmentsUpdatedAt: ISO8601DateTime

"""
Datetime of creation.
"""
createdAt: ISO8601DateTime!

"""
Description of the sample.
"""
Expand Down Expand Up @@ -924,6 +974,11 @@ type Sample implements Node {
Persistent Unique Identifier of the sample. For example, `INXT_SAM_AAAAAAAAAAAA`.
"""
puid: ID!

"""
Datetime of last update.
"""
updatedAt: ISO8601DateTime!
}

"""
Expand Down Expand Up @@ -1020,6 +1075,11 @@ type UpdateSampleMetadataPayload {
A user
"""
type User {
"""
Datetime of creation.
"""
createdAt: ISO8601DateTime!

"""
User email.
"""
Expand All @@ -1029,4 +1089,9 @@ type User {
ID of the user.
"""
id: ID!

"""
Datetime of last update.
"""
updatedAt: ISO8601DateTime!
}
3 changes: 1 addition & 2 deletions app/graphql/types/attachment_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

module Types
# Attachment Type
class AttachmentType < Types::BaseObject
class AttachmentType < Types::BaseType
implements GraphQL::Types::Relay::Node
description 'An attachment'

field :byte_size, Integer, null: false, description: 'Attachment file size'
field :created_at, String, null: false, description: 'Attachment creation date'
field :filename, String, null: false, description: 'Attachment file name'
field :puid,
ID,
Expand Down
10 changes: 10 additions & 0 deletions app/graphql/types/base_type.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Types
# Base Type
class BaseType < Types::BaseObject
# ISO8601DateTime field
field :created_at, GraphQL::Types::ISO8601DateTime, null: false, description: 'Datetime of creation.'
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false, description: 'Datetime of last update.'
end
end
2 changes: 1 addition & 1 deletion app/graphql/types/namespace_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Types
# Namespace Type
class NamespaceType < Types::BaseObject
class NamespaceType < Types::BaseType
implements GraphQL::Types::Relay::Node
description 'A namespace'

Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/project_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Types
# Project Type
class ProjectType < Types::BaseObject
class ProjectType < Types::BaseType
implements GraphQL::Types::Relay::Node
description 'A project'

Expand Down
6 changes: 5 additions & 1 deletion app/graphql/types/sample_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Types
# Sample Type
class SampleType < Types::BaseObject
class SampleType < Types::BaseType
implements GraphQL::Types::Relay::Node
description 'A sample'

Expand All @@ -25,6 +25,10 @@ class SampleType < Types::BaseObject
complexity: 5,
resolver: Resolvers::SampleAttachmentsResolver

field :attachments_updated_at, GraphQL::Types::ISO8601DateTime,
null: true,
description: 'Datetime when associated attachments were last updated.'

def self.authorized?(object, context)
super &&
allowed_to?(
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Types
# User Type
class UserType < Types::BaseObject
class UserType < Types::BaseType
description 'A user'

field :email, String, null: false, description: 'User email.'
Expand Down
8 changes: 6 additions & 2 deletions test/graphql/attachments_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class AttachmentsQueryTest < ActiveSupport::TestCase
id,
metadata,
filename,
byteSize
byteSize,
createdAt,
updatedAt
}
}
}
Expand All @@ -30,7 +32,9 @@ class AttachmentsQueryTest < ActiveSupport::TestCase
node {
id,
filename,
attachmentUrl
attachmentUrl,
createdAt,
updatedAt
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions test/graphql/group_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class GroupQueryTest < ActiveSupport::TestCase
id
fullName
fullPath
createdAt
updatedAt
descendantGroups(includeParentDescendants: $includeParentDescendants) {
nodes {
name
Expand All @@ -32,6 +34,8 @@ class GroupQueryTest < ActiveSupport::TestCase
id
fullName
fullPath
createdAt
updatedAt
descendantGroups(includeParentDescendants: $includeParentDescendants) {
nodes {
name
Expand Down
2 changes: 2 additions & 0 deletions test/graphql/groups_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class GroupsQueryTest < ActiveSupport::TestCase
path
description
id
createdAt
updatedAt
}
totalCount
}
Expand Down
2 changes: 2 additions & 0 deletions test/graphql/namespace_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class NamespaceQueryTest < ActiveSupport::TestCase
id
fullName
fullPath
createdAt
updatedAt
}
}
GRAPHQL
Expand Down
4 changes: 4 additions & 0 deletions test/graphql/project_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class ProjectQueryTest < ActiveSupport::TestCase
id
fullName
fullPath
createdAt
updatedAt
}
}
GRAPHQL
Expand All @@ -25,6 +27,8 @@ class ProjectQueryTest < ActiveSupport::TestCase
id
fullName
fullPath
createdAt
updatedAt
}
}
GRAPHQL
Expand Down
3 changes: 3 additions & 0 deletions test/graphql/sample_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ class SampleQueryTest < ActiveSupport::TestCase
name
description
id
createdAt
updatedAt
attachmentsUpdatedAt
}
}
GRAPHQL
Expand Down

0 comments on commit edfde24

Please sign in to comment.