rmosolgo / graphiql-rails

Mount the GraphiQL query editor in a Rails app
MIT License
447 stars 137 forks source link

Graphql query execute is getting freeze from model callbacks #103

Closed nagarjuna closed 2 years ago

nagarjuna commented 2 years ago

We have upgraded rails(5.2.3 to 6.1.6), graphiql-rails(1.7.0 to 1.8.0), and graphql(1.9.14 to 2.0.14) versions recently

All our active record models and graphql types, and query models are virtual models means which are generated on application start

We have configurable webhooks feature, means we can have create/update/delete webhooks which will be triggered on after_create_commit, after_update_commit and before_destroy and the webhook payload is fetching using graphiql query. Application is getting freeze when it triggers grphiql query. The resolver method is like below

SchemaControl::Graphiql.const_set(
        "GraphiqlQueryType",
        # GraphQL::ObjectType.define do
        Class.new(Types::BaseObject) do
          graphql_name 'Query'
          description 'The root of all queries'

          include GraphQL::Types::Relay::HasNodeField
          include GraphQL::Types::Relay::HasNodesField

          SchemaControl::SchemaBuilder.database_models.each do |model|
            model_name = model.name.demodulize

            field model_name.underscore.downcase.to_sym, "Types::#{model.name.demodulize}Type".classify.constantize, camelize: false, null: true do
              argument :id, GraphQL::Types::ID, required: true
              def resolve(obj, args, ctx)
                ctx_attributes = ctx.to_h.with_indifferent_access
                input_args = args.to_h.with_indifferent_access
                ## Application getting freeze at below line
                model = "SchemaControl::Model::#{self.name.singularize.classify}".classify.constantize 
                model.where({id: input_args[:id]}.merge(ctx_attributes[:access_control_column].present? ? {ctx_attributes[:access_control_column] => ctx_attributes[:access_control_id]} : {}) ).first
              end
            end
          end
        end
      )

This was working fine with older version but giving no error but application is not responding(freezing) after upgrade.

Any idea whats wrong in the code/approach ?

nagarjuna commented 2 years ago

Wrong place

https://github.com/rmosolgo/graphql-ruby/issues/4198