mirror of
https://github.com/hasura/graphql-engine.git
synced 2025-01-05 14:27:59 +03:00
Make command to generate types from typed metadata in languages other than Typescript
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/8238 GitOrigin-RevId: 9a4730e0d311916c0d837586485382c58033c914
This commit is contained in:
parent
a119260a5d
commit
69c8e8bb4a
4
metadata-api-types/.gitignore
vendored
Normal file
4
metadata-api-types/.gitignore
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
go/
|
||||
haskell/
|
||||
rust/
|
||||
kotlin/
|
@ -5,6 +5,24 @@ TYPESCRIPT_ROOT := typescript
|
||||
TYPESCRIPT_SRC := ${TYPESCRIPT_ROOT}/src
|
||||
PATCHES := $(wildcard ${TYPESCRIPT_ROOT}/patches/*.patch)
|
||||
|
||||
FILE_NAME := metadata.openapi
|
||||
|
||||
GO_ROOT := go
|
||||
GO_FILE := ${FILE_NAME}.go
|
||||
GO_TARGET := ${GO_ROOT}/${GO_FILE}
|
||||
|
||||
RUST_ROOT := rust
|
||||
RUST_FILE := ${FILE_NAME}.rs
|
||||
RUST_TARGET := ${RUST_ROOT}/${RUST_FILE}
|
||||
|
||||
HASKELL_ROOT := haskell
|
||||
HASKELL_FILE := ${FILE_NAME}.hs
|
||||
HASKELL_TARGET := ${HASKELL_ROOT}/${HASKELL_FILE}
|
||||
|
||||
KOTLIN_ROOT := kotlin
|
||||
KOTLIN_FILE := ${FILE_NAME}.kt
|
||||
KOTLIN_TARGET := ${KOTLIN_ROOT}/${KOTLIN_FILE}
|
||||
|
||||
# default target
|
||||
.PHONY: help
|
||||
## help: prints help message
|
||||
@ -13,18 +31,50 @@ help:
|
||||
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
|
||||
|
||||
.PHONY: generate-types
|
||||
## generate-types: Generate the TypeScript types for working with the Metadata API
|
||||
generate-types: ${TYPESCRIPT_SRC}
|
||||
## generate-types: Generate types for working with the Metadata API
|
||||
generate-types: generate-typescript-types generate-go-types generate-rust-types generate-haskell-types generate-kotlin-types
|
||||
|
||||
.PHONY: generate-typescript-types
|
||||
## generate-typescript-types: Generate the TypeScript types for working with the Metadata API
|
||||
generate-typescript-types: ${TYPESCRIPT_SRC}
|
||||
|
||||
.PHONY: generate-go-types
|
||||
## generate-go-types: Generate the Go types for working with the Metadata API
|
||||
generate-go-types: ${GO_TARGET}
|
||||
|
||||
.PHONY: generate-rust-types
|
||||
## generate-rust-types: Generate the Rust types for working with the Metadata API
|
||||
generate-rust-types: ${RUST_TARGET}
|
||||
|
||||
.PHONY: generate-haskell-types
|
||||
## generate-haskell-types: Generate the Haskell types for working with the Metadata API
|
||||
generate-haskell-types: ${HASKELL_TARGET}
|
||||
|
||||
.PHONY: generate-kotlin-types
|
||||
## generate-kotlin-types: Generate the Kotlin types for working with the Metadata API
|
||||
generate-kotlin-types: ${KOTLIN_TARGET}
|
||||
|
||||
.PHONY: typecheck
|
||||
## typecheck: Typechecks generated type definitions
|
||||
typecheck: typecheck-metadata-api-types
|
||||
|
||||
${TYPESCRIPT_SRC}: ${SCHEMA_FILE} ${TYPESCRIPT_ROOT}/package.json ${TYPESCRIPT_ROOT}/package-lock.json ${PATCHES}
|
||||
./scripts/generate-types.sh "${SCHEMA_FILE}"
|
||||
|
||||
.PHONY: typecheck-metadata-api-types
|
||||
## typecheck-metadata-api-types: Typechecks the metadata-api-types
|
||||
typecheck-metadata-api-types:
|
||||
cd ${TYPESCRIPT_ROOT} && \
|
||||
npm run typecheck
|
||||
|
||||
${TYPESCRIPT_SRC}: ${SCHEMA_FILE} ${TYPESCRIPT_ROOT}/package.json ${TYPESCRIPT_ROOT}/package-lock.json ${PATCHES}
|
||||
./scripts/generate-typescript-types.sh "${SCHEMA_FILE}"
|
||||
|
||||
${GO_TARGET}: ${TYPESCRIPT_SRC}
|
||||
./scripts/generate-types-for-lang.sh ${GO_ROOT} ${GO_FILE}
|
||||
|
||||
${RUST_TARGET}: ${TYPESCRIPT_SRC}
|
||||
./scripts/generate-types-for-lang.sh ${RUST_ROOT} ${RUST_FILE}
|
||||
|
||||
${HASKELL_TARGET}: ${TYPESCRIPT_SRC}
|
||||
./scripts/generate-types-for-lang.sh ${HASKELL_ROOT} ${HASKELL_FILE}
|
||||
|
||||
${KOTLIN_TARGET}: ${TYPESCRIPT_SRC}
|
||||
./scripts/generate-types-for-lang.sh ${KOTLIN_ROOT} ${KOTLIN_FILE}
|
||||
|
25
metadata-api-types/scripts/generate-types-for-lang.sh
Executable file
25
metadata-api-types/scripts/generate-types-for-lang.sh
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
PROJECT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." >/dev/null 2>&1 && pwd )" # ... https://stackoverflow.com/a/246128/176841
|
||||
|
||||
LANG="$1"
|
||||
FILE="$2"
|
||||
# We are generating types from already generated Typescript types.
|
||||
# `index.js`` is the file that contains the Typescript types
|
||||
INDEX_JS="${PROJECT_ROOT}/typescript/src/index.ts"
|
||||
|
||||
# Dir where generated types will be published.
|
||||
DIR="${PROJECT_ROOT}/${LANG}"
|
||||
|
||||
if [ ! -d "${DIR}" ]; then
|
||||
mkdir "${DIR}"
|
||||
fi
|
||||
|
||||
# npm package used to generate types.
|
||||
# Use `quicktype --help` to see a list of supported languages.
|
||||
# Use `npm i -g quicktype` to install.
|
||||
quicktype --lang "${LANG}" \
|
||||
--out "${DIR}/${FILE}" \
|
||||
--src-lang typescript \
|
||||
--src "${INDEX_JS}" # add --quiet to silence output
|
Loading…
Reference in New Issue
Block a user