@@ -262,4 +262,79 @@ 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+ get_depth = -> {
286+ graphql_caller = caller . select { |c | c . include? ( "graphql" ) }
287+ graphql_caller . size
288+ }
289+
290+ if lazy
291+ get_depth
292+ else
293+ get_depth . call
294+ end
295+ end
296+ end
297+
298+ class Query < GraphQL ::Schema ::Object
299+ field :thing , Thing
300+
301+ def thing
302+ :something
303+ end
304+ end
305+
306+ query ( Query )
307+ lazy_resolve ( Proc , :call )
308+ end
309+
310+ def self . profile_stack_depth
311+ query_str = <<-GRAPHQL
312+ query($lazyThing: Boolean!, $lazyStackTrace: Boolean!) {
313+ thing {
314+ thing(lazy: $lazyThing) {
315+ thing(lazy: $lazyThing) {
316+ thing(lazy: $lazyThing) {
317+ thing(lazy: $lazyThing) {
318+ stackTraceDepth(lazy: $lazyStackTrace)
319+ }
320+ }
321+ }
322+ }
323+ }
324+ }
325+ GRAPHQL
326+
327+ very_lazy_res = StackDepthSchema . execute ( query_str , variables : { lazyThing : true , lazyStackTrace : true } )
328+ lazy_res = StackDepthSchema . execute ( query_str , variables : { lazyThing : true , lazyStackTrace : false } )
329+ eager_res = StackDepthSchema . execute ( query_str , variables : { lazyThing : false , lazyStackTrace : false } )
330+ get_depth = -> ( result ) { result [ "data" ] [ "thing" ] [ "thing" ] [ "thing" ] [ "thing" ] [ "thing" ] [ "stackTraceDepth" ] }
331+
332+ puts <<~RESULT
333+ Result Depth
334+ ---------------------
335+ Eager #{ get_depth . call ( eager_res ) }
336+ Lazy #{ get_depth . call ( lazy_res ) }
337+ Very Lazy #{ get_depth . call ( very_lazy_res ) }
338+ RESULT
339+ end
265340end
0 commit comments