diff --git a/app/graphql/schema.graphql b/app/graphql/schema.graphql new file mode 100644 index 00000000..d770e4aa --- /dev/null +++ b/app/graphql/schema.graphql @@ -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! +} diff --git a/lib/tasks/graphql.rake b/lib/tasks/graphql.rake new file mode 100644 index 00000000..1e99e8be --- /dev/null +++ b/lib/tasks/graphql.rake @@ -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 \ No newline at end of file diff --git a/spec/graphql/staff_plan_schema_spec.rb b/spec/graphql/staff_plan_schema_spec.rb new file mode 100644 index 00000000..fb5c129f --- /dev/null +++ b/spec/graphql/staff_plan_schema_spec.rb @@ -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 \ No newline at end of file