Skip to content

Commit d73c679

Browse files
committed
chore: Rename args & response schemas to input & output
1 parent b08dc8e commit d73c679

File tree

16 files changed

+79
-73
lines changed

16 files changed

+79
-73
lines changed

features/@app-core/graphql-env.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export type introspection = {
1818
'Boolean': unknown;
1919
'Date': unknown;
2020
'Float': unknown;
21-
'HealthCheckArgs': { kind: 'INPUT_OBJECT'; name: 'HealthCheckArgs'; isOneOf: false; inputFields: [{ name: 'echo'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; }; defaultValue: null }, { name: 'showContext'; type: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; defaultValue: null }]; };
22-
'HealthCheckResponse': { kind: 'OBJECT'; name: 'HealthCheckResponse'; fields: { 'alive': { name: 'alive'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'aliveSince': { name: 'aliveSince'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Date'; ofType: null; }; } }; 'aliveTime': { name: 'aliveTime'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Float'; ofType: null; }; } }; 'apiURL': { name: 'apiURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'backendURL': { name: 'backendURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'baseURL': { name: 'baseURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'context': { name: 'context'; type: { kind: 'SCALAR'; name: 'JSON'; ofType: null; } }; 'debugPort': { name: 'debugPort'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'echo': { name: 'echo'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'graphURL': { name: 'graphURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'kicking': { name: 'kicking'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'nodeVersion': { name: 'nodeVersion'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'now': { name: 'now'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'port': { name: 'port'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'requestHost': { name: 'requestHost'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'requestProtocol': { name: 'requestProtocol'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'requestURL': { name: 'requestURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'serverTimezone': { name: 'serverTimezone'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'status': { name: 'status'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'systemArch': { name: 'systemArch'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemFreeMemory': { name: 'systemFreeMemory'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'systemLoadAverage': { name: 'systemLoadAverage'; type: { kind: 'LIST'; name: never; ofType: { kind: 'SCALAR'; name: 'Float'; ofType: null; }; } }; 'systemPlatform': { name: 'systemPlatform'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemRelease': { name: 'systemRelease'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemTotalMemory': { name: 'systemTotalMemory'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'v8Version': { name: 'v8Version'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; }; };
21+
'HealthCheckInput': { kind: 'INPUT_OBJECT'; name: 'HealthCheckInput'; isOneOf: false; inputFields: [{ name: 'echo'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; }; defaultValue: null }, { name: 'verbose'; type: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; defaultValue: null }]; };
22+
'HealthCheckOutput': { kind: 'OBJECT'; name: 'HealthCheckOutput'; fields: { 'alive': { name: 'alive'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'aliveSince': { name: 'aliveSince'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Date'; ofType: null; }; } }; 'aliveTime': { name: 'aliveTime'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Float'; ofType: null; }; } }; 'apiURL': { name: 'apiURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'backendURL': { name: 'backendURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'baseURL': { name: 'baseURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'context': { name: 'context'; type: { kind: 'SCALAR'; name: 'JSON'; ofType: null; } }; 'debugPort': { name: 'debugPort'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'echo': { name: 'echo'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'graphURL': { name: 'graphURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'kicking': { name: 'kicking'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'nodeVersion': { name: 'nodeVersion'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'now': { name: 'now'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'port': { name: 'port'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'requestHost': { name: 'requestHost'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'requestProtocol': { name: 'requestProtocol'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'requestURL': { name: 'requestURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'serverTimezone': { name: 'serverTimezone'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'status': { name: 'status'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'systemArch': { name: 'systemArch'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemFreeMemory': { name: 'systemFreeMemory'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'systemLoadAverage': { name: 'systemLoadAverage'; type: { kind: 'LIST'; name: never; ofType: { kind: 'SCALAR'; name: 'Float'; ofType: null; }; } }; 'systemPlatform': { name: 'systemPlatform'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemRelease': { name: 'systemRelease'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemTotalMemory': { name: 'systemTotalMemory'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'v8Version': { name: 'v8Version'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; }; };
2323
'Int': unknown;
2424
'JSON': unknown;
2525
'JSONObject': unknown;
26-
'Query': { kind: 'OBJECT'; name: 'Query'; fields: { 'healthCheck': { name: 'healthCheck'; type: { kind: 'OBJECT'; name: 'HealthCheckResponse'; ofType: null; } }; }; };
26+
'Query': { kind: 'OBJECT'; name: 'Query'; fields: { 'healthCheck': { name: 'healthCheck'; type: { kind: 'OBJECT'; name: 'HealthCheckOutput'; ofType: null; } }; }; };
2727
'String': unknown;
2828
};
2929
};

features/@app-core/graphql/schema.graphql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ scalar JSON
66

77
scalar JSONObject
88

9-
input HealthCheckArgs {
9+
input HealthCheckInput {
1010
echo: String
11-
showContext: Boolean
11+
verbose: Boolean
1212
}
1313

14-
type HealthCheckResponse {
14+
type HealthCheckOutput {
1515
echo: String
1616
status: String!
1717
alive: Boolean!
@@ -41,7 +41,7 @@ type HealthCheckResponse {
4141
}
4242

4343
type Query {
44-
healthCheck(args: HealthCheckArgs): HealthCheckResponse
44+
healthCheck(args: HealthCheckInput): HealthCheckOutput
4545
}
4646

4747
schema {

features/@app-core/graphql/typeDefs.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ scalar JSON
66
77
scalar JSONObject
88
9-
input HealthCheckArgs {
9+
input HealthCheckInput {
1010
echo: String
11-
showContext: Boolean
11+
verbose: Boolean
1212
}
1313
14-
type HealthCheckResponse {
14+
type HealthCheckOutput {
1515
echo: String
1616
status: String!
1717
alive: Boolean!
@@ -41,7 +41,7 @@ type HealthCheckResponse {
4141
}
4242
4343
type Query {
44-
healthCheck(args: HealthCheckArgs): HealthCheckResponse
44+
healthCheck(args: HealthCheckInput): HealthCheckOutput
4545
}
4646
4747
schema {
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import { createDataBridge } from '@green-stack/schemas/createDataBridge'
2-
import { HealthCheckArgs } from '../schemas/HealthCheckArgs'
3-
import { HealthCheckResponse } from '../schemas/HealthCheckResponse'
2+
import { HealthCheckInput } from '../schemas/HealthCheckInput'
3+
import { HealthCheckOutput } from '../schemas/HealthCheckOutput'
44

5-
/* --- Bridge ---------------------------------------------------------------------------------- */
5+
/* --- Types ----------------------------------------------------------------------------------- */
66

7+
export { HealthCheckInput, HealthCheckOutput }
8+
9+
/** --- Bridge --------------------------------------------------------------------------------- */
10+
/** -i- Bundled meta for the healthCheck() resolver, reusable on server, browser & mobile */
711
export const healthCheckBridge = createDataBridge({
812
resolverName: 'healthCheck',
9-
resolverArgsName: 'HealthCheckArgs',
10-
argsSchema: HealthCheckArgs,
11-
responseSchema: HealthCheckResponse,
13+
// resolverArgsName: 'HealthCheckInput',
14+
inputSchema: HealthCheckInput,
15+
outputSchema: HealthCheckOutput,
1216
apiPath: '/api/health',
1317
allowedMethods: ['GRAPHQL', 'GET'],
1418
})
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import type { HealthCheckArgs, HealthCheckResponse } from './healthCheck.bridge'
1+
import type { HealthCheckInput, HealthCheckOutput } from './healthCheck.bridge'
22
import { appConfig } from '../appConfig'
33

44
/** --- healthCheckFetcher() ------------------------------------------------------------------- */
55
/** -i- Isomorphic fetcher for our healthCheck() resolver at '/api/health' */
6-
export const healthCheckFetcher = async (args: HealthCheckArgs) => {
6+
export const healthCheckFetcher = async (args: HealthCheckInput) => {
77
const response = await fetch(`${appConfig.backendURL}/api/health?echo=${args.echo}`, {
88
method: 'GET',
99
headers: {
1010
'Content-Type': 'application/json',
1111
},
1212
})
1313
const data = await response.json()
14-
return data as HealthCheckResponse
14+
return data as HealthCheckOutput
1515
}

features/@app-core/resolvers/healthCheck.fetcher.web.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { NextRequest, NextResponse } from 'next/server'
2-
import type { HealthCheckArgs, HealthCheckResponse } from './healthCheck.bridge'
2+
import type { HealthCheckInput, HealthCheckOutput } from './healthCheck.bridge'
33
import { appConfig } from '../appConfig'
44

55
/** --- healthCheckFetcher() ------------------------------------------------------------------- */
66
/** -i- Isomorphic fetcher for our healthCheck() resolver at '/api/health' */
7-
export const healthCheckFetcher = async (args: HealthCheckArgs) => {
7+
export const healthCheckFetcher = async (args: HealthCheckInput) => {
88
// Vars
99
const isServer = typeof window === 'undefined'
1010

@@ -18,7 +18,7 @@ export const healthCheckFetcher = async (args: HealthCheckArgs) => {
1818
},
1919
})
2020
const data = await response.json()
21-
return data as HealthCheckResponse
21+
return data as HealthCheckOutput
2222
}
2323

2424
// -- Server --
@@ -31,5 +31,5 @@ export const healthCheckFetcher = async (args: HealthCheckArgs) => {
3131
res: {} as NextResponse,
3232
},
3333
})
34-
return data as HealthCheckResponse
34+
return data as HealthCheckOutput
3535
}

features/@app-core/resolvers/healthCheck.query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { graphql } from '../graphql/graphql'
66
/* --- Query ----------------------------------------------------------------------------------- */
77

88
export const healthCheckQuery = graphql(`
9-
query healthCheck ($healthCheckArgs: HealthCheckArgs) {
9+
query healthCheck ($healthCheckArgs: HealthCheckInput) {
1010
healthCheck(args: $healthCheckArgs) {
1111
echo
1212
status

features/@app-core/resolvers/healthCheck.resolver.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ const ALIVE_SINCE = new Date()
1212

1313
/** --- healthCheck() -------------------------------------------------------------------------- */
1414
/** -i- Check the health status of the server. Includes relevant urls, server time(zone), versions and more */
15-
export const healthCheck = createResolver(async ({ args, req, context }) => {
15+
export const healthCheck = createResolver(async ({ args, withDefaults, req, context }) => {
1616
// Inputs
17-
const { echo, showContext } = args
17+
const { echo, verbose } = args
1818

1919
// Context
2020
const { req: _, res: __, ...headerContext } = context
@@ -105,6 +105,6 @@ export const healthCheck = createResolver(async ({ args, req, context }) => {
105105
systemTotalMemory: OS.totalmem(),
106106
systemLoadAverage: OS.loadavg(),
107107
// CONTEXT
108-
context: showContext ? extraContext : undefined,
108+
context: verbose ? extraContext : undefined,
109109
}
110110
}, healthCheckBridge)

features/@app-core/routes/api/health/route.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@ export const POST = createNextRouteHandler(healthCheck)
1010

1111
/* --- GraphQL --------------------------------------------------------------------------------- */
1212

13+
// -i- Picked up by `npm run collect:resolvers` when running dev to add to list of resolvers
14+
// -i- which `npm run build:schema` will later turn into new GraphQL schema definitions
1315
export const graphResolver = createGraphResolver(healthCheck)

features/@app-core/schemas/HealthCheckArgs.ts renamed to features/@app-core/schemas/HealthCheckInput.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ import { z, schema } from '@green-stack/schemas'
22

33
/* --- Schemas --------------------------------------------------------------------------------- */
44

5-
export const HealthCheckArgs = schema('HealthCheckArgs', {
5+
export const HealthCheckInput = schema('HealthCheckInput', {
66
echo: z.string().default('Hello World'),
7-
showContext: z.boolean().default(false),
7+
verbose: z.boolean().default(false),
88
})
99

1010
/* --- Type Alias ------------------------------------------------------------------------------ */
1111

12-
export type HealthCheckArgs = z.infer<typeof HealthCheckArgs>
12+
export type HealthCheckInput = z.infer<typeof HealthCheckInput>

0 commit comments

Comments
 (0)