graphiti-api / vandal

16 stars 4 forks source link

Results not loading #4

Closed cooljacob204 closed 4 years ago

cooljacob204 commented 4 years ago

Hey All, the results and raw sections are not displaying any data. App is returning a 200 and a json object.

image

Running on Rails 2.6.4 using the vandal gem. Everything looks correct to me response wise.

Request url for this example is <my_app>/letters?page[number]=1&page[size]=10, however all resources are not displaying.

Rails code:

resource

class LetterResource < ApplicationResource
  attribute :first_name, :string
end

controller:

class LettersController < ApplicationController
  include Graphiti::Rails

  def index
    letters = LetterResource.all(params)

    render json: letters
  end

  def show
    letter = LetterResource.find(params)

    render json: letter
  end
end

Chrome error:

From Rails

each-pair.ts:2 Uncaught (in promise) TypeError: Cannot convert undefined or null to object at Function.keys () at w (each-pair.ts:2) at e.value (response-table.ts:114) at e.value (response-table.ts:172) at response-table.ts:47 at Array.map () at e.value (response-table.ts:46) at new e (response-table.ts:20) at e. (query.ts:134) at M (runtime.js:62)

From downloaded client in dev mode (still in chrome console)

vue.runtime.esm.js?2b0e:619 [Vue warn]: Error in v-on handler (Promise/async): "TypeError: Cannot convert undefined or null to object"

found in

---> at src/views/All.vue

at src/App.vue

and

vue.runtime.esm.js?2b0e:1888 TypeError: Cannot convert undefined or null to object at Function.keys () at eachPair (each-pair.ts?200b:2) at ResponseTable._buildRowAttributes (response-table.ts?b933:114) at ResponseTable.buildRow (response-table.ts?b933:172) at eval (response-table.ts?b933:47) at Array.map () at ResponseTable._buildRows (response-table.ts?b933:46) at new ResponseTable (response-table.ts?b933:20) at Query._callee$ (query.ts?7f78:134) at tryCatch (runtime.js?96cf:63)

network response information

Relevant response Headers:

HTTP/1.1 200 OK Content-Type: application/json; charset=utf-8

Body (With personal data removed): {"data":[{"id":"1","first_name":"<filler>"},{"id":"2","first_name":"<filler>"},{"id":"3","first_name":"<filler>"},{"id":"4","first_name":"<filler>"},{"id":"5","first_name":"<filler>"},{"id":"6","first_name":"<filler>"},{"id":"7","first_name":"<filler>"},{"id":"8","first_name":"<filler>"},{"id":"9","first_name":"<filler>"},{"id":"10","first_name":"<filler>"}]}

richmolj commented 4 years ago

Youre using render :json - try respond_with like our sample app/quickstart

cooljacob204 commented 4 years ago

I was trying to avoid including the responders gem.

I used render jsonapi: letters which seems to have fixed it. Would you say that this is also a correct approach?

I'm guessing it's crashing because the body did not have a meta tag.

cooljacob204 commented 4 years ago

Going to close since I am no longer running into this issue now that I respond with jsonapi.