@graphql-codegen/typescript-graphql-request 3.0.2 → 3.1.0

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/index.cjs.js CHANGED
@@ -22,9 +22,6 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
22
22
  const typeImport = this.config.useTypeImports ? 'import type' : 'import';
23
23
  this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);
24
24
  this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);
25
- if (this.config.documentMode !== visitorPluginCommon.DocumentMode.string) {
26
- this._additionalImports.push(`import { print } from 'graphql';`);
27
- }
28
25
  if (this.config.rawRequest) {
29
26
  this._additionalImports.push(`${typeImport} { GraphQLError } from 'graphql-request/dist/types';`);
30
27
  }
@@ -62,15 +59,14 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
62
59
  o.node.variableDefinitions.length === 0 ||
63
60
  o.node.variableDefinitions.every(v => v.type.kind !== graphql.Kind.NON_NULL_TYPE || v.defaultValue);
64
61
  const docVarName = this.getDocumentNodeVariable(o.documentVariableName);
65
- const doc = this.config.documentMode === visitorPluginCommon.DocumentMode.string ? docVarName : `print(${docVarName})`;
66
62
  if (this.config.rawRequest) {
67
63
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: any; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {
68
- return withWrapper(() => client.rawRequest<${o.operationResultType}>(${doc}, variables, requestHeaders));
64
+ return withWrapper(() => client.rawRequest<${o.operationResultType}>(${docVarName}, variables, requestHeaders));
69
65
  }`;
70
66
  }
71
67
  else {
72
68
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<${o.operationResultType}> {
73
- return withWrapper(() => client.request<${o.operationResultType}>(${doc}, variables, requestHeaders));
69
+ return withWrapper(() => client.request<${o.operationResultType}>(${docVarName}, variables, requestHeaders));
74
70
  }`;
75
71
  }
76
72
  })
