UNPKG

@powership/server

Version:
1 lines 2.44 kB
{"version":3,"file":"generateTypes.mjs","names":["formatWithPrettier","gql_utils","generateTypes","schema","utils","generateClientUtils","extendedUtils","singleQuote","parser"],"sources":["../../src/graphql/generateTypes.ts"],"sourcesContent":["import { GraphQLSchemaWithUtils } from '@powership/schema';\nimport { formatWithPrettier } from '@powership/utils';\n\nexport let gql_utils = '';\n\nexport async function generateTypes(\n schema: GraphQLSchemaWithUtils\n): Promise<string> {\n //\n if (gql_utils) return gql_utils;\n\n gql_utils = await schema.utils.generateClientUtils();\n gql_utils = `${gql_utils}\\n\\n${extendedUtils}`;\n\n gql_utils = await formatWithPrettier(gql_utils, {\n singleQuote: true,\n parser: 'typescript',\n });\n\n return gql_utils;\n}\n\nconst extendedUtils = `\nimport type { Compute } from '@powership/utils';\n\nexport type Ulid = string;\n\nexport type UseGraphQLConfig<K extends GraphQLEntry['name']> =\n ExpectedGraphQLClient[K]['args'] extends undefined\n ? { data?: Record<string, never> }\n : { data: ExpectedGraphQLClient[K]['args'] };\n\nconst fetchHelpers: Record<string, GraphQLFetchParams<any>> = {};\n\nexport function parseClientBody<K extends GraphQLEntry['name']>(\n method: K,\n config?: UseGraphQLConfig<K>\n) {\n const helpers = (() => {\n return (fetchHelpers[method] =\n fetchHelpers[method] || getGraphQLFetchHelpers(method));\n })();\n\n return {\n ...config,\n data: helpers.getBody(config?.data || ({} as any)),\n };\n}\n\n\nexport type GraphQLMethodResponse<MethodName extends GraphQLEntry['name']> =\n Compute<\n Exclude<\n Exclude<\n GraphQLClientResponse<\n ExpectedGraphQLClient[MethodName]['payload']\n >['data'],\n null\n >['data'],\n null\n >\n >;\n`;\n"],"mappings":"AACA,SAASA,kBAAkB,QAAQ,kBAAkB;AAErD,OAAO,IAAIC,SAAS,GAAG,EAAE;AAEzB,OAAO,eAAeC,aAAaA,CACjCC,MAA8B,EACb;EACjB;EACA,IAAIF,SAAS,EAAE,OAAOA,SAAS;EAE/BA,SAAS,GAAG,MAAME,MAAM,CAACC,KAAK,CAACC,mBAAmB,CAAC,CAAC;EACpDJ,SAAS,GAAG,GAAGA,SAAS,OAAOK,aAAa,EAAE;EAE9CL,SAAS,GAAG,MAAMD,kBAAkB,CAACC,SAAS,EAAE;IAC9CM,WAAW,EAAE,IAAI;IACjBC,MAAM,EAAE;EACV,CAAC,CAAC;EAEF,OAAOP,SAAS;AAClB;AAEA,MAAMK,aAAa,GAAG;AACtB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC","ignoreList":[]}