Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add graphql query to get package version #12

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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 }
}
}
Loading