Skip to content

Commit

Permalink
Merge pull request #12 from zeeshanakram3/add-graphql-query-to-get-pa…
Browse files Browse the repository at this point in the history
…ckage-version

Fix: Add graphql query to get package version
  • Loading branch information
zeeshanakram3 committed Jan 16, 2024
2 parents 0f8d165 + a3348d2 commit 457fa61
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 35 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 0 additions & 17 deletions db/migrations/2200000000000-Operator.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
const fs = require('fs')
const path = require('path')

module.exports = class Operator2200000000000 {
name = 'Operator2200000000000'

async up(db) {
// Path to your package.json file
const packageJsonPath = path.join(__dirname, '../../package.json')

// Read the package.json file synchronously
const data = fs.readFileSync(packageJsonPath, 'utf8')

// Parse the JSON data
const packageJson = JSON.parse(data)

await db.query(
`INSERT INTO "squid_version" ("id", "version")
VALUES ('${packageJson.name}' ,'${packageJson.version}');`
)

// Create pg_stat_statements extension for analyzing query stats
await db.query(`CREATE EXTENSION pg_stat_statements;`)
}
Expand Down
115 changes: 107 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"lodash": "^4.17.21",
"patch-package": "^6.5.0",
"pg": "8.8.0",
"pkg-dir": "^4.2.0",
"type-graphql": "^1.2.0-rc.1",
"typeorm": "^0.3.11"
},
Expand Down
4 changes: 0 additions & 4 deletions schema/misc.graphql

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/get-graphql-schema.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

set -e

Expand Down
2 changes: 1 addition & 1 deletion scripts/start-graphql-server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/usr/bin/env bash

# docker entrypoint fot graphql-server, to allow running with telemetry
if [[ "$TELEMETRY_ENABLED" = "yes" ]]; then
Expand Down
1 change: 1 addition & 0 deletions src/server-extension/resolvers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { SquidVersionResolver } from './squidVersion'
37 changes: 37 additions & 0 deletions src/server-extension/resolvers/squidVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import fs from 'fs'
import _ from 'lodash'
import pkgDir from 'pkg-dir'
import 'reflect-metadata'
import { Field, ObjectType, Query, Resolver } from 'type-graphql'

const pkgVersion = (): Promise<string> => {
// Path to package.json file
const packageJsonPath = `${pkgDir.sync()}/package.json`

// Read the package.json file synchronously
const data = fs.readFileSync(packageJsonPath, 'utf8')

// Parse the JSON data
const packageJson = JSON.parse(data)

return packageJson.version
}

const memoizedPkgVersion = _.memoize(pkgVersion)

@ObjectType()
export class SquidVersion {
@Field(() => String, { nullable: false })
version!: string
}

@Resolver()
export class SquidVersionResolver {
@Query(() => SquidVersion)
async squidVersion(): Promise<SquidVersion> {
// Get package version
const version = await memoizedPkgVersion()

return { version }
}
}

0 comments on commit 457fa61

Please sign in to comment.