Skip to content

Commit

Permalink
test: transition schema test to real data import
Browse files Browse the repository at this point in the history
  • Loading branch information
nottmey committed Sep 14, 2023
1 parent 768eb8d commit 53cf71e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,14 @@ interface EntityBase {
#generated, do not edit manually!
type PlanetaryBoundary implements EntityBase {
id: ID!
description: String
name: String
quantifications: [Quantification!]!
}

#generated, do not edit manually!
type Quantification implements EntityBase {
id: ID!
name: String
planetaryBoundaries: [PlanetaryBoundary!]!
}

#generated, do not edit manually!
Expand All @@ -158,15 +157,14 @@ type QuantificationListPage {
#generated, do not edit manually!
input PlanetaryBoundaryInput {
id: ID!
description: String
name: String
quantifications: [QuantificationInput!]!
}

#generated, do not edit manually!
input QuantificationInput {
id: ID!
name: String
planetaryBoundaries: [PlanetaryBoundaryInput!]!
}

#generated, do not edit manually!
Expand All @@ -188,23 +186,23 @@ type Mutation {
#generated, do not edit manually!
type Subscription {
"Reminder: A `null` argument will filter the result differently than omitting the argument entirely."
onCreatedPlanetaryBoundary(id: ID, name: String): PlanetaryBoundary
onCreatedPlanetaryBoundary(id: ID, description: String, name: String): PlanetaryBoundary
@aws_subscribe(mutations: ["publishCreatedPlanetaryBoundary"])

"Reminder: A `null` argument will filter the result differently than omitting the argument entirely."
onCreatedQuantification(id: ID, name: String): Quantification
@aws_subscribe(mutations: ["publishCreatedQuantification"])

"Reminder: A `null` argument will filter the result differently than omitting the argument entirely."
onUpdatedPlanetaryBoundary(id: ID, name: String): PlanetaryBoundary
onUpdatedPlanetaryBoundary(id: ID, description: String, name: String): PlanetaryBoundary
@aws_subscribe(mutations: ["publishUpdatedPlanetaryBoundary"])

"Reminder: A `null` argument will filter the result differently than omitting the argument entirely."
onUpdatedQuantification(id: ID, name: String): Quantification
@aws_subscribe(mutations: ["publishUpdatedQuantification"])

"Reminder: A `null` argument will filter the result differently than omitting the argument entirely."
onDeletedPlanetaryBoundary(id: ID, name: String): PlanetaryBoundary
onDeletedPlanetaryBoundary(id: ID, description: String, name: String): PlanetaryBoundary
@aws_subscribe(mutations: ["publishDeletedPlanetaryBoundary"])

"Reminder: A `null` argument will filter the result differently than omitting the argument entirely."
Expand Down
27 changes: 0 additions & 27 deletions src/graphql/schema.clj
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
(ns graphql.schema
(:require
[clojure.java.io :as io]
[clojure.string :as s]
[clojure.test :refer [deftest is]]
[datomic.access :as access]
[datomic.attributes :as attributes]
[datomic.client.api :as d]
[datomic.framework :as framework]
[datomic.temp :as temp]
[graphql.fields :as fields]
[graphql.objects :as objects]
[graphql.parsing :as parsing]
[graphql.spec :as spec]
[graphql.types :as types]
[shared.mappings :as mappings]
Expand Down Expand Up @@ -192,24 +186,3 @@
{:name types/subscription-type
:spaced-fields? true
:fields subscription-fields})))))

(comment
(generate (access/get-connection access/dev-env-db-name))

(generate (u/temp-conn))
(printf (generate (u/temp-conn)))
; re-gen golden snapshot
(spit (io/resource "cdk/schema.graphql") (str (generate (u/temp-conn)))))

(deftest generate-schema-test
(let [empty-temp-conn (temp/conn)]
(d/transact empty-temp-conn {:tx-data attributes/graphql-attributes})
(d/transact empty-temp-conn {:tx-data attributes/platform-attributes})
(let [generated-schema (generate empty-temp-conn)]
(is (parsing/valid? generated-schema))))

(let [golden-snapshot (slurp (io/resource "cdk/schema.graphql"))
generated-schema (str (generate (u/temp-conn)))]
(is (parsing/valid? generated-schema))
(is (string? golden-snapshot))
(is (= generated-schema golden-snapshot))))
22 changes: 22 additions & 0 deletions test/graphql/schema_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(ns graphql.schema-test
(:require [clojure.java.io :as io]
[clojure.test :refer [deftest is]]
[graphql.parsing :as parsing]
[graphql.schema :as schema]
[utils.cloud-import :refer [local-conn]]))

(def golden-schema-file (io/resource "goldens/schema.graphql"))

(comment
(schema/generate local-conn)

(printf (schema/generate local-conn))
; re-gen golden snapshot
(spit golden-schema-file (str (schema/generate local-conn))))

(deftest generate-schema-test
(let [golden-snapshot (slurp golden-schema-file)
generated-schema (str (schema/generate local-conn))]
(is (parsing/valid? generated-schema))
(is (string? golden-snapshot))
(is (= generated-schema golden-snapshot))))
4 changes: 3 additions & 1 deletion test/utils/cloud_import.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
; only errors when using divert-system...
(d/connect (d/client (access/load-config)) {:db-name access/dev-env-db-name}))

; this works though, and could be filtered if it is to intensive
; the approach below works though, and could be filtered if it is to intensive
; no other connection can be started, so it's best to do this once at process startup, or use unique names
; once new things are transacted to local, you need to remove the data before importing, or choose a new name

Expand All @@ -38,7 +38,9 @@
local-conn
(do
(try
(log/info :message "Starting import of test data")
(import-cloud import-config)
(log/info :message "Finished import of test data")
(catch OverlappingFileLockException e
(throw e))
(catch RuntimeException e
Expand Down

0 comments on commit 53cf71e

Please sign in to comment.