@@ -25,6 +25,7 @@ import {
2525 ConnectorConfig ,
2626 ExecuteGraphqlResponse ,
2727 GraphqlOptions ,
28+ RefOptions ,
2829} from './data-connect-api' ;
2930
3031export class DataConnectService {
@@ -162,78 +163,97 @@ export class DataConnect {
162163 }
163164
164165 /** @internal */
165- public executeQuery < Data , Variables > ( options : GraphqlOptions < Variables > ) : Promise < ExecuteGraphqlResponse < Data > > {
166- return this . client . executeQuery < Data , Variables > ( options ) ;
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 ) ;
167172 }
168173
169174 /** @internal */
170- public executeMutation < Data , Variables > ( options : GraphqlOptions < Variables > ) : Promise < ExecuteGraphqlResponse < Data > > {
171- return this . client . executeMutation < Data , Variables > ( options ) ;
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 ) ;
172181 }
173182
174183 /**
175184 * Create a reference to a specific "instance" of a named query.
176- * @param options - Required {@link GraphqlOptions} when executing a GraphQL query.
177- * @returns an reference to the named query with the specified impersonation and variables.
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.
178188 */
179189 public queryRef < Data > (
180- options : GraphqlOptions < undefined >
190+ name : string ,
191+ options ?: RefOptions
181192 ) : QueryRef < Data , undefined > ;
182193
183194 /**
184195 * Create a reference to a specific "instance" of a named query.
185- * @param options - Required {@link GraphqlOptions} when executing a GraphQL query.
186- * @returns an reference to the named query with the specified impersonation and variables.
196+ * @param name - The name of the query.
197+ * @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.
187200 */
188201 public queryRef < Data , Variables > (
189- options : GraphqlOptions < Variables >
202+ name : string ,
203+ variables : Variables ,
204+ options ?: RefOptions
190205 ) : QueryRef < Data , Variables > ;
191206
192207 public queryRef < Data , Variables > (
193- options : GraphqlOptions < Variables >
208+ name : string ,
209+ variables : Variables ,
210+ options ?: RefOptions
194211 ) : QueryRef < Data , Variables > {
195212 if ( ! ( 'connector' in this . connectorConfig ) ) {
196213 throw new FirebaseDataConnectError (
197214 DATA_CONNECT_ERROR_CODE_MAPPING . INVALID_ARGUMENT ,
198215 `The 'connectorConfig.connector' field used to instantiate your Data Connect
199216 instance must be a non-empty string (the connectorId) when creating a queryRef.` ) ;
200217 }
201- return new QueryRef ( this , options ) ;
218+ return new QueryRef ( this , name , variables , options ) ;
202219 }
203220
204221 /**
205222 * Create a reference to a specific "instance" of a named mutation.
206- * @param options - Required {@link GraphqlOptions} when executing a GraphQL mutation.
207- * @returns an reference to the named mutation with the specified impersonation and variables.
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.
208226 */
209227 public mutationRef < Data > (
210- options : GraphqlOptions < undefined >
228+ name : string ,
229+ options ?: RefOptions
211230 ) : MutationRef < Data , undefined >
212231
213232 /**
214233 * Create a reference to a specific "instance" of a named mutation.
215- * @param options - Required {@link GraphqlOptions} when executing a GraphQL mutation.
216- * @returns an reference to the named mutation with the specified impersonation and variables.
234+ * @param name - The name of the mutation.
235+ * @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.
217238 */
218239 public mutationRef < Data , Variables > (
219- options : GraphqlOptions < Variables >
240+ name : string ,
241+ variables : Variables ,
242+ options ?: RefOptions
220243 ) : MutationRef < Data , Variables > ;
221244
222- /**
223- * Create a reference to a specific "instance" of a named mutation.
224- * @param options - Required {@link GraphqlOptions} when executing a GraphQL mutation.
225- * @returns an reference to the named mutation with the specified impersonation and variables.
226- */
227245 public mutationRef < Data , Variables > (
228- options : GraphqlOptions < Variables >
246+ name : string ,
247+ variables : Variables ,
248+ options ?: RefOptions
229249 ) : MutationRef < Data , Variables > {
230250 if ( ! ( 'connector' in this . connectorConfig ) ) {
231251 throw new FirebaseDataConnectError (
232252 DATA_CONNECT_ERROR_CODE_MAPPING . INVALID_ARGUMENT ,
233253 `The 'connectorConfig.connector' field used to instantiate your Data Connect
234254 instance must be a non-empty string (the connectorId) when creating a mutationRef.` ) ;
235255 }
236- return new MutationRef ( this , options ) ;
256+ return new MutationRef ( this , name , variables , options ) ;
237257 }
238258}
239259
@@ -244,54 +264,49 @@ interface OperationResult<Data, Variables> {
244264 dataConnect : DataConnect ;
245265}
246266
267+ /**
268+ * The result of executing a query.
269+ */
247270export interface QueryResult < Data , Variables > extends OperationResult < Data , Variables > {
248271 ref : QueryRef < Data , Variables > ;
249272}
250273
274+ /**
275+ * The result of executing a mutation.
276+ */
251277export interface MutationResult < Data , Variables > extends OperationResult < Data , Variables > {
252278 ref : MutationRef < Data , Variables > ;
253279}
254280
255281abstract class OperationRef < Data , Variables > {
256282 constructor (
257283 public readonly dataConnect : DataConnect ,
258- public readonly options : GraphqlOptions < Variables > ,
259- ) {
260- if ( typeof options . operationName === 'undefined' ) {
261- throw new FirebaseDataConnectError (
262- DATA_CONNECT_ERROR_CODE_MAPPING . INVALID_ARGUMENT ,
263- `The 'options.operationName' field must be provided when creating a queryRef
264- or mutationRef.` ) ;
265- }
266- if ( typeof options . impersonate === 'undefined' ) {
267- throw new FirebaseDataConnectError (
268- DATA_CONNECT_ERROR_CODE_MAPPING . INVALID_ARGUMENT ,
269- `The 'options.impersonate' field must be provided when creating a queryRef
270- or mutationRef.` ) ;
271- }
272- }
284+ public readonly name : string ,
285+ public readonly variables : Variables ,
286+ public readonly options ?: RefOptions
287+ ) { }
273288 abstract execute ( ) : Promise < OperationResult < Data , Variables > > ;
274289}
275290
276291class QueryRef < Data , Variables > extends OperationRef < Data , Variables > {
277292 async execute ( ) : Promise < QueryResult < Data , Variables > > {
278- const { data } = await this . dataConnect . executeQuery < Data , Variables > ( this . options ) ;
293+ const { data } = await this . dataConnect . executeQuery < Data , Variables > ( this . name , this . variables , this . options ) ;
279294 return {
280295 ref : this ,
281296 data : data ,
282- variables : this . options . variables as Variables ,
297+ variables : this . variables ,
283298 dataConnect : this . dataConnect
284299 }
285300 }
286301}
287302
288303class MutationRef < Data , Variables > extends OperationRef < Data , Variables > {
289304 async execute ( ) : Promise < MutationResult < Data , Variables > > {
290- const { data } = await this . dataConnect . executeMutation < Data , Variables > ( this . options )
305+ const { data } = await this . dataConnect . executeMutation < Data , Variables > ( this . name , this . variables , this . options )
291306 return {
292307 ref : this ,
293308 data : data ,
294- variables : this . options . variables as Variables ,
309+ variables : this . variables ,
295310 dataConnect : this . dataConnect
296311 }
297312 }
0 commit comments