UNPKG

10.4 kBSource Map (JSON)View Raw
1{"version":3,"file":"index.cjs.js","sources":["../../../dist/plugins/typescript/stencil-apollo/src/config.js","../../../dist/plugins/typescript/stencil-apollo/src/visitor.js","../../../dist/plugins/typescript/stencil-apollo/src/index.js"],"sourcesContent":["export var StencilComponentType;\n(function (StencilComponentType) {\n StencilComponentType[\"functional\"] = \"functional\";\n StencilComponentType[\"class\"] = \"class\";\n})(StencilComponentType || (StencilComponentType = {}));\n//# sourceMappingURL=config.js.map","import { ClientSideBaseVisitor, getConfigValue, } from '@graphql-codegen/visitor-plugin-common';\nimport { StencilComponentType } from './config';\nimport autoBind from 'auto-bind';\nimport { paramCase } from 'change-case-all';\nimport { pascalCase } from 'change-case-all';\nexport class StencilApolloVisitor extends ClientSideBaseVisitor {\n constructor(schema, fragments, rawConfig) {\n super(schema, fragments, rawConfig, {\n componentType: getConfigValue(rawConfig.componentType, StencilComponentType.functional),\n noExport: rawConfig.componentType === StencilComponentType.class,\n });\n autoBind(this);\n }\n getImports() {\n const baseImports = super.getImports();\n const imports = [];\n const hasOperations = this._collectedOperations.length > 0;\n if (!hasOperations) {\n return baseImports;\n }\n if (this.config.componentType === StencilComponentType.class) {\n imports.push(`import 'stencil-apollo';`);\n imports.push(`import { Component, Prop, h } from '@stencil/core';`);\n }\n else {\n imports.push(`import * as StencilApollo from 'stencil-apollo';`);\n imports.push(`import { h } from '@stencil/core';`);\n }\n return [...baseImports, ...imports];\n }\n _buildOperationFunctionalComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {\n const operationName = this.convertName(node.name.value);\n const propsTypeName = this.convertName(operationName + 'Props');\n const rendererSignature = pascalCase(`${operationType}Renderer`) + `<${operationResultType}, ${operationVariablesTypes}>`;\n const apolloStencilComponentTag = paramCase(`Apollo${operationType}`);\n const componentName = this.convertName(`${operationName}Component`);\n const propsVar = `\nexport type ${propsTypeName} = {\n variables ?: ${operationVariablesTypes};\n inlist ?: StencilApollo.${rendererSignature};\n};\n `;\n const component = `\nexport const ${componentName} = (props: ${propsTypeName}, children: [StencilApollo.${rendererSignature}]) => (\n <${apolloStencilComponentTag} ${operationType.toLowerCase()}={ ${documentVariableName} } { ...props } renderer={ children[0] } />\n);\n `;\n return [propsVar, component].filter(a => a).join('\\n');\n }\n _buildClassComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {\n const componentName = this.convertName(node.name.value + 'Component');\n const apolloStencilComponentTag = paramCase(`Apollo${operationType}`);\n const rendererSignature = pascalCase(`${operationType}Renderer`);\n return `\n@Component({\n tag: '${paramCase(`Apollo${pascalCase(node.name.value)}`)}'\n})\nexport class ${componentName} {\n @Prop() renderer: import('stencil-apollo').${rendererSignature}<${operationResultType}, ${operationVariablesTypes}>;\n @Prop() variables: ${operationVariablesTypes};\n render() {\n return <${apolloStencilComponentTag} ${operationType.toLowerCase()}={ ${documentVariableName} } variables={ this.variables } renderer={ this.renderer } />;\n }\n}\n `;\n }\n buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {\n switch (this.config.componentType) {\n case StencilComponentType.class:\n return this._buildClassComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes);\n case StencilComponentType.functional:\n return this._buildOperationFunctionalComponent(node, documentVariableName, operationType, operationResultType, operationVariablesTypes);\n default:\n return '';\n }\n }\n}\n//# sourceMappingURL=visitor.js.map","import { visit, concatAST, Kind } from 'graphql';\nimport { StencilApolloVisitor } from './visitor';\nimport { extname } from 'path';\nexport const plugin = (schema, documents, config) => {\n const allAst = concatAST(documents.map(v => v.document));\n const allFragments = [\n ...allAst.definitions.filter(d => d.kind === Kind.FRAGMENT_DEFINITION).map(fragmentDef => ({\n node: fragmentDef,\n name: fragmentDef.name.value,\n onType: fragmentDef.typeCondition.name.value,\n isExternal: false,\n })),\n ...(config.externalFragments || []),\n ];\n const visitor = new StencilApolloVisitor(schema, allFragments, config);\n const visitorResult = visit(allAst, { leave: visitor });\n return {\n prepend: visitor.getImports(),\n content: ['', visitor.fragments, ...visitorResult.definitions.filter(t => typeof t === 'string')].join('\\n'),\n };\n};\nexport const validate = async (schema, documents, config, outputFile) => {\n if (extname(outputFile) !== '.tsx') {\n throw new Error(`Plugin \"stencil-apollo\" requires extension to be \".tsx\"!`);\n }\n};\nexport { StencilApolloVisitor };\n//# sourceMappingURL=index.js.map"],"names":["ClientSideBaseVisitor","getConfigValue","pascalCase","paramCase","concatAST","Kind","visit","extname"],"mappings":";;;;;;;;;;;;AAAO,IAAI,oBAAoB,CAAC;AAChC,CAAC,UAAU,oBAAoB,EAAE;AACjC,IAAI,oBAAoB,CAAC,YAAY,CAAC,GAAG,YAAY,CAAC;AACtD,IAAI,oBAAoB,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;AAC5C,CAAC,EAAE,oBAAoB,KAAK,oBAAoB,GAAG,EAAE,CAAC,CAAC;;ACChD,MAAM,oBAAoB,SAASA,yCAAqB,CAAC;AAChE,IAAI,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC9C,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC5C,YAAY,aAAa,EAAEC,kCAAc,CAAC,SAAS,CAAC,aAAa,EAAE,oBAAoB,CAAC,UAAU,CAAC;AACnG,YAAY,QAAQ,EAAE,SAAS,CAAC,aAAa,KAAK,oBAAoB,CAAC,KAAK;AAC5E,SAAS,CAAC,CAAC;AACX,QAAQ,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvB,KAAK;AACL,IAAI,UAAU,GAAG;AACjB,QAAQ,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC;AAC/C,QAAQ,MAAM,OAAO,GAAG,EAAE,CAAC;AAC3B,QAAQ,MAAM,aAAa,GAAG,IAAI,CAAC,oBAAoB,CAAC,MAAM,GAAG,CAAC,CAAC;AACnE,QAAQ,IAAI,CAAC,aAAa,EAAE;AAC5B,YAAY,OAAO,WAAW,CAAC;AAC/B,SAAS;AACT,QAAQ,IAA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