@powership/server
Version:
62 lines (54 loc) • 1.65 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.generateTypes = generateTypes;
exports.gql_utils = void 0;
var _utils = require("@powership/utils");
let gql_utils = exports.gql_utils = '';
async function generateTypes(schema) {
//
if (gql_utils) return gql_utils;
exports.gql_utils = gql_utils = await schema.utils.generateClientUtils();
exports.gql_utils = gql_utils = `${gql_utils}\n\n${extendedUtils}`;
exports.gql_utils = gql_utils = await (0, _utils.formatWithPrettier)(gql_utils, {
singleQuote: true,
parser: 'typescript'
});
return gql_utils;
}
const extendedUtils = `
import type { Compute } from '@powership/utils';
export type Ulid = string;
export type UseGraphQLConfig<K extends GraphQLEntry['name']> =
ExpectedGraphQLClient[K]['args'] extends undefined
? { data?: Record<string, never> }
: { data: ExpectedGraphQLClient[K]['args'] };
const fetchHelpers: Record<string, GraphQLFetchParams<any>> = {};
export function parseClientBody<K extends GraphQLEntry['name']>(
method: K,
config?: UseGraphQLConfig<K>
) {
const helpers = (() => {
return (fetchHelpers[method] =
fetchHelpers[method] || getGraphQLFetchHelpers(method));
})();
return {
...config,
data: helpers.getBody(config?.data || ({} as any)),
};
}
export type GraphQLMethodResponse<MethodName extends GraphQLEntry['name']> =
Compute<
Exclude<
Exclude<
GraphQLClientResponse<
ExpectedGraphQLClient[MethodName]['payload']
>['data'],
null
>['data'],
null
>
>;
`;
//# sourceMappingURL=generateTypes.cjs.map