Skip to content

Commit

Permalink
Fix/map is not a function (#820)
Browse files Browse the repository at this point in the history
* upgrade dependencies and fix breaking changes

* fixed c-sharp-operations tests

* fixed c-sharp tests

* add changeset
  • Loading branch information
mariusmuntean authored Aug 28, 2024
1 parent 6970825 commit 581e733
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 21 deletions.
7 changes: 7 additions & 0 deletions .changeset/eight-pandas-vanish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@graphql-codegen/c-sharp-operations': patch
'@graphql-codegen/c-sharp-common': patch
'@graphql-codegen/c-sharp': patch
---

upgrade dependencies and fix type errors
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
},
"cSpell.words": ["Newtonsoft"]
}
4 changes: 2 additions & 2 deletions packages/plugins/c-sharp/c-sharp-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
"graphql-tag": "2.12.6"
},
"dependencies": {
"@graphql-codegen/plugin-helpers": "^3.0.0",
"@graphql-codegen/visitor-plugin-common": "^2.12.1",
"@graphql-codegen/plugin-helpers": "^5.0.4",
"@graphql-codegen/visitor-plugin-common": "^5.3.1",
"auto-bind": "~4.0.0",
"change-case-all": "1.0.15",
"tslib": "~2.6.0"
Expand Down
34 changes: 27 additions & 7 deletions packages/plugins/c-sharp/c-sharp-common/src/scalars.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
export const C_SHARP_SCALARS = {
ID: 'string',
String: 'string',
Boolean: 'bool',
Int: 'int',
Float: 'double',
Date: 'DateTime',
import { NormalizedScalarsMap } from '@graphql-codegen/visitor-plugin-common';

export const C_SHARP_SCALARS: NormalizedScalarsMap = {
ID: {
input: 'string',
output: 'string',
},
String: {
input: 'string',
output: 'string',
},
Boolean: {
input: 'bool',
output: 'bool',
},
Int: {
input: 'int',
output: 'int',
},
Float: {
input: 'double',
output: 'double',
},
Date: {
input: 'DateTime',
output: 'DateTime',
},
};

export const csharpValueTypes = [
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/c-sharp/c-sharp-operations/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
},
"dependencies": {
"@graphql-codegen/c-sharp-common": "1.0.0",
"@graphql-codegen/plugin-helpers": "^3.0.0",
"@graphql-codegen/visitor-plugin-common": "^2.12.1",
"@graphql-codegen/plugin-helpers": "5.0.4",
"@graphql-codegen/visitor-plugin-common": "^5.3.1",
"auto-bind": "~4.0.0",
"change-case-all": "1.0.15",
"tslib": "~2.6.0"
Expand Down
17 changes: 12 additions & 5 deletions packages/plugins/c-sharp/c-sharp-operations/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor<
}[] = [];

private _schemaAST: DocumentNode;
private readonly _fragmentList: LoadedFragment[];

constructor(
schema: GraphQLSchema,
Expand Down Expand Up @@ -102,6 +103,7 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor<
autoBind(this);

this._schemaAST = getCachedDocumentNodeFromSchema(schema);
this._fragmentList = fragments;
}

// Some settings aren't supported with C#, overruled here
Expand Down Expand Up @@ -161,7 +163,12 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor<
}

protected _gql(node: OperationDefinitionNode): string {
const fragments = this._transformFragments(node);
const includeNestedFragments =
this.config.documentMode === DocumentMode.documentNode ||
this.config.documentMode === DocumentMode.string ||
(this.config.dedupeFragments && node.kind === 'OperationDefinition');
const fragmentNames = this._extractFragments(node, includeNestedFragments);
const fragments = this._transformFragments(fragmentNames);
const doc = this._prepareDocument(
[print(node), this._includeFragments(fragments, node.kind)].join('\n'),
);
Expand Down Expand Up @@ -189,7 +196,7 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor<
const name = variable.variable.name.value;
const baseType = !isScalarType(schemaType)
? innerType.name.value
: this.scalars[schemaType.name] || 'object';
: this.scalars[schemaType.name].input || 'object';

const listType = getListTypeField(typeNode);
const required = getListInnerTypeNode(typeNode).kind === Kind.NON_NULL_TYPE;
Expand Down Expand Up @@ -239,9 +246,9 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor<
const baseType = this.scalars[schemaType.name];
result = new CSharpFieldType({
baseType: {
type: baseType,
type: baseType.output,
required,
valueType: isValueType(baseType),
valueType: isValueType(baseType.output),
},
listType,
});
Expand Down Expand Up @@ -378,7 +385,7 @@ export class CSharpOperationsVisitor extends ClientSideBaseVisitor<
);
}
case Kind.FRAGMENT_SPREAD: {
const fragmentSchema = this._fragments.find(f => f.name === node.name.value);
const fragmentSchema = this._fragmentList.find(f => f.name === node.name.value);
if (!fragmentSchema) {
throw new Error(`Fragment schema not found; ${node.name.value}`);
}
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/c-sharp/c-sharp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@
},
"dependencies": {
"@graphql-codegen/c-sharp-common": "1.0.0",
"@graphql-codegen/plugin-helpers": "^3.0.0",
"@graphql-codegen/visitor-plugin-common": "^2.12.1",
"@graphql-codegen/plugin-helpers": "^5.0.4",
"@graphql-codegen/visitor-plugin-common": "^5.3.1",
"change-case-all": "1.0.15",
"tslib": "~2.6.0",
"unixify": "^1.0.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/c-sharp/c-sharp/src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ export class CSharpResolversVisitor extends BaseVisitor<
const baseType = this.scalars[schemaType.name];
result = new CSharpFieldType({
baseType: {
type: baseType,
type: baseType.input,
required,
valueType: isValueType(baseType),
valueType: isValueType(baseType.input),
},
listType,
});
Expand Down
44 changes: 44 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,18 @@
"@graphql-tools/utils" "^8.8.0"
tslib "~2.4.0"

"@graphql-codegen/plugin-helpers@5.0.4", "@graphql-codegen/plugin-helpers@^5.0.4":
version "5.0.4"
resolved "https://registry.yarnpkg.com/@graphql-codegen/plugin-helpers/-/plugin-helpers-5.0.4.tgz#5f4c987c3f308ef1c8809ee0c43af0369867e0f6"
integrity sha512-MOIuHFNWUnFnqVmiXtrI+4UziMTYrcquljaI5f/T/Bc7oO7sXcfkAvgkNWEEi9xWreYwvuer3VHCuPI/lAFWbw==
dependencies:
"@graphql-tools/utils" "^10.0.0"
change-case-all "1.0.15"
common-tags "1.8.2"
import-from "4.0.0"
lodash "~4.17.0"
tslib "~2.6.0"

"@graphql-codegen/plugin-helpers@^2.6.2", "@graphql-codegen/plugin-helpers@^2.7.2":
version "2.7.2"
resolved "https://registry.yarnpkg.com/@graphql-codegen/plugin-helpers/-/plugin-helpers-2.7.2.tgz#6544f739d725441c826a8af6a49519f588ff9bed"
Expand Down Expand Up @@ -1663,6 +1675,22 @@
parse-filepath "^1.0.2"
tslib "~2.4.0"

"@graphql-codegen/visitor-plugin-common@^5.3.1":
version "5.3.1"
resolved "https://registry.yarnpkg.com/@graphql-codegen/visitor-plugin-common/-/visitor-plugin-common-5.3.1.tgz#d3fb5f6336cbef58e2960471422da3f3caff7f17"
integrity sha512-MktoBdNZhSmugiDjmFl1z6rEUUaqyxtFJYWnDilE7onkPgyw//O0M+TuPBJPBWdyV6J2ond0Hdqtq+rkghgSIQ==
dependencies:
"@graphql-codegen/plugin-helpers" "^5.0.4"
"@graphql-tools/optimize" "^2.0.0"
"@graphql-tools/relay-operation-optimizer" "^7.0.0"
"@graphql-tools/utils" "^10.0.0"
auto-bind "~4.0.0"
change-case-all "1.0.15"
dependency-graph "^0.11.0"
graphql-tag "^2.11.0"
parse-filepath "^1.0.2"
tslib "~2.6.0"

"@graphql-tools/apollo-engine-loader@^7.3.6":
version "7.3.15"
resolved "https://registry.yarnpkg.com/@graphql-tools/apollo-engine-loader/-/apollo-engine-loader-7.3.15.tgz#2eae5c107029f2a0f40b73ab1c180bf96d788de4"
Expand Down Expand Up @@ -1820,6 +1848,13 @@
dependencies:
tslib "^2.4.0"

"@graphql-tools/optimize@^2.0.0":
version "2.0.0"
resolved "https://registry.yarnpkg.com/@graphql-tools/optimize/-/optimize-2.0.0.tgz#7a9779d180824511248a50c5a241eff6e7a2d906"
integrity sha512-nhdT+CRGDZ+bk68ic+Jw1OZ99YCDIKYA5AlVAnBHJvMawSx9YQqQAIj4refNc1/LRieGiuWvhbG3jvPVYho0Dg==
dependencies:
tslib "^2.4.0"

"@graphql-tools/prisma-loader@^7.2.7":
version "7.2.26"
resolved "https://registry.yarnpkg.com/@graphql-tools/prisma-loader/-/prisma-loader-7.2.26.tgz#4e5f2ca204259e3ca5a3038d1bde7b2ada63f5a0"
Expand Down Expand Up @@ -1854,6 +1889,15 @@
"@graphql-tools/utils" "8.8.0"
tslib "^2.4.0"

"@graphql-tools/relay-operation-optimizer@^7.0.0":
version "7.0.1"
resolved "https://registry.yarnpkg.com/@graphql-tools/relay-operation-optimizer/-/relay-operation-optimizer-7.0.1.tgz#8ac33e1d2626b6816d9283769c4a05c062b8065a"
integrity sha512-y0ZrQ/iyqWZlsS/xrJfSir3TbVYJTYmMOu4TaSz6F4FRDTQ3ie43BlKkhf04rC28pnUOS4BO9pDcAo1D30l5+A==
dependencies:
"@ardatan/relay-compiler" "12.0.0"
"@graphql-tools/utils" "^10.0.13"
tslib "^2.4.0"

"@graphql-tools/schema@10.0.4":
version "10.0.4"
resolved "https://registry.yarnpkg.com/@graphql-tools/schema/-/schema-10.0.4.tgz#d4fc739a2cc07b4fc5f31a714178a561cba210cd"
Expand Down

0 comments on commit 581e733

Please sign in to comment.