Skip to content

Commit 5b06179

Browse files
committed
feat: Add graphql.tada for automatic typesafe GQL
1 parent 8997961 commit 5b06179

File tree

7 files changed

+519
-6
lines changed

7 files changed

+519
-6
lines changed

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"typescript.enablePromptUseWorkspaceTsdk": true
4+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { graphql } from 'gql.tada'
2+
3+
/* --- Query ----------------------------------------------------------------------------------- */
4+
5+
export const healthCheckQuery = graphql(`
6+
query healthCheck {
7+
healthCheck {
8+
echo
9+
status
10+
alive
11+
kicking
12+
now
13+
aliveTime
14+
aliveSince
15+
serverTimezone
16+
requestHost
17+
requestProtocol
18+
requestURL
19+
baseURL
20+
apiURL
21+
port
22+
debugPort
23+
nodeVersion
24+
v8Version
25+
systemArch
26+
systemPlatform
27+
systemRelease
28+
systemFreeMemory
29+
systemTotalMemory
30+
systemLoadAverage
31+
}
32+
}
33+
`)

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* eslint-disable */
2+
/* prettier-ignore */
3+
4+
/** An IntrospectionQuery representation of your schema.
5+
*
6+
* @remarks
7+
* This is an introspection of your schema saved as a file by GraphQLSP.
8+
* It will automatically be used by `gql.tada` to infer the types of your GraphQL documents.
9+
* If you need to reuse this data or update your `scalars`, update `tadaOutputLocation` to
10+
* instead save to a .ts instead of a .d.ts file.
11+
*/
12+
export type introspection = {
13+
query: 'Query';
14+
mutation: never;
15+
subscription: never;
16+
types: {
17+
'Query': { kind: 'OBJECT'; name: 'Query'; fields: { 'healthCheck': { name: 'healthCheck'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'OBJECT'; name: 'HealthCheckData'; ofType: null; }; } }; }; };
18+
'HealthCheckArgs': { kind: 'INPUT_OBJECT'; name: 'HealthCheckArgs'; inputFields: [{ name: 'echo'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; }; defaultValue: null }]; };
19+
'String': unknown;
20+
'HealthCheckData': { kind: 'OBJECT'; name: 'HealthCheckData'; fields: { 'echo': { name: 'echo'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'status': { name: 'status'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'alive': { name: 'alive'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'kicking': { name: 'kicking'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Boolean'; ofType: null; }; } }; 'now': { name: 'now'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'aliveTime': { name: 'aliveTime'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'Float'; ofType: null; }; } }; 'aliveSince': { name: 'aliveSince'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; ofType: null; }; } }; 'serverTimezone': { name: 'serverTimezone'; type: { kind: 'NON_NULL'; name: never; ofType: { kind: 'SCALAR'; name: 'String'; 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; } }; 'baseURL': { name: 'baseURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'apiURL': { name: 'apiURL'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'port': { name: 'port'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'debugPort': { name: 'debugPort'; type: { kind: 'SCALAR'; name: 'Int'; ofType: null; } }; 'nodeVersion': { name: 'nodeVersion'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'v8Version': { name: 'v8Version'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemArch': { name: 'systemArch'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemPlatform': { name: 'systemPlatform'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemRelease': { name: 'systemRelease'; type: { kind: 'SCALAR'; name: 'String'; ofType: null; } }; 'systemFreeMemory': { name: 'systemFreeMemory'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'systemTotalMemory': { name: 'systemTotalMemory'; type: { kind: 'SCALAR'; name: 'Float'; ofType: null; } }; 'systemLoadAverage': { name: 'systemLoadAverage'; type: { kind: 'LIST'; name: never; ofType: { kind: 'SCALAR'; name: 'Float'; ofType: null; }; } }; }; };
21+
'Boolean': unknown;
22+
'Float': unknown;
23+
'Int': unknown;
24+
};
25+
};
26+
27+
import * as gqlTada from 'gql.tada';
28+
29+
declare module 'gql.tada' {
30+
interface setupSchema {
31+
introspection: introspection
32+
}
33+
}

features/app-core/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
"@apollo/server": "^4.10.2",
77
"@as-integrations/next": "^3.0.0",
88
"@graphql-tools/load-files": "^7.0.0",
9+
"gql.tada": "^1.4.3",
910
"graphql-tag": "^2.12.6"
1011
},
1112
"devDependencies": {
13+
"@0no-co/graphqlsp": "^1.9.1",
1214
"typescript": "5.3.3"
1315
},
1416
"scripts": {}

features/app-core/tsconfig.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
"resolveJsonModule": true,
1717
"isolatedModules": true,
1818
"jsx": "preserve",
19+
"plugins": [
20+
{
21+
"name": "@0no-co/graphqlsp",
22+
"schema": "http://localhost:3000/api/graphql",
23+
"tadaOutputLocation": "./graphql-env.d.ts"
24+
}
25+
],
1926
"paths": {
2027
"@app/config": ["../../features/app-core/appConfig.ts"],
2128
"@app/hooks/*": ["../../features/app-core/hooks/*"],
@@ -24,7 +31,7 @@
2431
"@app/assets/*": ["../../features/app-core/assets/*"],
2532
"@app/resolvers/*": ["../../features/app-core/resolvers/*"],
2633
"@app/middleware/*": ["../../features/app-core/middleware/*"]
27-
},
34+
}
2835
},
2936
"include": [
3037
"next-env.d.ts",

0 commit comments

Comments
 (0)