@graphql-codegen/c-sharp-operations 3.0.0 → 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/cjs/visitor.js CHANGED
@@ -22,11 +22,13 @@ class CSharpOperationsVisitor extends visitor_plugin_common_1.ClientSideBaseVisi
22
22
  subscriptionSuffix: rawConfig.subscriptionSuffix || defaultSuffix,
23
23
  scalars: (0, visitor_plugin_common_1.buildScalarsFromConfig)(schema, rawConfig, c_sharp_common_1.C_SHARP_SCALARS),
24
24
  typesafeOperation: rawConfig.typesafeOperation || false,
25
+ memberNamingFunction: (0, c_sharp_common_1.getMemberNamingFunction)(rawConfig),
25
26
  }, documents);
26
27
  this._operationsToInclude = [];
27
28
  this.overruleConfigSettings();
28
29
  (0, auto_bind_1.default)(this);
29
30
  this._schemaAST = (0, plugin_helpers_1.getCachedDocumentNodeFromSchema)(schema);
31
+ this._fragmentList = fragments;
30
32
  }
31
33
  // Some settings aren't supported with C#, overruled here
32
34
  overruleConfigSettings() {
@@ -71,7 +73,11 @@ class CSharpOperationsVisitor extends visitor_plugin_common_1.ClientSideBaseVisi
71
73
  return name;
72
74
  }
73
75
  _gql(node) {
74
- const fragments = this._transformFragments(node);
76
+ const includeNestedFragments = this.config.documentMode === visitor_plugin_common_1.DocumentMode.documentNode ||
77
+ this.config.documentMode === visitor_plugin_common_1.DocumentMode.string ||
78
+ (this.config.dedupeFragments && node.kind === 'OperationDefinition');
79
+ const fragmentNames = this._extractFragments(node, includeNestedFragments);
80
+ const fragments = this._transformFragments(fragmentNames);
75
81
  const doc = this._prepareDocument([(0, graphql_1.print)(node), this._includeFragments(fragments, node.kind)].join('\n'));
76
82
  return doc.replace(/"/g, '""');
77
83
  }
@@ -87,7 +93,7 @@ class CSharpOperationsVisitor extends visitor_plugin_common_1.ClientSideBaseVisi
87
93
  const name = variable.variable.name.value;
88
94
  const baseType = !(0, graphql_1.isScalarType)(schemaType)
89
95
  ? innerType.name.value
90
- : this.scalars[schemaType.name] || 'object';
96
+ : this.scalars[schemaType.name].input || 'object';
91
97
  const listType = (0, c_sharp_common_1.getListTypeField)(typeNode);
92
98
  const required = (0, c_sharp_common_1.getListInnerTypeNode)(typeNode).kind === graphql_1.Kind.NON_NULL_TYPE;
93
99
  return {
@@ -125,9 +131,9 @@ class CSharpOperationsVisitor extends visitor_plugin_common_1.ClientSideBaseVisi
125
131
  const baseType = this.scalars[schemaType.name];
126
132
  result = new c_sharp_common_1.CSharpFieldType({
127
133
  baseType: {
128
- type: baseType,
134
+ type: baseType.output,
129
135
  required,
130
- valueType: (0, c_sharp_common_1.isValueType)(baseType),
136
+ valueType: (0, c_sharp_common_1.isValueType)(baseType.output),
131
137
  },
132
138
  listType,
133
139
  });
@@ -204,9 +210,10 @@ class CSharpOperationsVisitor extends visitor_plugin_common_1.ClientSideBaseVisi
204
210
  const responseType = this.resolveFieldType(fieldSchema.type);
205
211
  if (!node.selectionSet) {
206
212
  const responseTypeName = (0, c_sharp_common_1.wrapFieldType)(responseType, responseType.listType, 'System.Collections.Generic.List');
213
+ const propertyName = (0, c_sharp_common_1.convertSafeName)(this._parsedConfig.memberNamingFunction(node.name.value));
207
214
  return (0, visitor_plugin_common_1.indentMultiline)([
208
215
  `[JsonProperty("${node.name.value}")]`,
209
- `public ${responseTypeName} ${(0, c_sharp_common_1.convertSafeName)(node.name.value)} { get; set; }`,
216
+ `public ${responseTypeName} ${propertyName} { get; set; }`,
210
217
  ].join('\n') + '\n');
211
218
  }
212
219
  const selectionBaseTypeName = `${responseType.baseType.type}Selection`;
@@ -228,14 +235,15 @@ class CSharpOperationsVisitor extends visitor_plugin_common_1.ClientSideBaseVisi
228
235
  return this._getResponseFieldRecursive(s, innerClassSchema);
229
236
  })
