@@ -262,4 +262,75 @@ def self.profile_schema_memory_footprint
262262
263263 report . pretty_print
264264 end
265+
266+ class StackDepthSchema < GraphQL ::Schema
267+ class Thing < GraphQL ::Schema ::Object
268+ field :thing , self do
269+ argument :lazy , Boolean , default_value : false
270+ end
271+
272+ def thing ( lazy :)
273+ if lazy
274+ -> { :something }
275+ else
276+ :something
277+ end
278+ end
279+
280+ field :stack_trace_depth , Integer do
281+ argument :lazy , Boolean , default_value : false
282+ end
283+
284+ def stack_trace_depth ( lazy :)
285+ if lazy
286+ -> { caller . size }
287+ else
288+ caller . size
289+ end
290+ end
291+ end
292+
293+ class Query < GraphQL ::Schema ::Object
294+ field :thing , Thing
295+
296+ def thing
297+ :something
298+ end
299+ end
300+
301+ query ( Query )
302+ lazy_resolve ( Proc , :call )
303+ end
304+
305+ def self . profile_stack_depth
306+ query_str = <<-GRAPHQL
307+ query($lazyThing: Boolean!, $lazyStackTrace: Boolean!) {
308+ thing {
309+ thing(lazy: $lazyThing) {
310+ thing(lazy: $lazyThing) {
311+ thing(lazy: $lazyThing) {
312+ thing(lazy: $lazyThing) {
313+ stackTraceDepth(lazy: $lazyStackTrace)
314+ }
315+ }
316+ }
317+ }
318+ }
319+ }
320+ GRAPHQL
321+
322+ very_lazy_res = StackDepthSchema . execute ( query_str , variables : { lazyThing : true , lazyStackTrace : true } )
323+ pp very_lazy_res
324+ lazy_res = StackDepthSchema . execute ( query_str , variables : { lazyThing : true , lazyStackTrace : false } )
325+ eager_res = StackDepthSchema . execute ( query_str , variables : { lazyThing : false , lazyStackTrace : false } )
326+ get_depth = -> ( result ) { result [ "data" ] [ "thing" ] [ "thing" ] [ "thing" ] [ "thing" ] [ "thing" ] [ "stackTraceDepth" ] }
327+
328+ puts <<~RESULT
329+ Result Depth
330+ ---------------------
331+ Eager #{ get_depth . call ( eager_res ) }
332+ Lazy #{ get_depth . call ( lazy_res ) }
333+ Very Lazy #{ get_depth . call ( very_lazy_res ) }
334+ RESULT
335+ end
265336end
0 commit comments