Skip to content

Commit

Permalink
adds a rake function to generate the GraphQL schema, and a test to ch…
Browse files Browse the repository at this point in the history
…eck that it's up to date
  • Loading branch information
fermion committed Jan 6, 2024
1 parent da0fd37 commit a80d8b4
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
97 changes: 97 additions & 0 deletions app/graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
type Assignment {
createdAt: ISO8601DateTime!
id: ID!
project: Project!
status: String!
updatedAt: ISO8601DateTime!
user: User!
workWeeks: [WorkWeek!]!
}

type Client {
createdAt: ISO8601DateTime!
description: String
id: ID!
name: String!
projects: [Project!]!
status: String!
updatedAt: ISO8601DateTime!
}

type Company {
clients: [Client!]!
createdAt: ISO8601DateTime!
id: ID!
name: String!
projects: [Project!]!
updatedAt: ISO8601DateTime!
users: [User!]!
}

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

type Mutation {
createWorkWeek: WorkWeek!
setCurrentCompany(companyId: ID!): Company!
updateWorkWeek: WorkWeek!
}

type Project {
assignments: [Assignment!]!
client: Client!
createdAt: ISO8601DateTime!
id: ID!
name: String!
paymentFrequency: String!
status: String!
updatedAt: ISO8601DateTime!
users: [User!]!
workWeeks: [WorkWeek!]!
}

type Query {
clients: [Client!]!
projectAssignments(
"""
ID of the project to fetch assignments for.
"""
projectId: ID!
): [Assignment!]!
userAssignments(
"""
ID of the user to fetch assignments for. The current user's assignments will
be returned if this argument is not provided.
"""
userId: ID
): [Assignment!]!
users: [User!]!
}

type User {
assignments: [Assignment!]!
companies: [Company!]!
createdAt: ISO8601DateTime!
currentCompanyId: ID
email: String!
id: ID!
name: String!
projects: [Project!]!
updatedAt: ISO8601DateTime!
}

type WorkWeek {
actualHours: Int!
assignmentId: Int!
beginningOfWeek: Int!
createdAt: ISO8601DateTime!
cweek: Int!
estimatedHours: Int!
id: ID!
project: Project!
updatedAt: ISO8601DateTime!
user: User!
year: Int!
}
10 changes: 10 additions & 0 deletions lib/tasks/graphql.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# lib/tasks/graphql.rake
task dump_schema: :environment do
# Get a string containing the definition in GraphQL IDL:
schema_defn = StaffplanReduxSchema.to_definition
# Choose a place to write the schema dump:
schema_path = "app/graphql/schema.graphql"
# Write the schema dump to that file:
File.write(Rails.root.join(schema_path), schema_defn)
puts "Updated #{schema_path}"
end
12 changes: 12 additions & 0 deletions spec/graphql/staff_plan_schema_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe "StaffPlan GraphQL Schema dump" do
it "matches the printed schema" do
current_definition = StaffplanReduxSchema.to_definition
printout_definition = File.read(Rails.root.join("app/graphql/schema.graphql"))
# If this fails, update the printed schema with `bundle exec rake dump_schema`
expect(current_definition).to eq(printout_definition)
end
end

0 comments on commit a80d8b4

Please sign in to comment.