package/index.cjs.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../../../dist/plugins/typescript/graphql-request/src/visitor.js","../../../dist/plugins/typescript/graphql-request/src/index.js"],"sourcesContent":["import { ClientSideBaseVisitor, DocumentMode, getConfigValue, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';\nimport autoBind from 'auto-bind';\nimport { Kind, print } from 'graphql';\nconst additionalExportedTypes = `\nexport type SdkFunctionWrapper = <T>(action: () => Promise<T>) => Promise<T>;\n`;\nexport class GraphQLRequestVisitor extends ClientSideBaseVisitor {\n constructor(schema, fragments, rawConfig) {\n super(schema, fragments, rawConfig, {\n rawRequest: getConfigValue(rawConfig.rawRequest, false),\n });\n this._operationsToInclude = [];\n autoBind(this);\n const typeImport = this.config.useTypeImports ? 'import type' : 'import';\n this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);\n this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);\n if (this.config.documentMode !== DocumentMode.string) {\n this._additionalImports.push(`import { print } from 'graphql';`);\n }\n if (this.config.rawRequest) {\n this._additionalImports.push(`${typeImport} { GraphQLError } from 'graphql-request/dist/types';`);\n }\n }\n OperationDefinition(node) {\n var _a;\n const operationName = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value;\n if (!operationName) {\n // eslint-disable-next-line no-console\n console.warn(`Anonymous GraphQL operation was ignored in \"typescript-graphql-request\", please make sure to name your operation: `, print(node));\n return null;\n }\n return super.OperationDefinition(node);\n }\n buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {\n this._operationsToInclude.push({\n node,\n documentVariableName,\n operationType,\n operationResultType,\n operationVariablesTypes,\n });\n return null;\n }\n getDocumentNodeVariable(documentVariableName) {\n return this.config.documentMode === DocumentMode.external\n ? `Operations.${documentVariableName}`\n : documentVariableName;\n }\n get sdkContent() {\n const allPossibleActions = this._operationsToInclude\n .map(o => {\n const operationName = o.node.name.value;\n const optionalVariables = !o.node.variableDefinitions ||\n o.node.variableDefinitions.length === 0 ||\n o.node.variableDefinitions.every(v => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue);\n const docVarName = this.getDocumentNodeVariable(o.documentVariableName);\n const doc = this.config.documentMode === DocumentMode.string ? docVarName : `print(${docVarName})`;\n if (this.config.rawRequest) {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: any; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {\n return withWrapper(() => client.rawRequest<${o.operationResultType}>(${doc}, variables, requestHeaders));\n}`;\n }\n else {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<${o.operationResultType}> {\n return withWrapper(() => client.request<${o.operationResultType}>(${doc}, variables, requestHeaders));\n}`;\n }\n })\n .filter(Boolean)\n .map(s => indentMultiline(s, 2));\n return `${additionalExportedTypes}\n\nconst defaultWrapper: SdkFunctionWrapper = sdkFunction => sdkFunction();\nexport function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {\n return {\n${allPossibleActions.join(',\\n')}\n };\n}\nexport type Sdk = ReturnType<typeof getSdk>;`;\n }\n}\n//# sourceMappingURL=visitor.js.map","import { visit, concatAST, Kind } from 'graphql';\nimport { GraphQLRequestVisitor } 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 GraphQLRequestVisitor(schema, allFragments, config);\n const visitorResult = visit(allAst, { leave: visitor });\n return {\n prepend: visitor.getImports(),\n content: [\n visitor.fragments,\n ...visitorResult.definitions.filter(t => typeof t === 'string'),\n visitor.sdkContent,\n ].join('\\n'),\n };\n};\nexport const validate = async (schema, documents, config, outputFile) => {\n if (extname(outputFile) !== '.ts') {\n throw new Error(`Plugin \"typescript-graphql-request\" requires extension to be \".ts\"!`);\n }\n};\nexport { GraphQLRequestVisitor };\n//# sourceMappingURL=index.js.map"],"names":["ClientSideBaseVisitor","getConfigValue","DocumentMode","print","Kind","indentMultiline","concatAST","visit","extname"],"mappings":";;;;;;;;;;;AAGA,MAAM,uBAAuB,GAAG,CAAC;AACjC;AACA,CAAC,CAAC;AACK,MAAM,qBAAqB,SAASA,yCAAqB,CAAC;AACjE,IAAI,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC9C,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC5C,YAAY,UAAU,EAAEC,kCAAc,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC;AACnE,SAAS,CAAC,CAAC;AACX,QAAQ,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;AACvC,QAAQ,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvB,QAAQ,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,aAAa,GAAG,QAAQ,CAAC;AACjF,QAAQ,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,0CAA0C,CAAC,CAAC,CAAC;AAChG,QAAQ,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,gDAAgD,CAAC,CAAC,CAAC;AACtG,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC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AAG,IAAI,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AAC5E,IAAI,MAAM,aAAa,GAAGG,aAAK,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5D,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE;AACrC,QAAQ,OAAO,EAAE;AACjB,YAAY,OAAO,CAAC,SAAS;AAC7B,YAAY,GAAG,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC3E,YAAY,OAAO,CAAC,UAAU;AAC9B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;AACpB,KAAK,CAAC;AACN,EAAE;AACU,MAAC,QAAQ,GAAG,OAAO,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,KAAK;AACzE,IAAI,IAAIC,YAAO,CAAC,UAAU,CAAC,KAAK,KAAK,EAAE;AACvC,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,mEAAmE,CAAC,CAAC,CAAC;AAC/F,KAAK;AACL;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../../../dist/plugins/typescript/graphql-request/src/visitor.js","../../../dist/plugins/typescript/graphql-request/src/index.js"],"sourcesContent":["import { ClientSideBaseVisitor, DocumentMode, getConfigValue, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';\nimport autoBind from 'auto-bind';\nimport { Kind, print } from 'graphql';\nconst additionalExportedTypes = `\nexport type SdkFunctionWrapper = <T>(action: () => Promise<T>) => Promise<T>;\n`;\nexport class GraphQLRequestVisitor extends ClientSideBaseVisitor {\n constructor(schema, fragments, rawConfig) {\n super(schema, fragments, rawConfig, {\n rawRequest: getConfigValue(rawConfig.rawRequest, false),\n });\n this._operationsToInclude = [];\n autoBind(this);\n const typeImport = this.config.useTypeImports ? 'import type' : 'import';\n this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);\n this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);\n if (this.config.rawRequest) {\n this._additionalImports.push(`${typeImport} { GraphQLError } from 'graphql-request/dist/types';`);\n }\n }\n OperationDefinition(node) {\n var _a;\n const operationName = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value;\n if (!operationName) {\n // eslint-disable-next-line no-console\n console.warn(`Anonymous GraphQL operation was ignored in \"typescript-graphql-request\", please make sure to name your operation: `, print(node));\n return null;\n }\n return super.OperationDefinition(node);\n }\n buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {\n this._operationsToInclude.push({\n node,\n documentVariableName,\n operationType,\n operationResultType,\n operationVariablesTypes,\n });\n return null;\n }\n getDocumentNodeVariable(documentVariableName) {\n return this.config.documentMode === DocumentMode.external\n ? `Operations.${documentVariableName}`\n : documentVariableName;\n }\n get sdkContent() {\n const allPossibleActions = this._operationsToInclude\n .map(o => {\n const operationName = o.node.name.value;\n const optionalVariables = !o.node.variableDefinitions ||\n o.node.variableDefinitions.length === 0 ||\n o.node.variableDefinitions.every(v => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue);\n const docVarName = this.getDocumentNodeVariable(o.documentVariableName);\n if (this.config.rawRequest) {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: any; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {\n return withWrapper(() => client.rawRequest<${o.operationResultType}>(${docVarName}, variables, requestHeaders));\n}`;\n }\n else {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<${o.operationResultType}> {\n return withWrapper(() => client.request<${o.operationResultType}>(${docVarName}, variables, requestHeaders));\n}`;\n }\n })\n .filter(Boolean)\n .map(s => indentMultiline(s, 2));\n return `${additionalExportedTypes}\n\nconst defaultWrapper: SdkFunctionWrapper = sdkFunction => sdkFunction();\nexport function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {\n return {\n${allPossibleActions.join(',\\n')}\n };\n}\nexport type Sdk = ReturnType<typeof getSdk>;`;\n }\n}\n//# sourceMappingURL=visitor.js.map","import { visit, concatAST, Kind } from 'graphql';\nimport { GraphQLRequestVisitor } 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 GraphQLRequestVisitor(schema, allFragments, config);\n const visitorResult = visit(allAst, { leave: visitor });\n return {\n prepend: visitor.getImports(),\n content: [\n visitor.fragments,\n ...visitorResult.definitions.filter(t => typeof t === 'string'),\n visitor.sdkContent,\n ].join('\\n'),\n };\n};\nexport const validate = async (schema, documents, config, outputFile) => {\n if (extname(outputFile) !== '.ts') {\n throw new Error(`Plugin \"typescript-graphql-request\" requires extension to be \".ts\"!`);\n }\n};\nexport { GraphQLRequestVisitor };\n//# sourceMappingURL=index.js.map"],"names":["ClientSideBaseVisitor","getConfigValue","print","DocumentMode","Kind","indentMultiline","concatAST","visit","extname"],"mappings":";;;;;;;;;;;AAGA,MAAM,uBAAuB,GAAG,CAAC;AACjC;AACA,CAAC,CAAC;AACK,MAAM,qBAAqB,SAASA,yCAAqB,CAAC;AACjE,IAAI,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC9C,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC5C,YAAY,UAAU,EAAEC,kCAAc,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC;AACnE,SAAS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,CAAC,CAAC;AACX,QAAQ,IAAI,MAAM,CAAC,iBAAiB,IAAI,EAAE,CAAC;AAC3C,KAAK,CAAC;AACN,IAAI,MAAM,OAAO,GAAG,IAAI,qBAAqB,CAAC,MAAM,EAAE,YAAY,EAAE,MAAM,CAAC,CAAC;AAC5E,IAAI,MAAM,aAAa,GAAGG,aAAK,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;AAC5D,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,OAAO,CAAC,UAAU,EAAE;AACrC,QAAQ,OAAO,EAAE;AACjB,YAAY,OAAO,CAAC,SAAS;AAC7B,YAAY,GAAG,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC;AAC3E,YAAY,OAAO,CAAC,UAAU;AAC9B,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;AACpB,KAAK,CAAC;AACN,EAAE;AACU,MAAC,QAAQ,GAAG,OAAO,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,UAAU,KAAK;AACzE,IAAI,IAAIC,YAAO,CAAC,UAAU,CAAC,KAAK,KAAK,EAAE;AACvC,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,mEAAmE,CAAC,CAAC,CAAC;AAC/F,KAAK;AACL;;;;;;"}
package/index.esm.js CHANGED
@@ -16,9 +16,6 @@ class GraphQLRequestVisitor extends ClientSideBaseVisitor {
16
16
  const typeImport = this.config.useTypeImports ? 'import type' : 'import';
17
17
  this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);
18
18
  this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);
19
- if (this.config.documentMode !== DocumentMode.string) {
20
- this._additionalImports.push(`import { print } from 'graphql';`);
21
- }
22
19
  if (this.config.rawRequest) {
23
20
  this._additionalImports.push(`${typeImport} { GraphQLError } from 'graphql-request/dist/types';`);
24
21
  }
@@ -56,15 +53,14 @@ class GraphQLRequestVisitor extends ClientSideBaseVisitor {
56
53
  o.node.variableDefinitions.length === 0 ||
57
54
  o.node.variableDefinitions.every(v => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue);
58
55
  const docVarName = this.getDocumentNodeVariable(o.documentVariableName);
59
- const doc = this.config.documentMode === DocumentMode.string ? docVarName : `print(${docVarName})`;
60
56
  if (this.config.rawRequest) {
61
57
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: any; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {
62
- return withWrapper(() => client.rawRequest<${o.operationResultType}>(${doc}, variables, requestHeaders));
58
+ return withWrapper(() => client.rawRequest<${o.operationResultType}>(${docVarName}, variables, requestHeaders));
63
59
  }`;
64
60
  }
65
61
  else {
66
62
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<${o.operationResultType}> {
67
- return withWrapper(() => client.request<${o.operationResultType}>(${doc}, variables, requestHeaders));
63
+ return withWrapper(() => client.request<${o.operationResultType}>(${docVarName}, variables, requestHeaders));
68
64
  }`;
69
65
  }
70
66
  })