230
237
  .join('\n')).string;
238
+ const propertyName = (0, c_sharp_common_1.convertSafeName)(this._parsedConfig.memberNamingFunction(node.name.value));
231
239
  return (0, visitor_plugin_common_1.indentMultiline)([
232
240
  innerClassDefinition,
233
241
  `[JsonProperty("${node.name.value}")]`,
234
- `public ${selectionTypeName} ${(0, c_sharp_common_1.convertSafeName)(node.name.value)} { get; set; }`,
242
+ `public ${selectionTypeName} ${propertyName} { get; set; }`,
235
243
  ].join('\n') + '\n');
236
244
  }
237
245
  case graphql_1.Kind.FRAGMENT_SPREAD: {
238
- const fragmentSchema = this._fragments.find(f => f.name === node.name.value);
246
+ const fragmentSchema = this._fragmentList.find(f => f.name === node.name.value);
239
247
  if (!fragmentSchema) {
240
248
  throw new Error(`Fragment schema not found; ${node.name.value}`);
241
249
  }
@@ -270,9 +278,10 @@ class CSharpOperationsVisitor extends visitor_plugin_common_1.ClientSideBaseVisi
270
278
  ((_b = node.variableDefinitions) === null || _b === void 0 ? void 0 : _b.map(v => {
271
279
  const inputType = this.resolveFieldType(v.type);
272
280
  const inputTypeName = (0, c_sharp_common_1.wrapFieldType)(inputType, inputType.listType, 'System.Collections.Generic.List');
281
+ const propertyName = (0, c_sharp_common_1.convertSafeName)(this._parsedConfig.memberNamingFunction(v.variable.name.value));
273
282
  return (0, visitor_plugin_common_1.indentMultiline)([
274
283
  `[JsonProperty("${v.variable.name.value}")]`,
275
- `public ${inputTypeName} ${(0, c_sharp_common_1.convertSafeName)(v.variable.name.value)} { get; set; }`,
284
+ `public ${inputTypeName} ${propertyName} { get; set; }`,
276
285
  ].join('\n') + '\n');
277
286
  }).join('\n'))).string;
278
287
  }
@@ -407,9 +416,10 @@ ${this._getOperationMethod(node)}
407
416
  }
408
417
  const inputType = this.resolveFieldType(f.type);
409
418
  const inputTypeName = (0, c_sharp_common_1.wrapFieldType)(inputType, inputType.listType, 'System.Collections.Generic.List');
419
+ const propertyName = (0, c_sharp_common_1.convertSafeName)(this._parsedConfig.memberNamingFunction(f.name.value));
410
420
  return (0, visitor_plugin_common_1.indentMultiline)([
411
421
  `[JsonProperty("${f.name.value}")]`,
412
- `public ${inputTypeName} ${(0, c_sharp_common_1.convertSafeName)(f.name.value)} { get; set; }`,
422
+ `public ${inputTypeName} ${propertyName} { get; set; }`,
413
423
  ].join('\n') + '\n');
414
424
  }).filter(f => !!f).join('\n'))).string;
415
425
  return (0, visitor_plugin_common_1.indentMultiline)(inputClass, 2);
@@ -423,7 +433,7 @@ ${this._getOperationMethod(node)}
423
433
  .access('public')
424
434
  .asKind('enum')
425
435
  .withName((0, c_sharp_common_1.convertSafeName)(this.convertName(node.name)))
426
- .withBlock((0, visitor_plugin_common_1.indentMultiline)((_a = node.values) === null || _a === void 0 ? void 0 : _a.map(v => v.name.value).join(',\n'))).string;
436
+ .withBlock((0, visitor_plugin_common_1.indentMultiline)((_a = node.values) === null || _a === void 0 ? void 0 : _a.map(v => this._parsedConfig.memberNamingFunction(v.name.value)).join(',\n'))).string;
427
437
  return (0, visitor_plugin_common_1.indentMultiline)(enumDefinition, 2);
