Skip to content

Commit

Permalink
fix: ensure migration is run before introspection
Browse files Browse the repository at this point in the history
  • Loading branch information
rhyslbw committed Sep 17, 2020
1 parent 4e3607c commit 079a248
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/api-cardano-db-hasura/src/HasuraClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dayjs.extend(utc)
export class HasuraClient {
private client: ApolloClient<NormalizedCacheObject>
readonly hasuraUri: string
private applyingSchemaAndMetadata: boolean

constructor (hasuraUri: string) {
this.hasuraUri = hasuraUri
Expand All @@ -37,7 +38,9 @@ export class HasuraClient {
})
}

public async applySchemaAndMetadata () {
public async applySchemaAndMetadata (): Promise<void> {
if (this.applyingSchemaAndMetadata) return
this.applyingSchemaAndMetadata = true
await pRetry(async () => {
await this.hasuraCli('migrate apply --down all')
await this.hasuraCli('migrate apply --up all')
Expand All @@ -48,9 +51,11 @@ export class HasuraClient {
retries: 9,
onFailedAttempt: util.onFailedAttemptFor('Applying PostgreSQL schema and Hasura metadata')
})
this.applyingSchemaAndMetadata = false
}

public async buildHasuraSchema () {
await this.applySchemaAndMetadata()
const executor = async ({ document, variables }: { document: DocumentNode, variables?: Object }) => {
const query = print(document)
try {
Expand Down

0 comments on commit 079a248

Please sign in to comment.