0

I get this error on load when I try to load the graphiql client with Rails 6, specifically wanting to use the Documentation Explorer.

TypeError: Cannot read property 'types' of undefined
at buildClientSchema (http://localhost:3000/assets/graphiql/rails/application-6f03c7a92432765b0fbe671bfb7a292ee6c37e6704b6e6ac95587e45676bbf72.js:34102:72)
at http://localhost:3000/assets/graphiql/rails/application-6f03c7a92432765b0fbe671bfb7a292ee6c37e6704b6e6ac95587e45676bbf72.js:2795:55

I tried deleting my graphql directory and re-doing the rails generate graphql:install.

I am using

  • rails 6
  • graphiql-rails (1.7.0)
  • graphql (1.10.5)

I originally built it as API only (and removed unnecessary files, including the assets) but then added the necessary configurations to run graphiql in local development, including adding an app/assetts/config/manifest.js with

//= link_tree ../images
//= link_directory ../javascripts .js
//= link_directory ../stylesheets .css

I was able to look into it more - I made a breakpoint in the chrome debugger for line 34,102, which has the following code:

function buildClientSchema(introspection, options) {
  // Get the schema from the introspection result.
  var schemaIntrospection = introspection.__schema;

  // Converts the list of types into a keyMap based on the type names.
  var typeIntrospectionMap = (0, _keyMap2.default)(schemaIntrospection.types, function (type) {
    return type.name;
  });
..... more code ......

The issue is with schemaIntrospection.types, schemaIntrospection is undefined. So above, I inspected the introspection variable which calls introspection.__schema - The introspection variable looked like:

{"Schema":
    {"queryType": {"name":"Query"},
     "mutationType": {"name":"Mutation"},
     "subscriptionType":null,
.... more JSON ...

So, what I ended up doing is instead of having var schemaIntrospection = introspection.__schema;, I set the schemaIntrospection variable using the correct key:

var schemaIntrospection = introspection.Schema;

And it worked! For that specific call only :/ , as I had used the interactive debugger

Does anyone know how I can fix this with ruby-graphql/graphiql more permanently?

I want to be able to use the Documentation Explorer

Thanks!

user2498045
  • 141
  • 1
  • 5

1 Answers1

0

Circling back, I was migrating from a REST based API to Graphql. My old project had a middleware (https://github.com/vigetlabs/olive_branch) which I had forgotten to disable, so this was causing it to auto change snake case (which it identified __schema as snake case) to CamelCase. My bad about this, but wanted to follow up in case anyone else had issues, maybe check your middlewares.

user2498045
  • 141
  • 1
  • 5