1616 */
1717
1818import { App } from '../app' ;
19- import {
20- DATA_CONNECT_ERROR_CODE_MAPPING ,
21- DataConnectApiClient ,
22- FirebaseDataConnectError } from './data-connect-api-client-internal' ;
19+ import { DataConnectApiClient } from './data-connect-api-client-internal' ;
2320
2421import {
2522 ConnectorConfig ,
@@ -162,152 +159,75 @@ export class DataConnect {
162159 return this . client . upsertMany ( tableName , variables ) ;
163160 }
164161
165- /** @internal */
166- public executeQuery < Data , Variables > (
167- name : string ,
168- variables : Variables ,
169- options ?: RefOptions
170- ) : Promise < ExecuteGraphqlResponse < Data > > {
171- return this . client . executeQuery < Data , Variables > ( name , variables , options ) ;
172- }
173-
174- /** @internal */
175- public executeMutation < Data , Variables > (
176- name : string ,
177- variables : Variables ,
178- options ?: RefOptions
179- ) : Promise < ExecuteGraphqlResponse < Data > > {
180- return this . client . executeMutation < Data , Variables > ( name , variables , options ) ;
181- }
182-
183162 /**
184- * Create a reference to a specific "instance" of a named query.
185- * @param name - The name of the query.
186- * @param options - The RefOptions for the query (optional).
187- * @returns A reference to the named query with the specified impersonation and variables.
163+ * Executes a pre-defined GraphQL query with impersonation.
164+ *
165+ * The query must be defined in your Data Connect GraphQL files.
166+ *
167+ * @param options - The GraphQL options, must include operationName and impersonation details.
168+ * @returns A promise that fulfills with the GraphQL response.
188169 */
189- public queryRef < Data > (
170+ public executeQuery < Data > (
190171 name : string ,
191172 options ?: RefOptions
192- ) : QueryRef < Data , undefined > ;
173+ ) : Promise < ExecuteGraphqlResponse < Data > > ;
193174
194175 /**
195- * Create a reference to a specific "instance" of a named query.
196- * @param name - The name of the query.
176+ * Executes a pre-defined GraphQL query with impersonation.
177+ *
178+ * The query must be defined in your Data Connect GraphQL files.
179+ *
180+ * @param options - The GraphQL options, must include operationName and impersonation details.
197181 * @param variables - The variables for the query. May be optional if the query's variables are optional.
198- * @param options - The RefOptions for the query (optional).
199- * @returns A reference to the named query with the specified impersonation and variables.
182+ * @returns A promise that fulfills with the GraphQL response.
200183 */
201- public queryRef < Data , Variables > (
184+ public executeQuery < Data , Variables > (
202185 name : string ,
203186 variables : Variables ,
204187 options ?: RefOptions
205- ) : QueryRef < Data , Variables > ;
188+ ) : Promise < ExecuteGraphqlResponse < Data > > ;
206189
207- public queryRef < Data , Variables > (
190+ public executeQuery < Data , Variables > (
208191 name : string ,
209192 variables : Variables ,
210193 options ?: RefOptions
211- ) : QueryRef < Data , Variables > {
212- if ( ! ( 'connector' in this . connectorConfig ) ) {
213- throw new FirebaseDataConnectError (
214- DATA_CONNECT_ERROR_CODE_MAPPING . INVALID_ARGUMENT ,
215- `The 'connectorConfig.connector' field used to instantiate your Data Connect
216- instance must be a non-empty string (the connectorId) when creating a queryRef.` ) ;
217- }
218- return new QueryRef ( this , name , variables , options ) ;
194+ ) : Promise < ExecuteGraphqlResponse < Data > > {
195+ return this . client . executeQuery < Data , Variables > ( name , variables , options ) ;
219196 }
220197
221198 /**
222- * Create a reference to a specific "instance" of a named mutation.
223- * @param name - The name of the mutation.
224- * @param options - The RefOptions for the mutation (optional).
225- * @returns A reference to the named mutation with the specified impersonation and variables.
199+ * Executes a pre-defined GraphQL mutation with impersonation.
200+ *
201+ * The mutation must be defined in your Data Connect GQL files.
202+ *
203+ * @param options - The GraphQL options, must include operationName and impersonation details.
204+ * @returns A promise that fulfills with the GraphQL response.
226205 */
227- public mutationRef < Data > (
206+ public executeMutation < Data > (
228207 name : string ,
229208 options ?: RefOptions
230- ) : MutationRef < Data , undefined >
231-
209+ ) : Promise < ExecuteGraphqlResponse < Data > > ;
210+
232211 /**
233- * Create a reference to a specific "instance" of a named mutation.
234- * @param name - The name of the mutation.
212+ * Executes a pre-defined GraphQL mutation with impersonation.
213+ *
214+ * The mutation must be defined in your Data Connect GQL files.
215+ *
216+ * @param options - The GraphQL options, must include operationName and impersonation details.
235217 * @param variables - The variables for the mutation. May be optional if the mutation's variables are optional.
236- * @param options - The RefOptions for the mutation (optional).
237- * @returns A reference to the named mutation with the specified impersonation and variables.
218+ * @returns A promise that fulfills with the GraphQL response.
238219 */
239- public mutationRef < Data , Variables > (
220+ public executeMutation < Data , Variables > (
240221 name : string ,
241222 variables : Variables ,
242223 options ?: RefOptions
243- ) : MutationRef < Data , Variables > ;
224+ ) : Promise < ExecuteGraphqlResponse < Data > > ;
244225
245- public mutationRef < Data , Variables > (
226+ public executeMutation < Data , Variables > (
246227 name : string ,
247228 variables : Variables ,
248229 options ?: RefOptions
249- ) : MutationRef < Data , Variables > {
250- if ( ! ( 'connector' in this . connectorConfig ) ) {
251- throw new FirebaseDataConnectError (
252- DATA_CONNECT_ERROR_CODE_MAPPING . INVALID_ARGUMENT ,
253- `The 'connectorConfig.connector' field used to instantiate your Data Connect
254- instance must be a non-empty string (the connectorId) when creating a mutationRef.` ) ;
255- }
256- return new MutationRef ( this , name , variables , options ) ;
257- }
258- }
259-
260- export interface OperationResult < Data , Variables > {
261- ref : OperationRef < Data , Variables > ;
262- data : Data ;
263- variables : Variables ;
264- dataConnect : DataConnect ;
265- }
266-
267- /**
268- * The result of executing a query.
269- */
270- export interface QueryResult < Data , Variables > extends OperationResult < Data , Variables > {
271- ref : QueryRef < Data , Variables > ;
272- }
273-
274- /**
275- * The result of executing a mutation.
276- */
277- export interface MutationResult < Data , Variables > extends OperationResult < Data , Variables > {
278- ref : MutationRef < Data , Variables > ;
279- }
280-
281- export abstract class OperationRef < Data , Variables > {
282- constructor (
283- public readonly dataConnect : DataConnect ,
284- public readonly name : string ,
285- public readonly variables : Variables ,
286- public readonly options ?: RefOptions
287- ) { }
288- abstract execute ( ) : Promise < OperationResult < Data , Variables > > ;
289- }
290-
291- export class QueryRef < Data , Variables > extends OperationRef < Data , Variables > {
292- async execute ( ) : Promise < QueryResult < Data , Variables > > {
293- const { data } = await this . dataConnect . executeQuery < Data , Variables > ( this . name , this . variables , this . options ) ;
294- return {
295- ref : this ,
296- data : data ,
297- variables : this . variables ,
298- dataConnect : this . dataConnect
299- }
300- }
301- }
302-
303- export class MutationRef < Data , Variables > extends OperationRef < Data , Variables > {
304- async execute ( ) : Promise < MutationResult < Data , Variables > > {
305- const { data } = await this . dataConnect . executeMutation < Data , Variables > ( this . name , this . variables , this . options )
306- return {
307- ref : this ,
308- data : data ,
309- variables : this . variables ,
310- dataConnect : this . dataConnect
311- }
230+ ) : Promise < ExecuteGraphqlResponse < Data > > {
231+ return this . client . executeMutation < Data , Variables > ( name , variables , options ) ;
312232 }
313233}
0 commit comments