Code Monkey home page Code Monkey logo

Comments (5)

rmosolgo avatar rmosolgo commented on June 18, 2024 1

Ok, thanks for sharing that... I created a test script based on that string. Could you please run it and share the output you get?

Do you see any differences between the string in the test script and the string in your app?

require "bundler/inline"

gemfile do
  gem "graphql", "2.3.0"
end

str1 = "
                mutation {
                  createRecord(data: {
                     dynamicFields: { string_test: \"avenue 1st
 2nd line\"},
                   })
                  { id, dynamicFields }\
               }
              "
puts str1.inspect
# "\n                mutation {\n                  createRecord(data: {\n                     dynamicFields: { string_test: \"avenue 1st\n 2nd line\"},\n                   })\n                  { id, dynamicFields }               }\n              "

str2 = GraphQL::Language.escape_single_quoted_newlines(str1)
# This one is different: it has an extra backslash ("\\n" instead of "\n"), showing that the newline was escaped:
puts str2.inspect
# "\n                mutation {\n                  createRecord(data: {\n                     dynamicFields: { string_test: \"avenue 1st\\n 2nd line\"},\n                   })\n                  { id, dynamicFields }               }\n              "

begin
  GraphQL.parse(str1)
rescue GraphQL::ParseError => err
  pp [err.line, err.col, err.message]
  # [4, 52, "Expected string or block string, but it was malformed"]
end

pp GraphQL.parse(str2).class
# GraphQL::Language::Nodes::Document

from graphql-ruby.

rmosolgo avatar rmosolgo commented on June 18, 2024

Hey, sorry for the trouble and thanks for the detailed report. Based on your examples, I added some cases to the GraphQL-Ruby test suite, but they passed as expected: 1e662f4

In your application, could you share the terminal output of puts bad_query_string.inspect? That would help me make sure I'm using the same linebreaks and backslashes as are present in your example.

from graphql-ruby.

niltonvasques avatar niltonvasques commented on June 18, 2024

Interesting!

Find the output here from the bad_query_string.inspect.

"\n                mutation {\n                  createRecord(data: {\n                     dynamicFields: { string_test: \"avenue 1st\n 2nd line\"},\n                   })\n                  { id, dynamicFields }\n                }\n              "

from graphql-ruby.

niltonvasques avatar niltonvasques commented on June 18, 2024

@rmosolgo I just found the problem, our application calls GraphQL.parse function directly to analyse query names, thus now we are also escaping from there!

::GraphQL.parse(query).definitions[0].selections[0].name

Thanks a lot for help me to identify it.

from graphql-ruby.

rmosolgo avatar rmosolgo commented on June 18, 2024

Glad you got to the bottom of it 👍

from graphql-ruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.