@@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
3
3
import { $ , Executor } from 'edgedb' ;
4
4
import { retry , RetryOptions } from '~/common/retry' ;
5
5
import { TypedEdgeQL } from './edgeql' ;
6
+ import { ExclusivityViolationError } from './exclusivity-violation.error' ;
6
7
import { InlineQueryCardinalityMap } from './generated-client/inline-queries' ;
7
8
import { OptionsContext , OptionsFn } from './options.context' ;
8
9
import { Client } from './reexports' ;
@@ -58,29 +59,39 @@ export class EdgeDB {
58
59
) : Promise < R > ;
59
60
60
61
async run ( query : any , args ?: any ) {
61
- if ( query instanceof TypedEdgeQL ) {
62
- const cardinality = InlineQueryCardinalityMap . get ( query . query ) ;
63
- if ( ! cardinality ) {
64
- throw new Error ( `Query was not found from inline query generation` ) ;
62
+ try {
63
+ if ( query instanceof TypedEdgeQL ) {
64
+ const cardinality = InlineQueryCardinalityMap . get ( query . query ) ;
65
+ if ( ! cardinality ) {
66
+ throw new Error ( `Query was not found from inline query generation` ) ;
67
+ }
68
+ const exeMethod = cardinalityToExecutorMethod [ cardinality ] ;
69
+
70
+ return await this . executor . current [ exeMethod ] ( query . query , args ) ;
65
71
}
66
- const exeMethod = cardinalityToExecutorMethod [ cardinality ] ;
67
72
68
- return await this . executor . current [ exeMethod ] ( query . query , args ) ;
69
- }
73
+ if ( query . run ) {
74
+ // eslint-disable-next-line @typescript-eslint/return-await
75
+ return await query . run ( this . executor . current , args ) ;
76
+ }
70
77
71
- if ( query . run ) {
72
- // eslint-disable-next-line @typescript-eslint/return-await
73
- return await query . run ( this . executor . current , args ) ;
74
- }
78
+ if ( typeof query === 'function' ) {
79
+ // eslint-disable-next-line @typescript-eslint/return-await
80
+ return await query ( this . executor . current , args ) ;
81
+ }
75
82
76
- if ( typeof query === 'function' ) {
77
- // eslint-disable-next-line @typescript-eslint/return-await
78
- return await query ( this . executor . current , args ) ;
79
- }
83
+ // For REPL, as this is untyped and assumes many/empty cardinality
84
+ if ( typeof query === 'string' ) {
85
+ return await this . executor . current . query ( query , args ) ;
86
+ }
87
+ } catch ( e ) {
88
+ // Ignore this call in stack trace. This puts the actual query as the first.
89
+ e . stack = e . stack ! . replace ( / ^ \s + a t E d g e D B \. r u n .+ \n / m, '' ) ;
80
90
81
- // For REPL, as this is untyped and assumes many/empty cardinality
82
- if ( typeof query === 'string' ) {
83
- return await this . executor . current . query ( query , args ) ;
91
+ if ( ExclusivityViolationError . is ( e ) ) {
92
+ throw ExclusivityViolationError . cast ( e ) ;
93
+ }
94
+ throw e ;
84
95
}
85
96
86
97
throw new Error ( 'Could not figure out how to run given query' ) ;
0 commit comments