428
438
  }
429
439
  }
package/esm/visitor.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import autoBind from 'auto-bind';
2
2
  import { isEnumType, isInputObjectType, isScalarType, Kind, print, visit, } from 'graphql';
3
- import { C_SHARP_SCALARS, convertSafeName, CSharpDeclarationBlock, CSharpFieldType, getListInnerTypeNode, getListTypeDepth, getListTypeField, isValueType, wrapFieldType, } from '@graphql-codegen/c-sharp-common';
3
+ import { C_SHARP_SCALARS, convertSafeName, CSharpDeclarationBlock, CSharpFieldType, getListInnerTypeNode, getListTypeDepth, getListTypeField, getMemberNamingFunction, isValueType, wrapFieldType, } from '@graphql-codegen/c-sharp-common';
4
4
  import { getCachedDocumentNodeFromSchema } from '@graphql-codegen/plugin-helpers';
5
5
  import { buildScalarsFromConfig, ClientSideBaseVisitor, DocumentMode, getBaseTypeNode, indent, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';
6
6
  const defaultSuffix = 'GQL';
@@ -18,11 +18,13 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor {
18
18
  subscriptionSuffix: rawConfig.subscriptionSuffix || defaultSuffix,
19
19
  scalars: buildScalarsFromConfig(schema, rawConfig, C_SHARP_SCALARS),
20
20
  typesafeOperation: rawConfig.typesafeOperation || false,
21
+ memberNamingFunction: getMemberNamingFunction(rawConfig),
21
22
  }, documents);
22
23
  this._operationsToInclude = [];
23
24
  this.overruleConfigSettings();
24
25
  autoBind(this);
25
26
  this._schemaAST = getCachedDocumentNodeFromSchema(schema);
27
+ this._fragmentList = fragments;
26
28
  }
27
29
  // Some settings aren't supported with C#, overruled here
