Coder Social home page Coder Social logo

TypeError: Cannot read property 'types' of undefined when completeing tutorial on https://www.howtographql.com/graphql-ruby/2-queries/ about graphql-ruby HOT 17 CLOSED

howtographql avatar howtographql commented on August 11, 2024 1
TypeError: Cannot read property 'types' of undefined when completeing tutorial on https://www.howtographql.com/graphql-ruby/2-queries/

from graphql-ruby.

Comments (17)

zacheryph avatar zacheryph commented on August 11, 2024 2

I also found you can receive this if you dont pass null: true|false to a field.

from graphql-ruby.

lostmarinero avatar lostmarinero commented on August 11, 2024 2

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.

from graphql-ruby.

RStankov avatar RStankov commented on August 11, 2024 1

Hey, I opened a PR which fixes this issue 👉 howtographql/howtographql#897

from graphql-ruby.

Jakub41 avatar Jakub41 commented on August 11, 2024 1

Ok thanks so I have to change to basenode instead great will try that

from graphql-ruby.

akz92 avatar akz92 commented on August 11, 2024 1

I got this error but it turned out to be a mistake with the type of one of the fields I declared.

from graphql-ruby.

karolselak avatar karolselak commented on August 11, 2024

I have exactly the same issue. Does anyone know how to fix it?

from graphql-ruby.

jonatasbaldin avatar jonatasbaldin commented on August 11, 2024

Fixed at #897, you may close this one ;)

from graphql-ruby.

smugller avatar smugller commented on August 11, 2024

I still have this issues...

from graphql-ruby.

Jakub41 avatar Jakub41 commented on August 11, 2024

Hello,

I'm having the same issue doing the same tutorial.
I copied the entire code from yours and getting the same error.

TypeError: Cannot read property 'types' of undefined
    at buildClientSchema (http://localhost:3000/assets/graphiql/rails/graphiql-0.12.0.self-84a2376c545f0620e86ec9d8681863a2f1b56b5eb3fe74c45003ff1fb982c1a3.js?body=1:33481:72)
    at http://localhost:3000/assets/graphiql/rails/graphiql-0.12.0.self-84a2376c545f0620e86ec9d8681863a2f1b56b5eb3fe74c45003ff1fb982c1a3.js?body=1:2174:55

Thanks for help

from graphql-ruby.

RStankov avatar RStankov commented on August 11, 2024

Can you give me a link to repo with steps you have so far?

from graphql-ruby.

Jakub41 avatar Jakub41 commented on August 11, 2024

Yes sharing the link thanks
https://github.com/Jakub41/GraphQL-Ruby-Server

from graphql-ruby.

RStankov avatar RStankov commented on August 11, 2024

@Jakub41 @paw3lgora I found the issue. It was inheriting from BaseNode, not BaseObject:

diff --git a/app/graphql/types/link_type.rb b/app/graphql/types/link_type.rb
index f76eb79..07fe5cb 100644
--- a/app/graphql/types/link_type.rb
+++ b/app/graphql/types/link_type.rb
@@ -1,5 +1,6 @@
 module Types
-  class LinkType < BaseNode
+  class LinkType < BaseObject
+    field :id, ID, null: false
     field :created_at, DateTimeType, null: false
     field :url, String, null: false
     field :description, String, null: false
diff --git a/app/graphql/types/user_type.rb b/app/graphql/types/user_type.rb
index 8afeeef..a7ea514 100644
--- a/app/graphql/types/user_type.rb
+++ b/app/graphql/types/user_type.rb
@@ -1,5 +1,6 @@
 module Types
-  class UserType < BaseNode
+  class UserType < BaseObject
+    field :id, ID, null: false
     field :created_at, DateTimeType, null: false
     field :name, String, null: false
     field :email, String, null: false
diff --git a/app/graphql/types/vote_type.rb b/app/graphql/types/vote_type.rb
index 719638a..a5a2c38 100644
--- a/app/graphql/types/vote_type.rb
+++ b/app/graphql/types/vote_type.rb
@@ -1,5 +1,6 @@
 module Types
-  class VoteType < BaseNode
+  class VoteType < BaseObject
+    field :id, ID, null: false
     field :created_at, DateTimeType, null: false
     field :user, UserType, null: false
     field :link, LinkType, null: false

BaseNode was part of a chapter in the tutorial, which didn't make the cut. It is part of the repo code though.

from graphql-ruby.

runn-vermel avatar runn-vermel commented on August 11, 2024

I just ran into the same issue with the same errors, so it seems the PR didn't fix it :(

from graphql-ruby.

RStankov avatar RStankov commented on August 11, 2024

Hey, does this help

#19 (comment)

from graphql-ruby.

runn-vermel avatar runn-vermel commented on August 11, 2024

frankly, i'm not sure what to do with that comment - do i replace baseObject with BaseNode on linkType? i haven't even gotten as far as UserType or VoteType.

if that's the case ( replacing BaseObject with BaseNode), that doesn't work for me - i still get the same error

TypeError: Cannot read property 'types' of undefined
    at buildClientSchema (http://localhost:3000/assets/graphiql/rails/graphiql-0.12.0.self-84a2376c545f0620e86ec9d8681863a2f1b56b5eb3fe74c45003ff1fb982c1a3.js?body=1:33481:72)
    at http://localhost:3000/assets/graphiql/rails/graphiql-0.12.0.self-84a2376c545f0620e86ec9d8681863a2f1b56b5eb3fe74c45003ff1fb982c1a3.js?body=1:2174:55

from graphql-ruby.

RStankov avatar RStankov commented on August 11, 2024

@runn-vermel can you send me link to the repo to check out?

from graphql-ruby.

lostmarinero avatar lostmarinero commented on August 11, 2024

I recently got this error. I am running rails 6, graphiql-rails (1.7.0) and graphql (1.10.5). I had built it as an API 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

The error I am receiving is:

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 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 more permanently?

I want to be able to use the Documentation Explorer

Thanks!

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.