Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support a custom Schema.query_class #4679

Merged
merged 1 commit into from
Nov 21, 2023
Merged

Support a custom Schema.query_class #4679

merged 1 commit into from
Nov 21, 2023

Conversation

rmosolgo
Copy link
Owner

Fixes #4354

validator_opts = { schema: self }
rules && (validator_opts[:rules] = rules)
validator = GraphQL::StaticValidation::Validator.new(**validator_opts)
res = validator.validate(query, timeout: validate_timeout, max_errors: validate_max_errors)
res[:errors]
end

def query_class(new_query_class = NOT_CONFIGURED)
if NOT_CONFIGURED.equal?(new_query_class)
@query_class || (superclass.respond_to?(:query_class) ? superclass.query_class : GraphQL::Query)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth remembering this outcome?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a big question all around this library... what should happen in cases like:

BaseSchema.query_class = CustomQuery1 
ChildSchema = Class.new(BaseSchema)
ChildSchema.query_class # CustomQuery1 
# Then: 

BaseSchema.query_class = CustomQuery2 
ChildSchema.query_class # What should this return?

I'd expect it to return the inherited value, CustomQuery2, not the previously inherited value, CustomQuery1.

On the one hand, I wouldn't expect situations like this to happen often, but on the other hand, with Rails autoloading, and with Ruby being Ruby, I'd want to stay open to it!

So that's why I didn't memoize the result. What do you think?

Copy link
Contributor

@ravangen ravangen Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point, probably not worth it at this time.

Our internal implementation has class_attribute :query_class, default: GraphQL::Shopify::Query currently (we were ok with the dependency on activesupport) which handles this case.

@rmosolgo rmosolgo merged commit 565b62f into master Nov 21, 2023
12 checks passed
@rmosolgo rmosolgo added this to the 2.1.7 milestone Nov 21, 2023
@rmosolgo rmosolgo deleted the custom-query-class branch November 21, 2023 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configurable Query class to be used for operation evaluation
2 participants