28
30
  overruleConfigSettings() {
@@ -67,7 +69,11 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor {
67
69
  return name;
68
70
  }
69
71
  _gql(node) {
70
- const fragments = this._transformFragments(node);
72
+ const includeNestedFragments = this.config.documentMode === DocumentMode.documentNode ||
73
+ this.config.documentMode === DocumentMode.string ||
74
+ (this.config.dedupeFragments && node.kind === 'OperationDefinition');
75
+ const fragmentNames = this._extractFragments(node, includeNestedFragments);
76
+ const fragments = this._transformFragments(fragmentNames);
71
77
  const doc = this._prepareDocument([print(node), this._includeFragments(fragments, node.kind)].join('\n'));
72
78
  return doc.replace(/"/g, '""');
73
79
  }
@@ -83,7 +89,7 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor {
83
89
  const name = variable.variable.name.value;
84
90
  const baseType = !isScalarType(schemaType)
85
91
  ? innerType.name.value
86
- : this.scalars[schemaType.name] || 'object';
92
+ : this.scalars[schemaType.name].input || 'object';
87
93
  const listType = getListTypeField(typeNode);
88
94
  const required = getListInnerTypeNode(typeNode).kind === Kind.NON_NULL_TYPE;
89
95
  return {
@@ -121,9 +127,9 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor {
121
127
  const baseType = this.scalars[schemaType.name];
122
128
  result = new CSharpFieldType({
123
129
  baseType: {
124
- type: baseType,
130
+ type: baseType.output,
125
131
  required,
126
- valueType: isValueType(baseType),
132
+ valueType: isValueType(baseType.output),
127
133
  },
128
134
  listType,
129
135
  });
@@ -200,9 +206,10 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor {
200
206
  const responseType = this.resolveFieldType(fieldSchema.type);
201
207
  if (!node.selectionSet) {
202
208
  const responseTypeName = wrapFieldType(responseType, responseType.listType, 'System.Collections.Generic.List');
209
+ const propertyName = convertSafeName(this._parsedConfig.memberNamingFunction(node.name.value));
203
210
  return indentMultiline([
204
211
  `[JsonProperty("${node.name.value}")]`,
205
- `public ${responseTypeName} ${convertSafeName(node.name.value)} { get; set; }`,
212
+ `public ${responseTypeName} ${propertyName} { get; set; }`,
206
213
  ].join('\n') + '\n');
207
214
  }
208
215
  const selectionBaseTypeName = `${responseType.baseType.type}Selection`;
@@ -224,14 +231,15 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor {
224
231
  return this._getResponseFieldRecursive(s, innerClassSchema);
225
232
  })
226
233
  .join('\n')).string;
234
+ const propertyName = convertSafeName(this._parsedConfig.memberNamingFunction(node.name.value));
227
235
  return indentMultiline([
228
236
  innerClassDefinition,
229
237
  `[JsonProperty("${node.name.value}")]`,
230
- `public ${selectionTypeName} ${convertSafeName(node.name.value)} { get; set; }`,
238
+ `public ${selectionTypeName} ${propertyName} { get; set; }`,
231
239
  ].join('\n') + '\n');
232
240
  }
233
241
  case Kind.FRAGMENT_SPREAD: {
234
- const fragmentSchema = this._fragments.find(f => f.name === node.name.value);
242
+ const fragmentSchema = this._fragmentList.find(f => f.name === node.name.value);
235
243
  if (!fragmentSchema) {
236
244
  throw new Error(`Fragment schema not found; ${node.name.value}`);
237
245
  }
@@ -266,9 +274,10 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor {
266
274
  ((_b = node.variableDefinitions) === null || _b === void 0 ? void 0 : _b.map(v => {
267
275
  const inputType = this.resolveFieldType(v.type);
268
276
  const inputTypeName = wrapFieldType(inputType, inputType.listType, 'System.Collections.Generic.List');
277
+ const propertyName = convertSafeName(this._parsedConfig.memberNamingFunction(v.variable.name.value));
269
278
  return indentMultiline([
270
279
  `[JsonProperty("${v.variable.name.value}")]`,
271
- `public ${inputTypeName} ${convertSafeName(v.variable.name.value)} { get; set; }`,
280
+ `public ${inputTypeName} ${propertyName} { get; set; }`,
272
281
  ].join('\n') + '\n');
273
282
  }).join('\n'))).string;
274
283
  }
@@ -403,9 +412,10 @@ ${this._getOperationMethod(node)}
403
412
  }
404
413
  const inputType = this.resolveFieldType(f.type);
405
414
  const inputTypeName = wrapFieldType(inputType, inputType.listType, 'System.Collections.Generic.List');
415
+ const propertyName = convertSafeName(this._parsedConfig.memberNamingFunction(f.name.value));
406
416
  return indentMultiline([
407
417
  `[JsonProperty("${f.name.value}")]`,
408
- `public ${inputTypeName} ${convertSafeName(f.name.value)} { get; set; }`,
418
+ `public ${inputTypeName} ${propertyName} { get; set; }`,
409
419
  ].join('\n') + '\n');
410
420
  }).filter(f => !!f).join('\n'))).string;
411
421
  return indentMultiline(inputClass, 2);
@@ -419,7 +429,7 @@ ${this._getOperationMethod(node)}
419
429
  .access('public')
420
430
  .asKind('enum')
421
431
  .withName(convertSafeName(this.convertName(node.name)))
422
- .withBlock(indentMultiline((_a = node.values) === null || _a === void 0 ? void 0 : _a.map(v => v.name.value).join(',\n'))).string;
432
+ .withBlock(indentMultiline((_a = node.values) === null || _a === void 0 ? void 0 : _a.map(v => this._parsedConfig.memberNamingFunction(v.name.value)).join(',\n'))).string;
423
433
  return indentMultiline(enumDefinition, 2);
424
434
  }
425
435
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-codegen/c-sharp-operations",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "description": "GraphQL Code Generator plugin for generating CSharp code based on GraphQL operations",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -8,9 +8,9 @@
8
8
  "graphql-tag": "2.12.6"
9
9
  },
10
10
  "dependencies": {
11
- "@graphql-codegen/c-sharp-common": "1.0.0",
12
- "@graphql-codegen/plugin-helpers": "^3.0.0",
13
- "@graphql-codegen/visitor-plugin-common": "^2.12.1",
11
+ "@graphql-codegen/c-sharp-common": "1.1.0",
12
+ "@graphql-codegen/plugin-helpers": "5.0.4",
13
+ "@graphql-codegen/visitor-plugin-common": "^5.3.1",
14
14
  "auto-bind": "~4.0.0",
15
15
  "change-case-all": "1.0.15",
16
16
  "tslib": "~2.6.0"
@@ -1,8 +1,9 @@
1
+ import { MemberNameConventionConfig } from '@graphql-codegen/c-sharp-common';
1
2
  import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
2
3
  /**
3
4
  * @description This plugin generates C# `class` based on your GraphQL operations.
4
5
  */
5
- export interface CSharpOperationsRawPluginConfig extends RawClientSideBasePluginConfig {
6
+ export interface CSharpOperationsRawPluginConfig extends RawClientSideBasePluginConfig, MemberNameConventionConfig {
6
7
  /**
7
8
  * @default GraphQLCodeGen
8
9
  * @description Allow you to customize the namespace name.
@@ -1,8 +1,9 @@
1
+ import { MemberNameConventionConfig } from '@graphql-codegen/c-sharp-common';
1
2
  import { RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common';
2
3
  /**
3
4
  * @description This plugin generates C# `class` based on your GraphQL operations.
4
5
  */
5
- export interface CSharpOperationsRawPluginConfig extends RawClientSideBasePluginConfig {
6
+ export interface CSharpOperationsRawPluginConfig extends RawClientSideBasePluginConfig, MemberNameConventionConfig {
6
7
  /**
7
8
  * @default GraphQLCodeGen
8
9
  * @description Allow you to customize the namespace name.
@@ -1,5 +1,5 @@
1
1
  import { EnumTypeDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, OperationDefinitionNode, TypeNode } from 'graphql';
2
- import { CSharpFieldType } from '@graphql-codegen/c-sharp-common';
2
+ import { CSharpFieldType, MemberNamingFn } from '@graphql-codegen/c-sharp-common';
3
3
  import { Types } from '@graphql-codegen/plugin-helpers';
4
4
  import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
5
5
  import { CSharpOperationsRawPluginConfig } from './config.cjs';
@@ -10,10 +10,12 @@ export interface CSharpOperationsPluginConfig extends ClientSideBasePluginConfig
10
10
  mutationSuffix: string;
11
11
  subscriptionSuffix: string;
12
12
  typesafeOperation: boolean;
13
+ memberNamingFunction: MemberNamingFn;
13
14
  }
14
15
  export declare class CSharpOperationsVisitor extends ClientSideBaseVisitor<CSharpOperationsRawPluginConfig, CSharpOperationsPluginConfig> {
15
16
  private _operationsToInclude;
16
17
  private _schemaAST;
18
+ private readonly _fragmentList;
17
19
  constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: CSharpOperationsRawPluginConfig, documents?: Types.DocumentFile[]);
18
20
  private overruleConfigSettings;
19
21
  private _operationHasDirective;
@@ -1,5 +1,5 @@
1
1
  import { EnumTypeDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, OperationDefinitionNode, TypeNode } from 'graphql';
2
- import { CSharpFieldType } from '@graphql-codegen/c-sharp-common';
2
+ import { CSharpFieldType, MemberNamingFn } from '@graphql-codegen/c-sharp-common';
3
3
  import { Types } from '@graphql-codegen/plugin-helpers';
4
4
  import { ClientSideBasePluginConfig, ClientSideBaseVisitor, LoadedFragment } from '@graphql-codegen/visitor-plugin-common';
5
5
  import { CSharpOperationsRawPluginConfig } from './config.js';
@@ -10,10 +10,12 @@ export interface CSharpOperationsPluginConfig extends ClientSideBasePluginConfig
10
10
  mutationSuffix: string;
11
11
  subscriptionSuffix: string;
12
12
  typesafeOperation: boolean;
13
+ memberNamingFunction: MemberNamingFn;
13
14
  }
14
15
  export declare class CSharpOperationsVisitor extends ClientSideBaseVisitor<CSharpOperationsRawPluginConfig, CSharpOperationsPluginConfig> {
15
16
  private _operationsToInclude;
16
17
  private _schemaAST;
18
+ private readonly _fragmentList;
17
19
  constructor(schema: GraphQLSchema, fragments: LoadedFragment[], rawConfig: CSharpOperationsRawPluginConfig, documents?: Types.DocumentFile[]);
18
20
  private overruleConfigSettings;
19
21
  private _operationHasDirective;