lib/graphql_grpc/schema.rb in graphql_grpc-0.1.11 vs lib/graphql_grpc/schema.rb in graphql_grpc-0.1.12
- old
+ new
@@ -23,16 +23,17 @@
require 'google/protobuf/empty_pb'
module GraphqlGrpc
# :nodoc:
module Schema
+ QUERY_PREFIX_ENV_VAR = 'GRAPHQL_GRPC_QUERY_PREFIXES'
# TODO: Find better way to detect queries
# Currently look for methods named 'get', 'find' or with no args
def query?(name_sym, rpc_desc)
- name_sym.to_s.start_with?('get') ||
- name_sym.to_s.start_with?('find') ||
- rpc_desc.rpc_desc.input == Google::Protobuf::Empty
+ name_str = name_sym.to_s
+ prefixes.each { |prefix| return true if name_str.start_with?(prefix) }
+ rpc_desc.rpc_desc.input == Google::Protobuf::Empty
end
def streaming_response?(rpc_desc)
rpc_desc&.rpc_desc&.output.class == GRPC::RpcDesc::Stream
end
@@ -93,8 +94,14 @@
schema {
query: Query
#{gql_mutations.empty? ? '' : 'mutation: Mutation'}
}
GRAPHQL_SCHEMA
+ end
+
+ private
+
+ def prefixes
+ @prefixes ||= (ENV[QUERY_PREFIX_ENV_VAR]&.strip&.split(',') || ['get', 'find'])
end
end
end