package/index.esm.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../../../dist/plugins/typescript/graphql-request/src/visitor.js","../../../dist/plugins/typescript/graphql-request/src/index.js"],"sourcesContent":["import { ClientSideBaseVisitor, DocumentMode, getConfigValue, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';\nimport autoBind from 'auto-bind';\nimport { Kind, print } from 'graphql';\nconst additionalExportedTypes = `\nexport type SdkFunctionWrapper = <T>(action: () => Promise<T>) => Promise<T>;\n`;\nexport class GraphQLRequestVisitor extends ClientSideBaseVisitor {\n constructor(schema, fragments, rawConfig) {\n super(schema, fragments, rawConfig, {\n rawRequest: getConfigValue(rawConfig.rawRequest, false),\n });\n this._operationsToInclude = [];\n autoBind(this);\n const typeImport = this.config.useTypeImports ? 'import type' : 'import';\n this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);\n this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);\n if (this.config.documentMode !== DocumentMode.string) {\n this._additionalImports.push(`import { print } from 'graphql';`);\n }\n if (this.config.rawRequest) {\n this._additionalImports.push(`${typeImport} { GraphQLError } from 'graphql-request/dist/types';`);\n }\n }\n OperationDefinition(node) {\n var _a;\n const operationName = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value;\n if (!operationName) {\n // eslint-disable-next-line no-console\n console.warn(`Anonymous GraphQL operation was ignored in \"typescript-graphql-request\", please make sure to name your operation: `, print(node));\n return null;\n }\n return super.OperationDefinition(node);\n }\n buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {\n this._operationsToInclude.push({\n node,\n documentVariableName,\n operationType,\n operationResultType,\n operationVariablesTypes,\n });\n return null;\n }\n getDocumentNodeVariable(documentVariableName) {\n return this.config.documentMode === DocumentMode.external\n ? `Operations.${documentVariableName}`\n : documentVariableName;\n }\n get sdkContent() {\n const allPossibleActions = this._operationsToInclude\n .map(o => {\n const operationName = o.node.name.value;\n const optionalVariables = !o.node.variableDefinitions ||\n o.node.variableDefinitions.length === 0 ||\n o.node.variableDefinitions.every(v => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue);\n const docVarName = this.getDocumentNodeVariable(o.documentVariableName);\n const doc = this.config.documentMode === DocumentMode.string ? docVarName : `print(${docVarName})`;\n if (this.config.rawRequest) {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: any; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {\n return withWrapper(() => client.rawRequest<${o.operationResultType}>(${doc}, variables, requestHeaders));\n}`;\n }\n else {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<${o.operationResultType}> {\n return withWrapper(() => client.request<${o.operationResultType}>(${doc}, variables, requestHeaders));\n}`;\n }\n })\n .filter(Boolean)\n .map(s => indentMultiline(s, 2));\n return `${additionalExportedTypes}\n\nconst defaultWrapper: SdkFunctionWrapper = sdkFunction => sdkFunction();\nexport function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {\n return {\n${allPossibleActions.join(',\\n')}\n };\n}\nexport type Sdk = ReturnType<typeof getSdk>;`;\n }\n}\n//# sourceMappingURL=visitor.js.map","import { visit, concatAST, Kind } from 'graphql';\nimport { GraphQLRequestVisitor } 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 GraphQLRequestVisitor(schema, allFragments, config);\n const visitorResult = visit(allAst, { leave: visitor });\n return {\n prepend: visitor.getImports(),\n content: [\n visitor.fragments,\n ...visitorResult.definitions.filter(t => typeof t === 'string'),\n visitor.sdkContent,\n ].join('\\n'),\n };\n};\nexport const validate = async (schema, documents, config, outputFile) => {\n if (extname(outputFile) !== '.ts') {\n throw new Error(`Plugin \"typescript-graphql-request\" requires extension to be \".ts\"!`);\n }\n};\nexport { GraphQLRequestVisitor };\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;AAGA,MAAM,uBAAuB,GAAG,CAAC;AACjC;AACA,CAAC,CAAC;AACK,MAAM,qBAAqB,SAAS,qBAAqB,CAAC;AACjE,IAAI,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC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K,CAAC,CAAC,mEAAmE,CAAC,CAAC,CAAC;AAC/F,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../../../dist/plugins/typescript/graphql-request/src/visitor.js","../../../dist/plugins/typescript/graphql-request/src/index.js"],"sourcesContent":["import { ClientSideBaseVisitor, DocumentMode, getConfigValue, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';\nimport autoBind from 'auto-bind';\nimport { Kind, print } from 'graphql';\nconst additionalExportedTypes = `\nexport type SdkFunctionWrapper = <T>(action: () => Promise<T>) => Promise<T>;\n`;\nexport class GraphQLRequestVisitor extends ClientSideBaseVisitor {\n constructor(schema, fragments, rawConfig) {\n super(schema, fragments, rawConfig, {\n rawRequest: getConfigValue(rawConfig.rawRequest, false),\n });\n this._operationsToInclude = [];\n autoBind(this);\n const typeImport = this.config.useTypeImports ? 'import type' : 'import';\n this._additionalImports.push(`${typeImport} { GraphQLClient } from 'graphql-request';`);\n this._additionalImports.push(`${typeImport} * as Dom from 'graphql-request/dist/types.dom';`);\n if (this.config.rawRequest) {\n this._additionalImports.push(`${typeImport} { GraphQLError } from 'graphql-request/dist/types';`);\n }\n }\n OperationDefinition(node) {\n var _a;\n const operationName = (_a = node.name) === null || _a === void 0 ? void 0 : _a.value;\n if (!operationName) {\n // eslint-disable-next-line no-console\n console.warn(`Anonymous GraphQL operation was ignored in \"typescript-graphql-request\", please make sure to name your operation: `, print(node));\n return null;\n }\n return super.OperationDefinition(node);\n }\n buildOperation(node, documentVariableName, operationType, operationResultType, operationVariablesTypes) {\n this._operationsToInclude.push({\n node,\n documentVariableName,\n operationType,\n operationResultType,\n operationVariablesTypes,\n });\n return null;\n }\n getDocumentNodeVariable(documentVariableName) {\n return this.config.documentMode === DocumentMode.external\n ? `Operations.${documentVariableName}`\n : documentVariableName;\n }\n get sdkContent() {\n const allPossibleActions = this._operationsToInclude\n .map(o => {\n const operationName = o.node.name.value;\n const optionalVariables = !o.node.variableDefinitions ||\n o.node.variableDefinitions.length === 0 ||\n o.node.variableDefinitions.every(v => v.type.kind !== Kind.NON_NULL_TYPE || v.defaultValue);\n const docVarName = this.getDocumentNodeVariable(o.documentVariableName);\n if (this.config.rawRequest) {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: any; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {\n return withWrapper(() => client.rawRequest<${o.operationResultType}>(${docVarName}, variables, requestHeaders));\n}`;\n }\n else {\n return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit[\"headers\"]): Promise<${o.operationResultType}> {\n return withWrapper(() => client.request<${o.operationResultType}>(${docVarName}, variables, requestHeaders));\n}`;\n }\n })\n .filter(Boolean)\n .map(s => indentMultiline(s, 2));\n return `${additionalExportedTypes}\n\nconst defaultWrapper: SdkFunctionWrapper = sdkFunction => sdkFunction();\nexport function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {\n return {\n${allPossibleActions.join(',\\n')}\n };\n}\nexport type Sdk = ReturnType<typeof getSdk>;`;\n }\n}\n//# sourceMappingURL=visitor.js.map","import { visit, concatAST, Kind } from 'graphql';\nimport { GraphQLRequestVisitor } 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 GraphQLRequestVisitor(schema, allFragments, config);\n const visitorResult = visit(allAst, { leave: visitor });\n return {\n prepend: visitor.getImports(),\n content: [\n visitor.fragments,\n ...visitorResult.definitions.filter(t => typeof t === 'string'),\n visitor.sdkContent,\n ].join('\\n'),\n };\n};\nexport const validate = async (schema, documents, config, outputFile) => {\n if (extname(outputFile) !== '.ts') {\n throw new Error(`Plugin \"typescript-graphql-request\" requires extension to be \".ts\"!`);\n }\n};\nexport { GraphQLRequestVisitor };\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;;AAGA,MAAM,uBAAuB,GAAG,CAAC;AACjC;AACA,CAAC,CAAC;AACK,MAAM,qBAAqB,SAAS,qBAAqB,CAAC;AACjE,IAAI,WAAW,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC9C,QAAQ,KAAK,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE;AAC5C,YAAY,UAAU,EAAE,cAAc,CAAC,SAAS,CAAC,UAAU,EAAE,KAAK,CAAC;AACnE,SAAS,CAAC,CAAC;AACX,QAAQ,IAAI,CAAC,oBAAoB,GAAG,EAAE,CAAC;AACvC,QAAQ,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvB,QAAQ,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,aAAa,GAAG,QAAQ,CAAC;AACjF,QAAQ,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,0CAA0C,CAAC,CAAC,CAAC;AAChG,QAAQ,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,gDAAgD,CAAC,CAAC,CAAC;AACtG,QAAQ,IAAI,IAAI,CAAC,MAAM,CAAC,UAAU,EAAE;AACpC,YAAY,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,oDAAoD,CAAC,CAAC,CAAC;AAC9G,SAAS;AACT,KAAK;AACL,IAAI,mBAAmB,CAAC,IAAI,EAAE;AAC9B,QAAQ,IAAI,EAAE,CAAC;AACf,QAAQ,MAAM,aAAa,GAAG,CAAC,EAAE,GAAG,IAAI,CAAC,IAAI,MAAM,IAAI,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C,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,mEAAmE,CAAC,CAAC,CAAC;AAC/F,KAAK;AACL;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-graphql-request",
3
- "version": "3.0.2",
3
+ "version": "3.1.0",
4
4
  "description": "GraphQL Code Generator plugin for generating a ready-to-use SDK based on graphql-request and GraphQL operations",
5
5
  "peerDependencies": {
6
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",
@@ -8,8 +8,8 @@
8
8
  "graphql-tag": "^2.0.0"
9
9
  },
10
10
  "dependencies": {
11
- "@graphql-codegen/plugin-helpers": "^1.18.2",
12
- "@graphql-codegen/visitor-plugin-common": "^1.18.3",
11
+ "@graphql-codegen/plugin-helpers": "^1.18.3",
12
+ "@graphql-codegen/visitor-plugin-common": "^1.19.0",
13
13
  "auto-bind": "~4.0.0",
14
14
  "tslib": "~2.1.0"
15
15
  },