@graphql-codegen/typescript-nhost 0.0.1
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/cjs/config.js +2 -0
- package/cjs/index.js +40 -0
- package/cjs/package.json +1 -0
- package/esm/config.js +1 -0
- package/esm/index.js +36 -0
- package/package.json +45 -0
- package/typings/config.d.cts +7 -0
- package/typings/config.d.ts +7 -0
- package/typings/index.d.cts +4 -0
- package/typings/index.d.ts +4 -0
package/cjs/config.js
ADDED
package/cjs/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.plugin = void 0;
|
|
4
|
+
const introspection_1 = require("@urql/introspection");
|
|
5
|
+
const typescript_1 = require("@graphql-codegen/typescript");
|
|
6
|
+
const plugin = (schema, documents, config) => {
|
|
7
|
+
// * We don't allow the other @graphql-codegen/typescript options as they could break the generator and the types.
|
|
8
|
+
const { scalars } = config;
|
|
9
|
+
const conf = {
|
|
10
|
+
scalars,
|
|
11
|
+
declarationKind: 'type',
|
|
12
|
+
enumsAsTypes: true,
|
|
13
|
+
// * Add underscore to args type to avoid conflicts with the generated types
|
|
14
|
+
// * See: https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#addunderscoretoargstype
|
|
15
|
+
addUnderscoreToArgsType: true,
|
|
16
|
+
};
|
|
17
|
+
const minifiedData = (0, introspection_1.minifyIntrospectionQuery)((0, introspection_1.getIntrospectedSchema)(schema), {
|
|
18
|
+
includeDirectives: false,
|
|
19
|
+
includeEnums: true,
|
|
20
|
+
includeInputs: true,
|
|
21
|
+
includeScalars: true,
|
|
22
|
+
});
|
|
23
|
+
const { prepend, content } = (0, typescript_1.plugin)(schema, documents, conf);
|
|
24
|
+
// * https://stackoverflow.com/questions/2008279/validate-a-javascript-function-name
|
|
25
|
+
const types = Array.from(content.matchAll(/^export type ([$A-Z_][0-9A-Z_$]*) = /gim))
|
|
26
|
+
.map(([, name]) => `\n${name}: ${name}`)
|
|
27
|
+
.join(',');
|
|
28
|
+
const result = `
|
|
29
|
+
export default {
|
|
30
|
+
introspection: ${JSON.stringify(minifiedData, null, 2).replace(/^/gm, ' ').slice(2)} as const,
|
|
31
|
+
types: {} as {${types.replace(/^/gm, ' ').slice(4)}
|
|
32
|
+
}
|
|
33
|
+
}`;
|
|
34
|
+
return {
|
|
35
|
+
prepend,
|
|
36
|
+
content: [content, result].join('\n'),
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.plugin = plugin;
|
|
40
|
+
exports.default = exports.plugin;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
package/esm/config.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getIntrospectedSchema, minifyIntrospectionQuery } from '@urql/introspection';
|
|
2
|
+
import { plugin as typescriptPlugin } from '@graphql-codegen/typescript';
|
|
3
|
+
export const plugin = (schema, documents, config) => {
|
|
4
|
+
// * We don't allow the other @graphql-codegen/typescript options as they could break the generator and the types.
|
|
5
|
+
const { scalars } = config;
|
|
6
|
+
const conf = {
|
|
7
|
+
scalars,
|
|
8
|
+
declarationKind: 'type',
|
|
9
|
+
enumsAsTypes: true,
|
|
10
|
+
// * Add underscore to args type to avoid conflicts with the generated types
|
|
11
|
+
// * See: https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#addunderscoretoargstype
|
|
12
|
+
addUnderscoreToArgsType: true,
|
|
13
|
+
};
|
|
14
|
+
const minifiedData = minifyIntrospectionQuery(getIntrospectedSchema(schema), {
|
|
15
|
+
includeDirectives: false,
|
|
16
|
+
includeEnums: true,
|
|
17
|
+
includeInputs: true,
|
|
18
|
+
includeScalars: true,
|
|
19
|
+
});
|
|
20
|
+
const { prepend, content } = typescriptPlugin(schema, documents, conf);
|
|
21
|
+
// * https://stackoverflow.com/questions/2008279/validate-a-javascript-function-name
|
|
22
|
+
const types = Array.from(content.matchAll(/^export type ([$A-Z_][0-9A-Z_$]*) = /gim))
|
|
23
|
+
.map(([, name]) => `\n${name}: ${name}`)
|
|
24
|
+
.join(',');
|
|
25
|
+
const result = `
|
|
26
|
+
export default {
|
|
27
|
+
introspection: ${JSON.stringify(minifiedData, null, 2).replace(/^/gm, ' ').slice(2)} as const,
|
|
28
|
+
types: {} as {${types.replace(/^/gm, ' ').slice(4)}
|
|
29
|
+
}
|
|
30
|
+
}`;
|
|
31
|
+
return {
|
|
32
|
+
prepend,
|
|
33
|
+
content: [content, result].join('\n'),
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export default plugin;
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@graphql-codegen/typescript-nhost",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "GraphQL Code Generator plugin for the Typescript Nhost SDK",
|
|
5
|
+
"peerDependencies": {
|
|
6
|
+
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"@graphql-codegen/plugin-helpers": "^4.0.0",
|
|
10
|
+
"@graphql-codegen/typescript": "^3.0.0",
|
|
11
|
+
"@graphql-codegen/visitor-plugin-common": "3.0.0",
|
|
12
|
+
"@urql/introspection": "^1.0.0",
|
|
13
|
+
"tslib": "~2.5.0"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/dotansimha/graphql-code-generator-community.git",
|
|
18
|
+
"directory": "packages/plugins/typescript/nhost"
|
|
19
|
+
},
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"main": "cjs/index.js",
|
|
22
|
+
"module": "esm/index.js",
|
|
23
|
+
"typings": "typings/index.d.ts",
|
|
24
|
+
"typescript": {
|
|
25
|
+
"definition": "typings/index.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"require": {
|
|
31
|
+
"types": "./typings/index.d.cts",
|
|
32
|
+
"default": "./cjs/index.js"
|
|
33
|
+
},
|
|
34
|
+
"import": {
|
|
35
|
+
"types": "./typings/index.d.ts",
|
|
36
|
+
"default": "./esm/index.js"
|
|
37
|
+
},
|
|
38
|
+
"default": {
|
|
39
|
+
"types": "./typings/index.d.ts",
|
|
40
|
+
"default": "./esm/index.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RawTypesConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
+
/**
|
|
3
|
+
* @description This plugin generates the Typescript schema that enables queries and mutations to be typed in the Nhost SDK.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export interface NhostPluginConfig extends Pick<RawTypesConfig, 'scalars'> {
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RawTypesConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
+
/**
|
|
3
|
+
* @description This plugin generates the Typescript schema that enables queries and mutations to be typed in the Nhost SDK.
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
export interface NhostPluginConfig extends Pick<RawTypesConfig, 'scalars'> {
|
|
7
|
+
}
|