Module: GraphQL::Language
- Included in:
- StaticValidation::DirectivesAreInValidLocations
- Defined in:
- lib/graphql/language.rb,
lib/graphql/language/cache.rb,
lib/graphql/language/lexer.rb,
lib/graphql/language/nodes.rb,
lib/graphql/language/token.rb,
lib/graphql/language/parser.rb,
lib/graphql/language/printer.rb,
lib/graphql/language/visitor.rb,
lib/graphql/language/generation.rb,
lib/graphql/language/block_string.rb,
lib/graphql/language/static_visitor.rb,
lib/graphql/language/definition_slice.rb,
lib/graphql/language/sanitized_printer.rb,
lib/graphql/language/document_from_schema_definition.rb
Defined Under Namespace
Modules: BlockString, DefinitionSlice, Generation, Nodes Classes: Cache, DocumentFromSchemaDefinition, Lexer, Parser, Printer, SanitizedPrinter, StaticVisitor, Token, Visitor
Class Method Summary collapse
-
.escape_single_quoted_newlines(query_str) ⇒ String
Returns a new string if any single-quoted newlines were escaped.
-
.serialize(value) ⇒ Object
private
Class Method Details
.escape_single_quoted_newlines(query_str) ⇒ String
Returns a new string if any single-quoted newlines were escaped.
Otherwise, returns query_str
unchanged.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/graphql/language.rb', line 41 def self.escape_single_quoted_newlines(query_str) scanner = StringScanner.new(query_str) inside_single_quoted_string = false new_query_str = nil while !scanner.eos? if (match = scanner.scan(/(?:\\"|[^"\n\r]|""")+/m)) && new_query_str new_query_str << match elsif scanner.scan('"') new_query_str && (new_query_str << '"') inside_single_quoted_string = !inside_single_quoted_string elsif scanner.scan("\n") if inside_single_quoted_string new_query_str ||= query_str[0, scanner.pos - 1] new_query_str << '\\n' else new_query_str && (new_query_str << "\n") end elsif scanner.scan("\r") if inside_single_quoted_string new_query_str ||= query_str[0, scanner.pos - 1] new_query_str << '\\r' else new_query_str && (new_query_str << "\r") end elsif scanner.eos? break else raise ArgumentError, "Unmatchable string scanner segment: #{scanner.rest.inspect}" end end new_query_str || query_str end |
.serialize(value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/graphql/language.rb', line 20 def self.serialize(value) if value.is_a?(Hash) serialized_hash = value.map do |k, v| "#{k}:#{serialize v}" end.join(",") "{#{serialized_hash}}" elsif value.is_a?(Array) serialized_array = value.map do |v| serialize v end.join(",") "[#{serialized_array}]" else JSON.generate(value, quirks_mode: true) end end |