@@ -50,9 +50,9 @@ export class FirematService {
50
50
}
51
51
52
52
/** Encode a body while handling the fact that "variables" is raw JSON.
53
- *
54
- * If the JSON is invalid, will throw.
55
- */
53
+ *
54
+ * If the JSON is invalid, will throw.
55
+ */
56
56
private _serializeBody ( body : { variables ?: string ; [ key : string ] : unknown } ) {
57
57
if ( ! body . variables ) {
58
58
return JSON . stringify ( body ) ;
@@ -67,60 +67,6 @@ export class FirematService {
67
67
} ) ;
68
68
}
69
69
70
- async executeMutation ( params : {
71
- operation_name : String ;
72
- mutation : String ;
73
- variables : string ;
74
- } ) {
75
- // TODO: get operationSet name from firemat.yaml
76
- const body = this . _serializeBody ( {
77
- ...params ,
78
- name : "projects/p/locations/l/services/local/operationSets/crud/revisions/r" ,
79
- } ) ;
80
- const resp = await fetch (
81
- ( await this . getFirematEndpoint ( ) ) +
82
- "/v0/projects/p/locations/l/services/local/operationSets/crud/revisions/r:executeMutation" ,
83
- {
84
- method : "POST" ,
85
- headers : {
86
- Accept : "application/json" ,
87
- "Content-Type" : "application/json" ,
88
- "x-mantle-admin" : "all" ,
89
- } ,
90
- body,
91
- }
92
- ) ;
93
- const result = await resp . json ( ) . catch ( ( ) => resp . text ( ) ) ;
94
- return result ;
95
- }
96
-
97
- async executeQuery ( params : {
98
- operation_name : String ;
99
- query : String ;
100
- variables : string ;
101
- } ) {
102
- // TODO: get operationSet name from firemat.yaml
103
- const body = this . _serializeBody ( {
104
- ...params ,
105
- name : "projects/p/locations/l/services/local/operationSets/crud/revisions/r" ,
106
- } ) ;
107
- const resp = await fetch (
108
- ( await this . getFirematEndpoint ( ) ) +
109
- "/v0/projects/p/locations/l/services/local/operationSets/crud/revisions/r:executeQuery" ,
110
- {
111
- method : "POST" ,
112
- headers : {
113
- Accept : "application/json" ,
114
- "Content-Type" : "application/json" ,
115
- "x-mantle-admin" : "all" ,
116
- } ,
117
- body,
118
- }
119
- ) ;
120
- const result = await resp . json ( ) . catch ( ( ) => resp . text ( ) ) ;
121
- return result ;
122
- }
123
-
124
70
// This introspection is used to generate a basic graphql schema
125
71
// It will not include our predefined operations, which requires a Firemat specific introspection query
126
72
async introspect ( ) : Promise < { data ?: IntrospectionQuery } > {
@@ -149,8 +95,8 @@ export class FirematService {
149
95
}
150
96
151
97
async executeGraphQLRead ( params : {
152
- query : String ;
153
- operationName : String ;
98
+ query : string ;
99
+ operationName : string ;
154
100
variables : string ;
155
101
} ) {
156
102
try {
@@ -180,4 +126,31 @@ export class FirematService {
180
126
return null ;
181
127
}
182
128
}
129
+
130
+ async executeGraphQL ( params : {
131
+ query : string ;
132
+ operationName ?: string ;
133
+ variables : string ;
134
+ } ) {
135
+ // TODO: get name programmatically
136
+ const body = this . _serializeBody ( {
137
+ ...params ,
138
+ name : "projects/p/locations/l/services/local" ,
139
+ } ) ;
140
+ const resp = await fetch (
141
+ ( await this . getFirematEndpoint ( ) ) +
142
+ "/v0/projects/p/locations/l/services/local:executeGraphql" ,
143
+ {
144
+ method : "POST" ,
145
+ headers : {
146
+ Accept : "application/json" ,
147
+ "Content-Type" : "application/json" ,
148
+ "x-mantle-admin" : "all" ,
149
+ } ,
150
+ body : body ,
151
+ }
152
+ ) ;
153
+ const result = await resp . json ( ) . catch ( ( ) => resp . text ( ) ) ;
154
+ return result ;
155
+ }
183
156
}
0 commit comments