Graphql-ruby: Bare-word names are parsing as strings

Created on 14 Aug 2018  路  10Comments  路  Source: rmosolgo/graphql-ruby

Consider a query like

{
  node(id: garbage) {
    id
  }
}

GraphiQL red-underlines this as invalid syntax (since IDs are strings and should be quoted). On graphql-js similarly you get back a top-level error "Expected type ID!, found garbage".

In graphql-ruby (1.8.7) it executes the query with id given the value of "garbage". As far as I can tell this is not spec-compliant.

cc @bernardoamc @swalkinshaw

Most helpful comment

Probably related, but this also parses correctly:

{
  node(id:) {
    id
  }
}

I'll take a look later, unless someone gets to it before.

All 10 comments

yes, seems wrong 馃槅

It's a feature, not a bug 馃槅, new RFC to add this to the spec please :trollface:

Probably related, but this also parses correctly:

{
  node(id:) {
    id
  }
}

I'll take a look later, unless someone gets to it before.

I made a PR for another issue that parses # comment as an empty document (should raise error)
https://github.com/rmosolgo/graphql-ruby/pull/2344

Long story short, I got racc/ragel/colm setup, would like to give this a shot.

This was pretty fun, took quite a bit of head banging to spot the subtle issue. @cjoudrey

https://github.com/rmosolgo/graphql-ruby/pull/2344/commits/f2191b33e29272b326ef30183e967b8859873b9b

What a find! 馃嵒

Same as #2371, I think

I think garbage is still parsed correctly as an enum value when the spec might specify that it must be all caps. Let me check that!

it looks like this is fixed in the latest version:

# test.rb
require "graphql"

class Query < GraphQL::Schema::Object
  field :str, String, null: false do
    argument :input, String, required: true
  end

  def str(input:)
    input
  end
end

class Schema < GraphQL::Schema
  query(Query)
end

p Schema.execute('{ str(input: "abc") }')
p Schema.execute('{ str(input: abc) }')
$ ruby test.rb
#<GraphQL::Query::Result @query=... @to_h={"data"=>{"str"=>"abc"}}>
#<GraphQL::Query::Result @query=... @to_h={"errors"=>[{"message"=>"Argument 'input' on Field 'str' has an invalid value (abc). Expected type 'String!'.", "locations"=>[{"line"=>1, "column"=>3}], "path"=>["query", "str", "input"], "extensions"=>{"code"=>"argumentLiteralsIncompatible", "typeName"=>"Field", "argumentName"=>"input"}}]}>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jturkel picture jturkel  路  3Comments

ecomuere picture ecomuere  路  3Comments

sayduck-daniel picture sayduck-daniel  路  3Comments

gastonmorixe picture gastonmorixe  路  3Comments

jesster2k10 picture jesster2k10  路  3Comments