Skip to content

Commit 5b70539

Browse files
taeyzzzThanetpon Kultontikorn
andauthored
feat: auto generate codegen config and generate (#18)
* WIP: generate codegen * WIP: create script to generate codegen and use it * WIP * add TODO * change to use string template for plugin * able to generate codegen config with output file * generate done, WIP: with header * done, deploy and test --------- Co-authored-by: Thanetpon Kultontikorn <[email protected]>
1 parent a294b02 commit 5b70539

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2910
-473
lines changed

Agoda.Graphql/SupplyApi/Queries/Availabilities/GetAvailabilities.generated.cs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using Newtonsoft.Json.Converters;
55
using Agoda.Graphql;
66

7-
namespace Agoda.Graphql.GetAvailabilities
7+
namespace Agoda.Graphql.SupplyApi.Queries.Availabilities
88
{
9-
public partial class Query : QueryBase<Data>
9+
public class Query : QueryBase<Data>
1010
{
1111
private const string _query = @"query GetAvailabilities($propertyId: String!, $dmcId: Int!, $roomTypeId: String, $startDate: Date!, $endDate: Date!) {
1212
Availabilities(
@@ -31,6 +31,12 @@ public partial class Query : QueryBase<Data>
3131
}
3232
}";
3333

34+
public string PropertyId { get; }
35+
public int DmcId { get; }
36+
public string RoomTypeId { get; }
37+
public DateTime StartDate { get; }
38+
public DateTime EndDate { get; }
39+
3440
public Query(string propertyId, int dmcId, string roomTypeId, DateTime startDate, DateTime endDate, IResultProcessor<Data> resultProcessor = null) : base(resultProcessor)
3541
{
3642
PropertyId = propertyId;
@@ -40,11 +46,6 @@ public Query(string propertyId, int dmcId, string roomTypeId, DateTime startDate
4046
EndDate = endDate;
4147
}
4248

43-
public string PropertyId { get; }
44-
public int DmcId { get; }
45-
public string RoomTypeId { get; }
46-
public DateTime StartDate { get; }
47-
public DateTime EndDate { get; }
4849
protected override string QueryText => _query;
4950

5051
protected override Dictionary<string, object> Variables => new Dictionary<string, object>
@@ -59,60 +60,45 @@ public Query(string propertyId, int dmcId, string roomTypeId, DateTime startDate
5960

6061
public sealed class Data
6162
{
62-
6363
[JsonProperty("Availabilities")]
6464
public List<Availabilities> Availabilities { get; set; }
6565
}
6666

67-
/// <summary>Inner Model</summary>
6867
public sealed class Availabilities
69-
{
70-
71-
68+
{
7269
[JsonProperty("propertyId")]
7370
public string PropertyId { get; set; }
7471

75-
7672
[JsonProperty("roomId")]
7773
public string RoomId { get; set; }
7874

79-
8075
[JsonProperty("dmcId")]
8176
public int DmcId { get; set; }
8277

83-
8478
[JsonProperty("date")]
8579
public DateTime Date { get; set; }
8680

87-
8881
[JsonProperty("regularAllotment")]
8982
public int? RegularAllotment { get; set; }
9083

91-
9284
[JsonProperty("regularAllotmentUsed")]
9385
public int? RegularAllotmentUsed { get; set; }
9486

95-
9687
[JsonProperty("guaranteedAllotment")]
9788
public int? GuaranteedAllotment { get; set; }
9889

99-
10090
[JsonProperty("guaranteedAllotmentUsed")]
10191
public int? GuaranteedAllotmentUsed { get; set; }
10292

103-
10493
[JsonProperty("createdBy")]
10594
public string CreatedBy { get; set; }
10695

107-
10896
[JsonProperty("createdWhen")]
10997
public DateTime CreatedWhen { get; set; }
11098

111-
11299
[JsonProperty("modifiedBy")]
113100
public string ModifiedBy { get; set; }
114101

115-
116102
[JsonProperty("modifiedWhen")]
117103
public DateTime? ModifiedWhen { get; set; }
118104
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using Agoda.Graphql;
6+
7+
namespace Agoda.Graphql.SupplyApi.Queries.Availabilities.GetAvailabilities
8+
{
9+
public class Query : QueryBase<Data>
10+
{
11+
private const string _query = @"query GetAvailabilities($propertyId: String!, $dmcId: Int!, $roomTypeId: String, $startDate: Date!, $endDate: Date!) {
12+
Availabilities(
13+
hotelId: $propertyId
14+
dmcId: $dmcId
15+
roomTypeId: $roomTypeId
16+
startDate: $startDate
17+
endDate: $endDate
18+
) {
19+
propertyId
20+
roomId
21+
dmcId
22+
date
23+
regularAllotment
24+
regularAllotmentUsed
25+
guaranteedAllotment
26+
guaranteedAllotmentUsed
27+
createdBy
28+
createdWhen
29+
modifiedBy
30+
modifiedWhen
31+
}
32+
}";
33+
34+
public string PropertyId { get; }
35+
public int DmcId { get; }
36+
public string RoomTypeId { get; }
37+
public DateTime StartDate { get; }
38+
public DateTime EndDate { get; }
39+
40+
public Query(string propertyId, int dmcId, string roomTypeId, DateTime startDate, DateTime endDate, IResultProcessor<Data> resultProcessor = null) : base(resultProcessor)
41+
{
42+
PropertyId = propertyId;
43+
DmcId = dmcId;
44+
RoomTypeId = roomTypeId;
45+
StartDate = startDate;
46+
EndDate = endDate;
47+
}
48+
49+
protected override string QueryText => _query;
50+
51+
protected override Dictionary<string, object> Variables => new Dictionary<string, object>
52+
{
53+
{ "propertyId", PropertyId },
54+
{ "dmcId", DmcId },
55+
{ "roomTypeId", RoomTypeId },
56+
{ "startDate", StartDate.ToString("yyyy-MM-dd") },
57+
{ "endDate", EndDate.ToString("yyyy-MM-dd") }
58+
};
59+
}
60+
61+
public sealed class Data
62+
{
63+
[JsonProperty("Availabilities")]
64+
public List<Availabilities> Availabilities { get; set; }
65+
}
66+
67+
public sealed class Availabilities
68+
{
69+
[JsonProperty("propertyId")]
70+
public string PropertyId { get; set; }
71+
72+
[JsonProperty("roomId")]
73+
public string RoomId { get; set; }
74+
75+
[JsonProperty("dmcId")]
76+
public int DmcId { get; set; }
77+
78+
[JsonProperty("date")]
79+
public DateTime Date { get; set; }
80+
81+
[JsonProperty("regularAllotment")]
82+
public int? RegularAllotment { get; set; }
83+
84+
[JsonProperty("regularAllotmentUsed")]
85+
public int? RegularAllotmentUsed { get; set; }
86+
87+
[JsonProperty("guaranteedAllotment")]
88+
public int? GuaranteedAllotment { get; set; }
89+
90+
[JsonProperty("guaranteedAllotmentUsed")]
91+
public int? GuaranteedAllotmentUsed { get; set; }
92+
93+
[JsonProperty("createdBy")]
94+
public string CreatedBy { get; set; }
95+
96+
[JsonProperty("createdWhen")]
97+
public DateTime CreatedWhen { get; set; }
98+
99+
[JsonProperty("modifiedBy")]
100+
public string ModifiedBy { get; set; }
101+
102+
[JsonProperty("modifiedWhen")]
103+
public DateTime? ModifiedWhen { get; set; }
104+
}
105+
}
File renamed without changes.

Agoda.Graphql/SupplyApi/Queries/Availabilities/UpdateAvailability.generated.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using Newtonsoft.Json.Converters;
55
using Agoda.Graphql;
66

7-
namespace Agoda.Graphql.UpdateAvailability
7+
namespace Agoda.Graphql.SupplyApi.Queries.Availabilities
88
{
9-
public partial class Mutation : QueryBase<Data>
9+
public class Mutation : QueryBase<Data>
1010
{
1111
private const string _query = @"mutation UpdateAvailability($dmcId: Int!, $hotelId: String!, $roomTypeId: String!, $userId: String!, $startDate: Date!, $endDate: Date!, $regularAllotment: Int, $guaranteedAllotment: Int, $dayOfWeek: [Int!]) {
1212
AvailabilityMutation(
@@ -76,59 +76,44 @@ public Mutation(int dmcId, string hotelId, string roomTypeId, string userId, Dat
7676

7777
public sealed class Data
7878
{
79-
8079
[JsonProperty("AvailabilityMutation")]
81-
public AvailabilityMutation AvailabilityMutation { get; set; }
80+
public List<AvailabilityMutation> AvailabilityMutation { get; set; }
8281
}
8382

84-
/// <summary>Inner Model</summary>
8583
public sealed class AvailabilityMutation
86-
{
87-
88-
84+
{
8985
[JsonProperty("regularAllotment")]
9086
public int? RegularAllotment { get; set; }
9187

92-
9388
[JsonProperty("guaranteedAllotment")]
9489
public int? GuaranteedAllotment { get; set; }
9590

96-
9791
[JsonProperty("guaranteedAllotmentUsed")]
9892
public int? GuaranteedAllotmentUsed { get; set; }
9993

100-
10194
[JsonProperty("regularAllotmentUsed")]
10295
public int? RegularAllotmentUsed { get; set; }
10396

104-
10597
[JsonProperty("date")]
10698
public DateTime Date { get; set; }
10799

108-
109100
[JsonProperty("propertyId")]
110101
public string PropertyId { get; set; }
111102

112-
113103
[JsonProperty("dmcId")]
114-
public string DmcId { get; set; }
115-
104+
public int DmcId { get; set; }
116105

117106
[JsonProperty("roomId")]
118107
public string RoomId { get; set; }
119108

120-
121109
[JsonProperty("createdWhen")]
122110
public DateTime CreatedWhen { get; set; }
123111

124-
125112
[JsonProperty("createdBy")]
126113
public string CreatedBy { get; set; }
127114

128-
129115
[JsonProperty("modifiedWhen")]
130-
public DateTime ModifiedWhen { get; set; }
131-
116+
public DateTime? ModifiedWhen { get; set; }
132117

133118
[JsonProperty("modifiedBy")]
134119
public string ModifiedBy { get; set; }

Agoda.Graphql/SupplyApi/Queries/Properties/HotelCompetitor.generated.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using Newtonsoft.Json.Converters;
55
using Agoda.Graphql;
66

7-
namespace Agoda.Graphql.HotelCompetitorByHotelId
7+
namespace Agoda.Graphql.SupplyApi.Queries.Properties
88
{
9-
public partial class Query : QueryBase<Data>
9+
public class Query : QueryBase<Data>
1010
{
1111
private const string _query = @"query HotelCompetitorByHotelId($id: Int!, $languageId: Int!) {
1212
HotelCompetitorByHotelId(id: $id) {

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ npm install agoda-graphql-csharp-generator @graphql-codegen/cli graphql
1313
# Notes:
1414
- automate job to update semver version
1515
- automate job to create release and tags
16+
17+
18+
TODO:
19+
- create script to generate codegen.yml that accept
20+
```
21+
--schema-url 'https://smapi-qa-http.privatecloud.qa.agoda.is/v2/graphql' --graphql-dir '../../src/Agoda.SupplyReporting.GraphQl/SupplyApi/Queries/DMCs' --graphql-project 'Agoda.SupplyReporting.GraphQl' --output-name
22+
```
23+
- in target project just run with gql-gen

codegen.yml

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
1+
# generated by agoda-graphql-csharp-generator
12
overwrite: true
23
schema: "https://smapi-qa-http.privatecloud.qa.agoda.is/v2/graphql"
34
generates:
4-
./Agoda.Graphql/SupplyApi/Queries/Rooms/GetListRoomByPropertyId/GetListRoomByPropertyId.generated.cs:
5-
documents:
6-
- "Agoda.Graphql/SupplyApi/Queries/Rooms/GetListRoomByPropertyId/GetListRoomByPropertyId.graphql"
7-
plugins:
8-
- "./dist/agoda-csharp-codegen.js"
9-
config:
10-
namespace: "Agoda.Graphql.SupplyApi.Queries.Rooms.GetListRoomByPropertyId"
11-
./Agoda.Graphql/SupplyApi/Queries/Rooms/GetObjectExternalData/GetObjectExternalData.generated.cs:
12-
documents:
13-
- "Agoda.Graphql/SupplyApi/Queries/Rooms/GetObjectExternalData/GetObjectExternalData.graphql"
14-
plugins:
15-
- "./dist/agoda-csharp-codegen.js"
16-
config:
17-
namespace: "Agoda.Graphql.SupplyApi.Queries.Rooms.GetObjectExternalData"
18-
./Agoda.Graphql/SupplyApi/Queries/Rooms/GetRoomById/GetRoomById.generated.cs:
19-
documents:
20-
- "Agoda.Graphql/SupplyApi/Queries/Rooms/GetRoomById/GetRoomById.graphql"
21-
plugins:
22-
- "./dist/agoda-csharp-codegen.js"
23-
config:
24-
namespace: "Agoda.Graphql.SupplyApi.Queries.Rooms.GetRoomById"
5+
src/Agoda.Graphql/SupplyApi/Queries/Availabilities/GetAvailabilities/GetAvailabilities.generated.cs:
6+
documents:
7+
- "src/Agoda.Graphql/SupplyApi/Queries/Availabilities/GetAvailabilities/GetAvailabilities.graphql"
8+
plugins:
9+
- "agoda-graphql-csharp-generator"
10+
config:
11+
namespace: "Agoda.Graphql.SupplyApi.Queries.Availabilities.GetAvailabilities"
12+
src/Agoda.Graphql/SupplyApi/Queries/Availabilities/UpdateAvailability.generated.cs:
13+
documents:
14+
- "src/Agoda.Graphql/SupplyApi/Queries/Availabilities/UpdateAvailability.graphql"
15+
plugins:
16+
- "agoda-graphql-csharp-generator"
17+
config:
18+
namespace: "Agoda.Graphql.SupplyApi.Queries.Availabilities"
19+
src/Agoda.Graphql/SupplyApi/Queries/Properties/HotelCompetitor.generated.cs:
20+
documents:
21+
- "src/Agoda.Graphql/SupplyApi/Queries/Properties/HotelCompetitor.graphql"
22+
plugins:
23+
- "agoda-graphql-csharp-generator"
24+
config:
25+
namespace: "Agoda.Graphql.SupplyApi.Queries.Properties"
26+
src/Agoda.Graphql/SupplyApi/Queries/Rooms/GetListRoomByPropertyId/GetListRoomByPropertyId.generated.cs:
27+
documents:
28+
- "src/Agoda.Graphql/SupplyApi/Queries/Rooms/GetListRoomByPropertyId/GetListRoomByPropertyId.graphql"
29+
plugins:
30+
- "agoda-graphql-csharp-generator"
31+
config:
32+
namespace: "Agoda.Graphql.SupplyApi.Queries.Rooms.GetListRoomByPropertyId"
33+
src/Agoda.Graphql/SupplyApi/Queries/Rooms/GetObjectExternalData/GetObjectExternalData.generated.cs:
34+
documents:
35+
- "src/Agoda.Graphql/SupplyApi/Queries/Rooms/GetObjectExternalData/GetObjectExternalData.graphql"
36+
plugins:
37+
- "agoda-graphql-csharp-generator"
38+
config:
39+
namespace: "Agoda.Graphql.SupplyApi.Queries.Rooms.GetObjectExternalData"
40+
src/Agoda.Graphql/SupplyApi/Queries/Rooms/GetRoomById/GetRoomById.generated.cs:
41+
documents:
42+
- "src/Agoda.Graphql/SupplyApi/Queries/Rooms/GetRoomById/GetRoomById.graphql"
43+
plugins:
44+
- "agoda-graphql-csharp-generator"
45+
config:
46+
namespace: "Agoda.Graphql.SupplyApi.Queries.Rooms.GetRoomById"

0 commit comments

Comments
 (0)