@morphql/server 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -222
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,245 +1,59 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/Hyperwindmill/morphql/main/morphql.png" alt="MorphQL" width="200" />
|
|
3
|
+
</p>
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
<p align="center">
|
|
6
|
+
<a href="https://www.npmjs.com/package/@morphql/server"><img src="https://img.shields.io/npm/v/@morphql/server?label=%40morphql%2Fserver" alt="npm version" /></a>
|
|
7
|
+
<img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT" />
|
|
8
|
+
</p>
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
# @morphql/server
|
|
6
11
|
|
|
7
|
-
|
|
12
|
+
A headless transformation server core for **MorphQL**. Designed to be embedded into existing NestJS or Node.js applications to provide managed transformation endpoints with caching and OpenAPI support.
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
## Core Features
|
|
10
15
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
- ⚡ **Redis
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
- 📊 **Swagger Documentation**: Interactive API docs at `/api`
|
|
17
|
-
- 🏥 **Health Checks**: Liveness and readiness endpoints for orchestration
|
|
16
|
+
- 🏗️ **Headless Core**: Embed MorphQL management into your own backend.
|
|
17
|
+
- 🔗 **Staged Queries**: Map `.morphql` files to named API endpoints automatically.
|
|
18
|
+
- ⚡ **Redis Integration**: Strategic caching of compiled queries for maximum throughput.
|
|
19
|
+
- 📖 **Auto-OpenAPI**: Generates Swagger/OpenAPI fragments for all defined transformations.
|
|
20
|
+
- 🛡️ **Type-Safe**: Inferred schemas for request and response formats.
|
|
18
21
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
### Docker Compose (Recommended)
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
# Start server + Redis
|
|
25
|
-
docker compose up -d
|
|
26
|
-
|
|
27
|
-
# View logs
|
|
28
|
-
docker compose logs -f server
|
|
29
|
-
|
|
30
|
-
# Stop services
|
|
31
|
-
docker compose down
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
The server will be available at `http://localhost:3000` with Swagger docs at `http://localhost:3000/api`.
|
|
35
|
-
|
|
36
|
-
### Development Mode
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
# From monorepo root
|
|
40
|
-
npm run server
|
|
41
|
-
|
|
42
|
-
# Or from packages/server
|
|
43
|
-
npm run start:dev
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## API Reference
|
|
47
|
-
|
|
48
|
-
All endpoints are prefixed with `/v1`. Full interactive documentation is available at `/api` when the server is running.
|
|
49
|
-
|
|
50
|
-
### 1. Execute Transformation
|
|
51
|
-
|
|
52
|
-
Compile and execute a query against data in a single request.
|
|
53
|
-
|
|
54
|
-
**Endpoint**: `POST /v1/execute`
|
|
55
|
-
|
|
56
|
-
**Request**:
|
|
57
|
-
|
|
58
|
-
```json
|
|
59
|
-
{
|
|
60
|
-
"query": "from json to json transform set firstName = split(fullName, ' ')[0]",
|
|
61
|
-
"data": { "fullName": "John Doe" }
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
**Response**:
|
|
66
|
-
|
|
67
|
-
```json
|
|
68
|
-
{
|
|
69
|
-
"success": true,
|
|
70
|
-
"result": { "firstName": "John" },
|
|
71
|
-
"executionTime": 2.5
|
|
72
|
-
}
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
**Example with curl**:
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
curl -X POST http://localhost:3000/v1/execute \
|
|
79
|
-
-H "Content-Type: application/json" \
|
|
80
|
-
-d '{
|
|
81
|
-
"query": "from json to json transform set name = fullName",
|
|
82
|
-
"data": { "fullName": "Jane Smith" }
|
|
83
|
-
}'
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### 2. Compile Query
|
|
87
|
-
|
|
88
|
-
Get the generated JavaScript code for a query without executing it.
|
|
89
|
-
|
|
90
|
-
**Endpoint**: `POST /v1/compile`
|
|
91
|
-
|
|
92
|
-
**Request**:
|
|
93
|
-
|
|
94
|
-
```json
|
|
95
|
-
{
|
|
96
|
-
"query": "from json to xml transform set name = fullName"
|
|
97
|
-
}
|
|
98
|
-
```
|
|
99
|
-
|
|
100
|
-
**Response**:
|
|
101
|
-
|
|
102
|
-
```json
|
|
103
|
-
{
|
|
104
|
-
"success": true,
|
|
105
|
-
"code": "function(source) { /* generated code */ }"
|
|
106
|
-
}
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### 3. Health Checks
|
|
110
|
-
|
|
111
|
-
**Liveness**: `GET /v1/health`
|
|
112
|
-
|
|
113
|
-
```json
|
|
114
|
-
{ "status": "ok", "timestamp": "2026-01-20T00:00:00.000Z" }
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
**Readiness**: `GET /v1/health/ready`
|
|
118
|
-
|
|
119
|
-
- Returns `200` if service and Redis (if configured) are ready
|
|
120
|
-
- Returns `503` if Redis is configured but unavailable
|
|
121
|
-
|
|
122
|
-
## Configuration
|
|
123
|
-
|
|
124
|
-
Configure the server via environment variables:
|
|
125
|
-
|
|
126
|
-
| Variable | Description | Default | Required |
|
|
127
|
-
| -------------- | ------------------------------------ | ------- | -------- |
|
|
128
|
-
| `PORT` | Server port | `3000` | No |
|
|
129
|
-
| `NODE_ENV` | Environment mode | - | No |
|
|
130
|
-
| `REDIS_HOST` | Redis hostname for caching | - | No |
|
|
131
|
-
| `REDIS_PORT` | Redis port | `6379` | No |
|
|
132
|
-
| `REDIS_PREFIX` | Cache key prefix | `morphql:` | No |
|
|
133
|
-
| `API_KEY` | Optional API key for auth | - | No |
|
|
134
|
-
| `API_KEY_FILE` | Optional API key file (for secrets) | - | No |
|
|
135
|
-
|
|
136
|
-
**Note**: If `REDIS_HOST` is not set, the server runs without caching (queries are compiled on every request).
|
|
137
|
-
|
|
138
|
-
## Authentication
|
|
139
|
-
|
|
140
|
-
The server supports optional API key authentication via the `X-API-KEY` header.
|
|
141
|
-
|
|
142
|
-
**Enable authentication**:
|
|
22
|
+
## Installation
|
|
143
23
|
|
|
144
24
|
```bash
|
|
145
|
-
|
|
146
|
-
export API_KEY=your-secret-key
|
|
147
|
-
|
|
148
|
-
# Or in docker-compose.yml
|
|
149
|
-
environment:
|
|
150
|
-
- API_KEY=your-secret-key
|
|
25
|
+
npm install @morphql/server @morphql/core
|
|
151
26
|
```
|
|
152
27
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
curl -X POST http://localhost:3000/v1/execute \
|
|
157
|
-
-H "X-API-KEY: your-secret-key" \
|
|
158
|
-
-H "Content-Type: application/json" \
|
|
159
|
-
-d '{"query": "...", "data": {...}}'
|
|
160
|
-
```
|
|
28
|
+
## Basic Usage (NestJS/Node)
|
|
161
29
|
|
|
162
|
-
|
|
30
|
+
```typescript
|
|
31
|
+
import { MorphServer } from '@morphql/server';
|
|
163
32
|
|
|
164
|
-
|
|
33
|
+
const morph = new MorphServer({
|
|
34
|
+
queriesDir: './queries', // automatically load .morphql files
|
|
35
|
+
cache: redisCache, // optional Redis caching
|
|
36
|
+
});
|
|
165
37
|
|
|
166
|
-
|
|
38
|
+
await morph.initialize();
|
|
167
39
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
docker build -f packages/server/Dockerfile -t morphql-server .
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
### Running with Docker
|
|
174
|
-
|
|
175
|
-
```bash
|
|
176
|
-
# Without Redis
|
|
177
|
-
docker run -p 3000:3000 morphql-server
|
|
178
|
-
|
|
179
|
-
# With Redis
|
|
180
|
-
docker run -p 3000:3000 \
|
|
181
|
-
-e REDIS_HOST=redis.example.com \
|
|
182
|
-
-e REDIS_PORT=6379 \
|
|
183
|
-
morphql-server
|
|
40
|
+
// Execute a named staged query
|
|
41
|
+
const result = await morph.executeStaged('user-profile', sourceData);
|
|
184
42
|
```
|
|
185
43
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
The included `docker-compose.yml` provides a production-ready setup with:
|
|
189
|
-
|
|
190
|
-
- NestJS server with health checks
|
|
191
|
-
- Redis for query caching
|
|
192
|
-
- Persistent Redis data volume
|
|
193
|
-
- Automatic restart policies
|
|
194
|
-
|
|
195
|
-
## Development
|
|
196
|
-
|
|
197
|
-
### Available Scripts
|
|
198
|
-
|
|
199
|
-
| Command | Description |
|
|
200
|
-
| --------------------- | ------------------------ |
|
|
201
|
-
| `npm run start` | Start in production mode |
|
|
202
|
-
| `npm run start:dev` | Start with hot-reload |
|
|
203
|
-
| `npm run start:debug` | Start with debugger |
|
|
204
|
-
| `npm run build` | Build for production |
|
|
205
|
-
| `npm run test` | Run unit tests |
|
|
206
|
-
| `npm run test:e2e` | Run end-to-end tests |
|
|
207
|
-
| `npm run lint` | Lint and fix code |
|
|
208
|
-
|
|
209
|
-
### Project Structure
|
|
210
|
-
|
|
211
|
-
```
|
|
212
|
-
packages/server/
|
|
213
|
-
├── src/
|
|
214
|
-
│ ├── main.ts # Application entry point
|
|
215
|
-
│ ├── app.module.ts # Root module
|
|
216
|
-
│ ├── morph.controller.ts # API endpoints
|
|
217
|
-
│ └── auth.guard.ts # API key authentication
|
|
218
|
-
├── test/ # E2E tests
|
|
219
|
-
├── Dockerfile # Multi-stage production build
|
|
220
|
-
├── docker-compose.yml # Local deployment stack
|
|
221
|
-
└── package.json
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
## Performance
|
|
225
|
-
|
|
226
|
-
- **Caching**: When Redis is enabled, compiled queries are cached indefinitely (queries are deterministic)
|
|
227
|
-
- **Stateless**: Each request is independent, enabling horizontal scaling
|
|
228
|
-
- **Async**: All endpoints use async/await for non-blocking I/O
|
|
229
|
-
|
|
230
|
-
## Monitoring
|
|
44
|
+
## Standalone Usage
|
|
231
45
|
|
|
232
|
-
|
|
46
|
+
If you need a ready-to-deploy microservice, check the **[Server Instance Starter Template](https://github.com/Hyperwindmill/morphql/tree/main/packages/server-instance)** in our repository. It includes:
|
|
233
47
|
|
|
234
|
-
-
|
|
235
|
-
-
|
|
236
|
-
-
|
|
48
|
+
- Docker & Docker Compose setup
|
|
49
|
+
- Pre-configured NestJS application
|
|
50
|
+
- Health checks (Liveness/Readiness)
|
|
51
|
+
- API Key authentication
|
|
237
52
|
|
|
238
|
-
|
|
53
|
+
## Learn More
|
|
239
54
|
|
|
240
|
-
-
|
|
241
|
-
-
|
|
242
|
-
- Application Performance Monitoring (APM) tools
|
|
55
|
+
- 👉 **[Official Documentation](https://hyperwindmill.github.io/morphql/)**
|
|
56
|
+
- 🏠 **[Main Repository](https://github.com/Hyperwindmill/morphql)**
|
|
243
57
|
|
|
244
58
|
## License
|
|
245
59
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@morphql/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
4
4
|
"description": "MorphQL Server Core - Headless transformation engine",
|
|
5
5
|
"author": "Hyperwindmill",
|
|
6
6
|
"private": false,
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"js-yaml": "^4.1.1"
|
|
30
30
|
},
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"@morphql/core": "^0.1.
|
|
32
|
+
"@morphql/core": "^0.1.19"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
|
-
"@morphql/core": "^0.1.
|
|
35
|
+
"@morphql/core": "^0.1.19",
|
|
36
36
|
"@types/js-yaml": "^4.0.9",
|
|
37
37
|
"@types/node": "^25.2.0",
|
|
38
38
|
"typescript": "^5.9.3",
|