@graphql-codegen/c-sharp-operations 2.2.11 → 2.2.12-alpha-9d94e917a.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.js +31 -41
- package/index.mjs +31 -41
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -67,45 +67,37 @@ function getListTypeField(typeNode) {
|
|
|
67
67
|
type: getListTypeField(typeNode.type),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
if (typeNode.kind === graphql.Kind.NON_NULL_TYPE && typeNode.type.kind === graphql.Kind.LIST_TYPE) {
|
|
71
71
|
return Object.assign(getListTypeField(typeNode.type), {
|
|
72
72
|
required: true,
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
|
-
|
|
75
|
+
if (typeNode.kind === graphql.Kind.NON_NULL_TYPE) {
|
|
76
76
|
return getListTypeField(typeNode.type);
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
return undefined;
|
|
80
|
-
}
|
|
78
|
+
return undefined;
|
|
81
79
|
}
|
|
82
80
|
function getListTypeDepth(listType) {
|
|
83
81
|
if (listType) {
|
|
84
82
|
return getListTypeDepth(listType.type) + 1;
|
|
85
83
|
}
|
|
86
|
-
|
|
87
|
-
return 0;
|
|
88
|
-
}
|
|
84
|
+
return 0;
|
|
89
85
|
}
|
|
90
86
|
function getListInnerTypeNode(typeNode) {
|
|
91
87
|
if (typeNode.kind === graphql.Kind.LIST_TYPE) {
|
|
92
88
|
return getListInnerTypeNode(typeNode.type);
|
|
93
89
|
}
|
|
94
|
-
|
|
90
|
+
if (typeNode.kind === graphql.Kind.NON_NULL_TYPE && typeNode.type.kind === graphql.Kind.LIST_TYPE) {
|
|
95
91
|
return getListInnerTypeNode(typeNode.type);
|
|
96
92
|
}
|
|
97
|
-
|
|
98
|
-
return typeNode;
|
|
99
|
-
}
|
|
93
|
+
return typeNode;
|
|
100
94
|
}
|
|
101
95
|
function wrapFieldType(fieldType, listTypeField, listType = 'IEnumerable') {
|
|
102
96
|
if (listTypeField) {
|
|
103
97
|
const innerType = wrapFieldType(fieldType, listTypeField.type, listType);
|
|
104
98
|
return `${listType}<${innerType}>`;
|
|
105
99
|
}
|
|
106
|
-
|
|
107
|
-
return fieldType.innerTypeName;
|
|
108
|
-
}
|
|
100
|
+
return fieldType.innerTypeName;
|
|
109
101
|
}
|
|
110
102
|
|
|
111
103
|
// This file is bundled and inlined.
|
|
@@ -507,32 +499,30 @@ class CSharpOperationsVisitor extends visitorPluginCommon.ClientSideBaseVisitor
|
|
|
507
499
|
`public ${responseTypeName} ${convertSafeName(node.name.value)} { get; set; }`,
|
|
508
500
|
].join('\n') + '\n');
|
|
509
501
|
}
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
].join('\n') + '\n');
|
|
535
|
-
}
|
|
502
|
+
const selectionBaseTypeName = `${responseType.baseType.type}Selection`;
|
|
503
|
+
const selectionType = Object.assign(new CSharpFieldType(responseType), {
|
|
504
|
+
baseType: { type: selectionBaseTypeName },
|
|
505
|
+
});
|
|
506
|
+
const selectionTypeName = wrapFieldType(selectionType, selectionType.listType, 'System.Collections.Generic.List');
|
|
507
|
+
const innerClassSchema = this._schemaAST.definitions.find(d => d.kind === graphql.Kind.OBJECT_TYPE_DEFINITION && d.name.value === responseType.baseType.type);
|
|
508
|
+
const innerClassDefinition = new CSharpDeclarationBlock()
|
|
509
|
+
.access('public')
|
|
510
|
+
.asKind('class')
|
|
511
|
+
.withName(convertSafeName(selectionBaseTypeName))
|
|
512
|
+
.withBlock('\n' +
|
|
513
|
+
node.selectionSet.selections
|
|
514
|
+
.map(s => {
|
|
515
|
+
if (s.kind === graphql.Kind.INLINE_FRAGMENT) {
|
|
516
|
+
throw new Error(`Unsupported kind; ${node.name} ${s.kind}`);
|
|
517
|
+
}
|
|
518
|
+
return this._getResponseFieldRecursive(s, innerClassSchema);
|
|
519
|
+
})
|
|
520
|
+
.join('\n')).string;
|
|
521
|
+
return visitorPluginCommon.indentMultiline([
|
|
522
|
+
innerClassDefinition,
|
|
523
|
+
`[JsonProperty("${node.name.value}")]`,
|
|
524
|
+
`public ${selectionTypeName} ${convertSafeName(node.name.value)} { get; set; }`,
|
|
525
|
+
].join('\n') + '\n');
|
|
536
526
|
}
|
|
537
527
|
case graphql.Kind.FRAGMENT_SPREAD: {
|
|
538
528
|
const fragmentSchema = this._fragments.find(f => f.name === node.name.value);
|
package/index.mjs
CHANGED
|
@@ -61,45 +61,37 @@ function getListTypeField(typeNode) {
|
|
|
61
61
|
type: getListTypeField(typeNode.type),
|
|
62
62
|
};
|
|
63
63
|
}
|
|
64
|
-
|
|
64
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE && typeNode.type.kind === Kind.LIST_TYPE) {
|
|
65
65
|
return Object.assign(getListTypeField(typeNode.type), {
|
|
66
66
|
required: true,
|
|
67
67
|
});
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE) {
|
|
70
70
|
return getListTypeField(typeNode.type);
|
|
71
71
|
}
|
|
72
|
-
|
|
73
|
-
return undefined;
|
|
74
|
-
}
|
|
72
|
+
return undefined;
|
|
75
73
|
}
|
|
76
74
|
function getListTypeDepth(listType) {
|
|
77
75
|
if (listType) {
|
|
78
76
|
return getListTypeDepth(listType.type) + 1;
|
|
79
77
|
}
|
|
80
|
-
|
|
81
|
-
return 0;
|
|
82
|
-
}
|
|
78
|
+
return 0;
|
|
83
79
|
}
|
|
84
80
|
function getListInnerTypeNode(typeNode) {
|
|
85
81
|
if (typeNode.kind === Kind.LIST_TYPE) {
|
|
86
82
|
return getListInnerTypeNode(typeNode.type);
|
|
87
83
|
}
|
|
88
|
-
|
|
84
|
+
if (typeNode.kind === Kind.NON_NULL_TYPE && typeNode.type.kind === Kind.LIST_TYPE) {
|
|
89
85
|
return getListInnerTypeNode(typeNode.type);
|
|
90
86
|
}
|
|
91
|
-
|
|
92
|
-
return typeNode;
|
|
93
|
-
}
|
|
87
|
+
return typeNode;
|
|
94
88
|
}
|
|
95
89
|
function wrapFieldType(fieldType, listTypeField, listType = 'IEnumerable') {
|
|
96
90
|
if (listTypeField) {
|
|
97
91
|
const innerType = wrapFieldType(fieldType, listTypeField.type, listType);
|
|
98
92
|
return `${listType}<${innerType}>`;
|
|
99
93
|
}
|
|
100
|
-
|
|
101
|
-
return fieldType.innerTypeName;
|
|
102
|
-
}
|
|
94
|
+
return fieldType.innerTypeName;
|
|
103
95
|
}
|
|
104
96
|
|
|
105
97
|
// This file is bundled and inlined.
|
|
@@ -501,32 +493,30 @@ class CSharpOperationsVisitor extends ClientSideBaseVisitor {
|
|
|
501
493
|
`public ${responseTypeName} ${convertSafeName(node.name.value)} { get; set; }`,
|
|
502
494
|
].join('\n') + '\n');
|
|
503
495
|
}
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
].join('\n') + '\n');
|
|
529
|
-
}
|
|
496
|
+
const selectionBaseTypeName = `${responseType.baseType.type}Selection`;
|
|
497
|
+
const selectionType = Object.assign(new CSharpFieldType(responseType), {
|
|
498
|
+
baseType: { type: selectionBaseTypeName },
|
|
499
|
+
});
|
|
500
|
+
const selectionTypeName = wrapFieldType(selectionType, selectionType.listType, 'System.Collections.Generic.List');
|
|
501
|
+
const innerClassSchema = this._schemaAST.definitions.find(d => d.kind === Kind.OBJECT_TYPE_DEFINITION && d.name.value === responseType.baseType.type);
|
|
502
|
+
const innerClassDefinition = new CSharpDeclarationBlock()
|
|
503
|
+
.access('public')
|
|
504
|
+
.asKind('class')
|
|
505
|
+
.withName(convertSafeName(selectionBaseTypeName))
|
|
506
|
+
.withBlock('\n' +
|
|
507
|
+
node.selectionSet.selections
|
|
508
|
+
.map(s => {
|
|
509
|
+
if (s.kind === Kind.INLINE_FRAGMENT) {
|
|
510
|
+
throw new Error(`Unsupported kind; ${node.name} ${s.kind}`);
|
|
511
|
+
}
|
|
512
|
+
return this._getResponseFieldRecursive(s, innerClassSchema);
|
|
513
|
+
})
|
|
514
|
+
.join('\n')).string;
|
|
515
|
+
return indentMultiline([
|
|
516
|
+
innerClassDefinition,
|
|
517
|
+
`[JsonProperty("${node.name.value}")]`,
|
|
518
|
+
`public ${selectionTypeName} ${convertSafeName(node.name.value)} { get; set; }`,
|
|
519
|
+
].join('\n') + '\n');
|
|
530
520
|
}
|
|
531
521
|
case Kind.FRAGMENT_SPREAD: {
|
|
532
522
|
const fragmentSchema = this._fragments.find(f => f.name === node.name.value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@graphql-codegen/c-sharp-operations",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.12-alpha-9d94e917a.0",
|
|
4
4
|
"description": "GraphQL Code Generator plugin for generating CSharp code based on GraphQL operations",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"peerDependencies": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
11
|
"@graphql-codegen/plugin-helpers": "^2.4.0",
|
|
12
|
-
"@graphql-codegen/visitor-plugin-common": "2.
|
|
12
|
+
"@graphql-codegen/visitor-plugin-common": "2.9.0-alpha-9d94e917a.0",
|
|
13
13
|
"auto-bind": "~4.0.0",
|
|
14
14
|
"change-case-all": "1.0.14",
|
|
15
15
|
"tslib": "~2.4.0"
|