-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adds a rake function to generate the GraphQL schema, and a test to ch…
…eck that it's up to date
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |