@graphql-codegen/c-sharp 4.3.1 → 5.0.0-alpha-20230524082546-d7e1d0a4a
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/config.js +0 -2
- package/cjs/visitor.js +20 -8
- package/esm/config.js +0 -1
- package/esm/index.js +1 -1
- package/esm/visitor.js +21 -9
- package/package.json +8 -5
- package/typings/config.d.cts +1 -1
- package/typings/config.d.ts +1 -1
- package/typings/json-attributes.d.cts +1 -1
- package/typings/json-attributes.d.ts +1 -1
- package/typings/visitor.d.cts +3 -3
- package/typings/visitor.d.ts +3 -3
package/cjs/config.js
CHANGED
package/cjs/visitor.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CSharpResolversVisitor = void 0;
|
|
4
|
-
const
|
|
4
|
+
const change_case_all_1 = require("change-case-all");
|
|
5
5
|
const graphql_1 = require("graphql");
|
|
6
6
|
const c_sharp_common_1 = require("@graphql-codegen/c-sharp-common");
|
|
7
|
-
const
|
|
7
|
+
const visitor_plugin_common_1 = require("@graphql-codegen/visitor-plugin-common");
|
|
8
8
|
const json_attributes_js_1 = require("./json-attributes.js");
|
|
9
9
|
class CSharpResolversVisitor extends visitor_plugin_common_1.BaseVisitor {
|
|
10
10
|
constructor(rawConfig, _schema) {
|
|
@@ -25,7 +25,11 @@ class CSharpResolversVisitor extends visitor_plugin_common_1.BaseVisitor {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
getImports() {
|
|
28
|
-
const allImports = [
|
|
28
|
+
const allImports = [
|
|
29
|
+
'System',
|
|
30
|
+
'System.Collections.Generic',
|
|
31
|
+
'System.ComponentModel.DataAnnotations',
|
|
32
|
+
];
|
|
29
33
|
if (this._parsedConfig.emitJsonAttributes) {
|
|
30
34
|
const jsonAttributesNamespace = this.jsonAttributesConfiguration.namespace;
|
|
31
35
|
allImports.push(jsonAttributesNamespace);
|
|
@@ -62,7 +66,9 @@ class CSharpResolversVisitor extends visitor_plugin_common_1.BaseVisitor {
|
|
|
62
66
|
}
|
|
63
67
|
EnumTypeDefinition(node) {
|
|
64
68
|
const enumName = this.convertName(node.name);
|
|
65
|
-
const enumValues = node.values
|
|
69
|
+
const enumValues = node.values
|
|
70
|
+
.map(enumValue => enumValue(node.name.value))
|
|
71
|
+
.join(',\n');
|
|
66
72
|
const enumBlock = [enumValues].join('\n');
|
|
67
73
|
return new c_sharp_common_1.CSharpDeclarationBlock()
|
|
68
74
|
.access('public')
|
|
@@ -187,14 +193,17 @@ class CSharpResolversVisitor extends visitor_plugin_common_1.BaseVisitor {
|
|
|
187
193
|
}
|
|
188
194
|
buildRecord(name, description, inputValueArray, interfaces) {
|
|
189
195
|
const classSummary = (0, c_sharp_common_1.transformComment)(description === null || description === void 0 ? void 0 : description.value);
|
|
190
|
-
const interfaceImpl = interfaces && interfaces.length > 0
|
|
196
|
+
const interfaceImpl = interfaces && interfaces.length > 0
|
|
197
|
+
? ` : ${interfaces.map(ntn => ntn.name.value).join(', ')}`
|
|
198
|
+
: '';
|
|
191
199
|
const recordMembers = inputValueArray
|
|
192
200
|
.map(arg => {
|
|
193
201
|
const fieldType = this.resolveInputFieldType(arg.type);
|
|
194
202
|
const fieldHeader = this.getFieldHeader(arg, fieldType);
|
|
195
203
|
const fieldName = (0, c_sharp_common_1.convertSafeName)((0, change_case_all_1.pascalCase)(this.convertName(arg.name)));
|
|
196
204
|
const csharpFieldType = (0, c_sharp_common_1.wrapFieldType)(fieldType, fieldType.listType, this.config.listType);
|
|
197
|
-
return fieldHeader +
|
|
205
|
+
return (fieldHeader +
|
|
206
|
+
(0, visitor_plugin_common_1.indent)(`public ${csharpFieldType} ${fieldName} { get; init; } = ${fieldName};`));
|
|
198
207
|
})
|
|
199
208
|
.join('\n\n');
|
|
200
209
|
const recordInitializer = inputValueArray
|
|
@@ -216,7 +225,9 @@ ${recordMembers}
|
|
|
216
225
|
}
|
|
217
226
|
buildClass(name, description, inputValueArray, interfaces) {
|
|
218
227
|
const classSummary = (0, c_sharp_common_1.transformComment)(description === null || description === void 0 ? void 0 : description.value);
|
|
219
|
-
const interfaceImpl = interfaces && interfaces.length > 0
|
|
228
|
+
const interfaceImpl = interfaces && interfaces.length > 0
|
|
229
|
+
? ` : ${interfaces.map(ntn => ntn.name.value).join(', ')}`
|
|
230
|
+
: '';
|
|
220
231
|
const classMembers = inputValueArray
|
|
221
232
|
.map(arg => {
|
|
222
233
|
const fieldType = this.resolveInputFieldType(arg.type);
|
|
@@ -290,7 +301,8 @@ ${classMembers}
|
|
|
290
301
|
{
|
|
291
302
|
var value = propertyInfo.GetValue(this);
|
|
292
303
|
var defaultValue = propertyInfo.PropertyType.IsValueType ? Activator.CreateInstance(propertyInfo.PropertyType) : null;
|
|
293
|
-
${this._parsedConfig.emitJsonAttributes &&
|
|
304
|
+
${this._parsedConfig.emitJsonAttributes &&
|
|
305
|
+
this.jsonAttributesConfiguration.requiredAttribute != null
|
|
294
306
|
? `
|
|
295
307
|
var requiredProp = propertyInfo.GetCustomAttributes(typeof(${this.jsonAttributesConfiguration.requiredAttribute}Attribute), false).Length > 0;
|
|
296
308
|
`
|
package/esm/config.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/esm/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCachedDocumentNodeFromSchema, oldVisit } from '@graphql-codegen/plugin-helpers';
|
|
1
|
+
import { getCachedDocumentNodeFromSchema, oldVisit, } from '@graphql-codegen/plugin-helpers';
|
|
2
2
|
import { CSharpResolversVisitor } from './visitor.js';
|
|
3
3
|
export const plugin = async (schema, documents, config) => {
|
|
4
4
|
const visitor = new CSharpResolversVisitor(config, schema);
|
package/esm/visitor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BaseVisitor, indentMultiline, indent, getBaseTypeNode, buildScalarsFromConfig, } from '@graphql-codegen/visitor-plugin-common';
|
|
2
|
-
import { Kind, isScalarType, isInputObjectType, isEnumType, } from 'graphql';
|
|
3
|
-
import { C_SHARP_SCALARS, CSharpDeclarationBlock, transformComment, isValueType, getListInnerTypeNode, CSharpFieldType, convertSafeName, wrapFieldType, getListTypeField, } from '@graphql-codegen/c-sharp-common';
|
|
4
1
|
import { pascalCase } from 'change-case-all';
|
|
2
|
+
import { isEnumType, isInputObjectType, isScalarType, Kind, } from 'graphql';
|
|
3
|
+
import { C_SHARP_SCALARS, convertSafeName, CSharpDeclarationBlock, CSharpFieldType, getListInnerTypeNode, getListTypeField, isValueType, transformComment, wrapFieldType, } from '@graphql-codegen/c-sharp-common';
|
|
4
|
+
import { BaseVisitor, buildScalarsFromConfig, getBaseTypeNode, indent, indentMultiline, } from '@graphql-codegen/visitor-plugin-common';
|
|
5
5
|
import { getJsonAttributeSourceConfiguration, } from './json-attributes.js';
|
|
6
6
|
export class CSharpResolversVisitor extends BaseVisitor {
|
|
7
7
|
constructor(rawConfig, _schema) {
|
|
@@ -22,7 +22,11 @@ export class CSharpResolversVisitor extends BaseVisitor {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
getImports() {
|
|
25
|
-
const allImports = [
|
|
25
|
+
const allImports = [
|
|
26
|
+
'System',
|
|
27
|
+
'System.Collections.Generic',
|
|
28
|
+
'System.ComponentModel.DataAnnotations',
|
|
29
|
+
];
|
|
26
30
|
if (this._parsedConfig.emitJsonAttributes) {
|
|
27
31
|
const jsonAttributesNamespace = this.jsonAttributesConfiguration.namespace;
|
|
28
32
|
allImports.push(jsonAttributesNamespace);
|
|
@@ -59,7 +63,9 @@ export class CSharpResolversVisitor extends BaseVisitor {
|
|
|
59
63
|
}
|
|
60
64
|
EnumTypeDefinition(node) {
|
|
61
65
|
const enumName = this.convertName(node.name);
|
|
62
|
-
const enumValues = node.values
|
|
66
|
+
const enumValues = node.values
|
|
67
|
+
.map(enumValue => enumValue(node.name.value))
|
|
68
|
+
.join(',\n');
|
|
63
69
|
const enumBlock = [enumValues].join('\n');
|
|
64
70
|
return new CSharpDeclarationBlock()
|
|
65
71
|
.access('public')
|
|
@@ -184,14 +190,17 @@ export class CSharpResolversVisitor extends BaseVisitor {
|
|
|
184
190
|
}
|
|
185
191
|
buildRecord(name, description, inputValueArray, interfaces) {
|
|
186
192
|
const classSummary = transformComment(description === null || description === void 0 ? void 0 : description.value);
|
|
187
|
-
const interfaceImpl = interfaces && interfaces.length > 0
|
|
193
|
+
const interfaceImpl = interfaces && interfaces.length > 0
|
|
194
|
+
? ` : ${interfaces.map(ntn => ntn.name.value).join(', ')}`
|
|
195
|
+
: '';
|
|
188
196
|
const recordMembers = inputValueArray
|
|
189
197
|
.map(arg => {
|
|
190
198
|
const fieldType = this.resolveInputFieldType(arg.type);
|
|
191
199
|
const fieldHeader = this.getFieldHeader(arg, fieldType);
|
|
192
200
|
const fieldName = convertSafeName(pascalCase(this.convertName(arg.name)));
|
|
193
201
|
const csharpFieldType = wrapFieldType(fieldType, fieldType.listType, this.config.listType);
|
|
194
|
-
return fieldHeader +
|
|
202
|
+
return (fieldHeader +
|
|
203
|
+
indent(`public ${csharpFieldType} ${fieldName} { get; init; } = ${fieldName};`));
|
|
195
204
|
})
|
|
196
205
|
.join('\n\n');
|
|
197
206
|
const recordInitializer = inputValueArray
|
|
@@ -213,7 +222,9 @@ ${recordMembers}
|
|
|
213
222
|
}
|
|
214
223
|
buildClass(name, description, inputValueArray, interfaces) {
|
|
215
224
|
const classSummary = transformComment(description === null || description === void 0 ? void 0 : description.value);
|
|
216
|
-
const interfaceImpl = interfaces && interfaces.length > 0
|
|
225
|
+
const interfaceImpl = interfaces && interfaces.length > 0
|
|
226
|
+
? ` : ${interfaces.map(ntn => ntn.name.value).join(', ')}`
|
|
227
|
+
: '';
|
|
217
228
|
const classMembers = inputValueArray
|
|
218
229
|
.map(arg => {
|
|
219
230
|
const fieldType = this.resolveInputFieldType(arg.type);
|
|
@@ -287,7 +298,8 @@ ${classMembers}
|
|
|
287
298
|
{
|
|
288
299
|
var value = propertyInfo.GetValue(this);
|
|
289
300
|
var defaultValue = propertyInfo.PropertyType.IsValueType ? Activator.CreateInstance(propertyInfo.PropertyType) : null;
|
|
290
|
-
${this._parsedConfig.emitJsonAttributes &&
|
|
301
|
+
${this._parsedConfig.emitJsonAttributes &&
|
|
302
|
+
this.jsonAttributesConfiguration.requiredAttribute != null
|
|
291
303
|
? `
|
|
292
304
|
var requiredProp = propertyInfo.GetCustomAttributes(typeof(${this.jsonAttributesConfiguration.requiredAttribute}Attribute), false).Length > 0;
|
|
293
305
|
`
|
package/package.json
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/c-sharp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0-alpha-20230524082546-d7e1d0a4a",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating CSharp code based on a GraphQL schema",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
7
7
|
"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
|
},
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@graphql-codegen/
|
|
10
|
+
"@graphql-codegen/c-sharp-common": "1.0.0-alpha-20230524082546-d7e1d0a4a",
|
|
11
|
+
"@graphql-codegen/plugin-helpers": "^3.0.0",
|
|
11
12
|
"@graphql-codegen/visitor-plugin-common": "^2.12.1",
|
|
12
|
-
"
|
|
13
|
+
"change-case-all": "1.0.15",
|
|
13
14
|
"tslib": "~2.4.0",
|
|
14
|
-
"unixify": "^1.0.0"
|
|
15
|
-
"change-case-all": "1.0.14"
|
|
15
|
+
"unixify": "^1.0.0"
|
|
16
16
|
},
|
|
17
17
|
"repository": "git@github.com:dotansimha/graphql-code-generator.git",
|
|
18
18
|
"license": "MIT",
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">= 16.0.0"
|
|
21
|
+
},
|
|
19
22
|
"main": "cjs/index.js",
|
|
20
23
|
"module": "esm/index.js",
|
|
21
24
|
"typings": "typings/index.d.ts",
|
package/typings/config.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumValuesMap, RawConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
2
|
import { JsonAttributesSource } from './json-attributes.cjs';
|
|
3
3
|
/**
|
|
4
4
|
* @description This plugin generates C# `class` identifier for your schema types.
|
package/typings/config.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EnumValuesMap, RawConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
2
2
|
import { JsonAttributesSource } from './json-attributes.js';
|
|
3
3
|
/**
|
|
4
4
|
* @description This plugin generates C# `class` identifier for your schema types.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type JsonAttributesSource = 'Newtonsoft.Json' | 'System.Text.Json';
|
|
2
2
|
export declare class JsonAttributesSourceConfiguration {
|
|
3
3
|
readonly namespace: string;
|
|
4
4
|
readonly propertyAttribute: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type JsonAttributesSource = 'Newtonsoft.Json' | 'System.Text.Json';
|
|
2
2
|
export declare class JsonAttributesSourceConfiguration {
|
|
3
3
|
readonly namespace: string;
|
|
4
4
|
readonly propertyAttribute: string;
|
package/typings/visitor.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CSharpResolversPluginRawConfig } from './config.cjs';
|
|
3
|
-
import { GraphQLSchema, EnumTypeDefinitionNode, EnumValueDefinitionNode, InterfaceTypeDefinitionNode, InputObjectTypeDefinitionNode, ObjectTypeDefinitionNode, FieldDefinitionNode, InputValueDefinitionNode, TypeNode, DirectiveNode, StringValueNode, NamedTypeNode } from 'graphql';
|
|
1
|
+
import { DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, ObjectTypeDefinitionNode, StringValueNode, TypeNode } from 'graphql';
|
|
4
2
|
import { CSharpFieldType } from '@graphql-codegen/c-sharp-common';
|
|
3
|
+
import { BaseVisitor, EnumValuesMap, ParsedConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
+
import { CSharpResolversPluginRawConfig } from './config.cjs';
|
|
5
5
|
import { JsonAttributesSource } from './json-attributes.cjs';
|
|
6
6
|
export interface CSharpResolverParsedConfig extends ParsedConfig {
|
|
7
7
|
namespaceName: string;
|
package/typings/visitor.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CSharpResolversPluginRawConfig } from './config.js';
|
|
3
|
-
import { GraphQLSchema, EnumTypeDefinitionNode, EnumValueDefinitionNode, InterfaceTypeDefinitionNode, InputObjectTypeDefinitionNode, ObjectTypeDefinitionNode, FieldDefinitionNode, InputValueDefinitionNode, TypeNode, DirectiveNode, StringValueNode, NamedTypeNode } from 'graphql';
|
|
1
|
+
import { DirectiveNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, FieldDefinitionNode, GraphQLSchema, InputObjectTypeDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, NamedTypeNode, ObjectTypeDefinitionNode, StringValueNode, TypeNode } from 'graphql';
|
|
4
2
|
import { CSharpFieldType } from '@graphql-codegen/c-sharp-common';
|
|
3
|
+
import { BaseVisitor, EnumValuesMap, ParsedConfig } from '@graphql-codegen/visitor-plugin-common';
|
|
4
|
+
import { CSharpResolversPluginRawConfig } from './config.js';
|
|
5
5
|
import { JsonAttributesSource } from './json-attributes.js';
|
|
6
6
|
export interface CSharpResolverParsedConfig extends ParsedConfig {
|
|
7
7
|
namespaceName: string;
|