rmosolgo / graphiql-rails

Mount the GraphiQL query editor in a Rails app
MIT License
447 stars 135 forks source link

I got this when first open graphi page. #14

Closed jackalcooper closed 7 years ago

jackalcooper commented 7 years ago

I got this when first open graphi page and failed to extend doc area but the query works fine.

Started POST "/queries" for 127.0.0.1 at 2016-10-15 16:10:34 +0800
Processing by QueriesController#create as */*
  Parameters: {"query"=>"\n  query IntrospectionQuery {\n    __schema {\n      queryType { name }\n      mutationType { name }\n      subscriptionType { name }\n      types {\n        ...FullType\n      }\n      directives {\n        name\n        description\n        locations\n        args {\n          ...InputValue\n        }\n      }\n    }\n  }\n\n  fragment FullType on __Type {\n    kind\n    name\n    description\n    fields(includeDeprecated: true) {\n      name\n      description\n      args {\n        ...InputValue\n      }\n      type {\n        ...TypeRef\n      }\n      isDeprecated\n      deprecationReason\n    }\n    inputFields {\n      ...InputValue\n    }\n    interfaces {\n      ...TypeRef\n    }\n    enumValues(includeDeprecated: true) {\n      name\n      description\n      isDeprecated\n      deprecationReason\n    }\n    possibleTypes {\n      ...TypeRef\n    }\n  }\n\n  fragment InputValue on __InputValue {\n    name\n    description\n    type { ...TypeRef }\n    defaultValue\n  }\n\n  fragment TypeRef on __Type {\n    kind\n    name\n    ofType {\n      kind\n      name\n      ofType {\n        kind\n        name\n        ofType {\n          kind\n          name\n          ofType {\n            kind\n            name\n            ofType {\n              kind\n              name\n              ofType {\n                kind\n                name\n                ofType {\n                  kind\n                  name\n                }\n              }\n            }\n          }\n        }\n      }\n    }\n  }\n"}
Completed 500 Internal Server Error in 17ms

JSON::GeneratorError - only generation of JSON objects or arrays allowed:
  json_pure (2.0.2) lib/json/common.rb:224:in `generate'
  json_pure (2.0.2) lib/json/common.rb:224:in `generate'
  json_pure (2.0.2) lib/json/common.rb:394:in `dump'
  graphql (0.19.3) lib/graphql/introspection/input_value_type.rb:12:in `block (3 levels) in <top (required)>'
  graphql (0.19.3) lib/graphql/field.rb:162:in `call'
  graphql (0.19.3) lib/graphql/field.rb:162:in `resolve'
  graphql (0.19.3) lib/graphql/query/serial_execution/field_resolution.rb:81:in `block in get_middleware_proc_from_field_resolve'
  graphql (0.19.3) lib/graphql/schema/middleware_chain.rb:24:in `call'
  graphql (0.19.3) lib/graphql/schema/middleware_chain.rb:24:in `call'
  graphql (0.19.3) lib/graphql/schema/rescue_middleware.rb:34:in `call'
  graphql (0.19.3) lib/graphql/schema/middleware_chain.rb:24:in `call'
  graphql (0.19.3) lib/graphql/query/serial_execution/field_resolution.rb:69:in `get_raw_value'
  graphql (0.19.3) lib/graphql/query/serial_execution/field_resolution.rb:18:in `result'
  graphql (0.19.3) lib/graphql/query/serial_execution/selection_resolution.rb:22:in `block in result'
rmosolgo commented 7 years ago

Thanks, I think graphql-ruby is missing quirks_mode: true somewhere!

rmosolgo commented 7 years ago

I think this is fixed by https://github.com/rmosolgo/graphql-ruby/pull/316 , can you try master branch?

jcmfernandes commented 7 years ago

Since graphql-ruby is heavy on JSON generation for obvious reasons, wouldn't it be cool to allow it to use other JSON serializers like Oj?

If it doesn't sound like a bad idea right away, I may give this a try and post some benchmarks soon πŸ˜‰ what do you say @rmosolgo?

rmosolgo commented 7 years ago

heavy on JSON generation

I don't think of it as heavy on JSON generation. There are only a few places where we stringify Ruby values with JSON:

In general, graphql-ruby returns a Hash to the user, and the user can serialize it however they want!

I don't expect a big difference in the benchmark, since JSON is used so sparingly in the gem itself, but you're welcome to give it a try. If it turns out to be a big improvement, I'm happy to look at supporting other JSON implementations!

jcmfernandes commented 7 years ago

You, unexpectedly, seem mostly right πŸ˜‰ somehow I was expecting more JSON magic to happen inside, but seems like the bulk of the work is indeed outside, in serializing the response.

jackalcooper commented 7 years ago

Hi, guys. It is not a pain to me now. Well it could be just for now.

Here is my dirty walk around:

module JSON
  def self.dump(raw)
    raw.to_json
  end
end
rmosolgo commented 7 years ago

Glad you found something that works for you! I hope those changes to JSON will fix this bug for others, too.