@graphql-codegen/typescript-graphql-request 4.3.8-alpha-4a7e799f2.0 → 4.4.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.
Files changed (3) hide show
  1. package/index.js +5 -4
  2. package/index.mjs +5 -4
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -11,7 +11,7 @@ const autoBind = _interopDefault(require('auto-bind'));
11
11
  const path = require('path');
12
12
 
13
13
  const additionalExportedTypes = `
14
- export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string) => Promise<T>;
14
+ export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
15
15
  `;
16
16
  class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
17
17
  constructor(schema, fragments, rawConfig) {
@@ -60,6 +60,7 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
60
60
  const extraVariables = [];
61
61
  const allPossibleActions = this._operationsToInclude
62
62
  .map(o => {
63
+ const operationType = o.node.operation;
63
64
  const operationName = o.node.name.value;
64
65
  const optionalVariables = !o.node.variableDefinitions ||
65
66
  o.node.variableDefinitions.length === 0 ||
@@ -72,12 +73,12 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
72
73
  extraVariables.push(`const ${docArg} = print(${docVarName});`);
73
74
  }
74
75
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: ${this.config.extensionsType}; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {
75
- return withWrapper((wrappedRequestHeaders) => client.rawRequest<${o.operationResultType}>(${docArg}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}');
76
+ return withWrapper((wrappedRequestHeaders) => client.rawRequest<${o.operationResultType}>(${docArg}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}', '${operationType}');
76
77
  }`;
77
78
  }
78
79
  else {
79
80
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<${o.operationResultType}> {
80
- return withWrapper((wrappedRequestHeaders) => client.request<${o.operationResultType}>(${docVarName}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}');
81
+ return withWrapper((wrappedRequestHeaders) => client.request<${o.operationResultType}>(${docVarName}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}', '${operationType}');
81
82
  }`;
82
83
  }
83
84
  })
@@ -85,7 +86,7 @@ class GraphQLRequestVisitor extends visitorPluginCommon.ClientSideBaseVisitor {
85
86
  .map(s => visitorPluginCommon.indentMultiline(s, 2));
86
87
  return `${additionalExportedTypes}
87
88
 
88
- const defaultWrapper: SdkFunctionWrapper = (action, _operationName) => action();
89
+ const defaultWrapper: SdkFunctionWrapper = (action, _operationName, _operationType) => action();
89
90
  ${extraVariables.join('\n')}
90
91
  export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
91
92
  return {
package/index.mjs CHANGED
@@ -5,7 +5,7 @@ import autoBind from 'auto-bind';
5
5
  import { extname } from 'path';
6
6
 
7
7
  const additionalExportedTypes = `
8
- export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string) => Promise<T>;
8
+ export type SdkFunctionWrapper = <T>(action: (requestHeaders?:Record<string, string>) => Promise<T>, operationName: string, operationType?: string) => Promise<T>;
9
9
  `;
10
10
  class GraphQLRequestVisitor extends ClientSideBaseVisitor {
11
11
  constructor(schema, fragments, rawConfig) {
@@ -54,6 +54,7 @@ class GraphQLRequestVisitor extends ClientSideBaseVisitor {
54
54
  const extraVariables = [];
55
55
  const allPossibleActions = this._operationsToInclude
56
56
  .map(o => {
57
+ const operationType = o.node.operation;
57
58
  const operationName = o.node.name.value;
58
59
  const optionalVariables = !o.node.variableDefinitions ||
59
60
  o.node.variableDefinitions.length === 0 ||
@@ -66,12 +67,12 @@ class GraphQLRequestVisitor extends ClientSideBaseVisitor {
66
67
  extraVariables.push(`const ${docArg} = print(${docVarName});`);
67
68
  }
68
69
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<{ data?: ${o.operationResultType} | undefined; extensions?: ${this.config.extensionsType}; headers: Dom.Headers; status: number; errors?: GraphQLError[] | undefined; }> {
69
- return withWrapper((wrappedRequestHeaders) => client.rawRequest<${o.operationResultType}>(${docArg}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}');
70
+ return withWrapper((wrappedRequestHeaders) => client.rawRequest<${o.operationResultType}>(${docArg}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}', '${operationType}');
70
71
  }`;
71
72
  }
72
73
  else {
73
74
  return `${operationName}(variables${optionalVariables ? '?' : ''}: ${o.operationVariablesTypes}, requestHeaders?: Dom.RequestInit["headers"]): Promise<${o.operationResultType}> {
74
- return withWrapper((wrappedRequestHeaders) => client.request<${o.operationResultType}>(${docVarName}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}');
75
+ return withWrapper((wrappedRequestHeaders) => client.request<${o.operationResultType}>(${docVarName}, variables, {...requestHeaders, ...wrappedRequestHeaders}), '${operationName}', '${operationType}');
75
76
  }`;
76
77
  }
77
78
  })
@@ -79,7 +80,7 @@ class GraphQLRequestVisitor extends ClientSideBaseVisitor {
79
80
  .map(s => indentMultiline(s, 2));
80
81
  return `${additionalExportedTypes}
81
82
 
82
- const defaultWrapper: SdkFunctionWrapper = (action, _operationName) => action();
83
+ const defaultWrapper: SdkFunctionWrapper = (action, _operationName, _operationType) => action();
83
84
  ${extraVariables.join('\n')}
84
85
  export function getSdk(client: GraphQLClient, withWrapper: SdkFunctionWrapper = defaultWrapper) {
85
86
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/typescript-graphql-request",
3
- "version": "4.3.8-alpha-4a7e799f2.0",
3
+ "version": "4.4.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 || ^16.0.0",
@@ -8,8 +8,8 @@
8
8
  "graphql-tag": "^2.0.0"
9
9
  },
10
10
  "dependencies": {
11
- "@graphql-codegen/plugin-helpers": "2.4.2-alpha-4a7e799f2.0",
12
- "@graphql-codegen/visitor-plugin-common": "2.7.2-alpha-4a7e799f2.0",
11
+ "@graphql-codegen/plugin-helpers": "^2.4.0",
12
+ "@graphql-codegen/visitor-plugin-common": "2.7.1",
13
13
  "auto-bind": "~4.0.0",
14
14
  "tslib": "~2.3.0"
15
15
  },