question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem to $persist

See original GitHub issue

I dont know why I cant persist and object… I got: fetch, push and destroy works well.

vuex-orm-graphql.es5.js?8eb2:1 Uncaught (in promise) TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Function.e.transformOutgoingData (vuex-orm-graphql.es5.js?8eb2:1)
    at Function.e.addRecordToArgs (vuex-orm-graphql.es5.js?8eb2:1)
    at Function.eval (vuex-orm-graphql.es5.js?8eb2:1)
    at eval (vuex-orm-graphql.es5.js?8eb2:1)
    at Object.eval [as next] (vuex-orm-graphql.es5.js?8eb2:1)
    at eval (vuex-orm-graphql.es5.js?8eb2:1)
    at new Promise (<anonymous>)
    at __awaiter (vuex-orm-graphql.es5.js?8eb2:1)
    at Function.t.call (vuex-orm-graphql.es5.js?8eb2:1)

Sector,js

import { Model } from '@vuex-orm/core'

export default class Sector extends Model {
  static entity = 'sectors'

  static fields () {
    return {
      id: this.number(null),
      name: this.string(''),
    }
  }
}

store/index.js

import Vue from 'vue';
import Vuex from 'vuex';
import VuexORM from '@vuex-orm/core';
import VuexORMGraphQL from '@vuex-orm/plugin-graphql';
import { AuthModule } from './auth-module';
import { HttpModule } from './http-module';
import { SettingsModule } from './settings-module';
import { CustomAdapter } from '@/plugins/graphql-adapter';
import ApolloClient from '@/plugins/apollo-client';

// Create a new instance of Database.
const database = new VuexORM.Database();

// Models
import User from '@/models/User';
import Sector from '@/models/Sector';
import Subsector from '@/models/Subsector';
import Segment from '@/models/Segment';

// Register Models to Database.
database.register(User);
database.register(Sector);
database.register(Subsector);
database.register(Segment);

VuexORM.use(VuexORMGraphQL, { 
	database,
	adapter: new CustomAdapter(),
	apolloClient: ApolloClient
});
Vue.use(Vuex);

export default new Vuex.Store({
  plugins: [VuexORM.install(database)],
  modules: {
    auth: AuthModule,
    http: HttpModule,
    settings: SettingsModule
  },
});

Sector.vue

<script>
import Sector from '@/models/Sector';

export default {
	data() {
		return {
			sector: {},
		}
	},
	async mounted() {
		await Sector.fetch();
	},
	computed: {
		sectors: () => Sector.all(),
	},
	methods: {
		newf() {
			this.sector = {};
		},
		edit(sector) {
			this.sector = sector;
		},
		async create() {
			await Sector.insert({data: this.sector});
			const sector = Sector.query().last();
			await sector.$persist();
		},
		async update() {
			await this.sector.$push();
		},
		async destroy(sector) {
			await sector.$deleteAndDestroy();
		}
	}
};
</script>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7

github_iconTop GitHub Comments

3reactions
sysruncommented, Oct 27, 2020

I am using string ids in many of my models. Hat to fork the Repo and remove all “toNumber” calls in the code. Hope it will be fixed soon

0reactions
Arsynccommented, Mar 21, 2021

With generated $id: "tyr13zqj" I have the same error Uncaught (in promise) TypeError: Cannot convert undefined or null to object.

Seems that now (vuex-orm/core 0.36.3) it not prefixed with $uid in models: id: this.uid(() => tempId()) // tempId returns 'tyr13zqj' value

But in plugin code we have

getRecordWithId(id) {
    return this.baseModel
        .query()
        .withAllRecursive()
        .where("id", toPrimaryKey(id))
        .first();
}

where toPrimaryKey is

function toPrimaryKey(input) {
    if (input === null)
        return 0;
    if (typeof input === "string" && (input.startsWith("$uid") || isGuid(input))) {
        return input;
    }
    return parseInt(input.toString(), 10);
}

Why you need that conversion in plugin? Just return string if that is string!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem persists definition and meaning - Collins Dictionary
Problem persists definition: If something undesirable persists , it continues to exist. [...] | Meaning, pronunciation, translations and examples.
Read more >
If the problem still persists or If the problem still persist ?
The correct phrase is "If the problem still persists," because the word "problem" is singular, and the singular third-person form of the verb...
Read more >
What does "Let me know if the problem persists" exactly mean?
A logician might say that the person being addressed need say anything only if the problem did persist. In practice, the context will...
Read more >
The problem is persisting | English examples in context - Ludwig
The problem is that Carr persists in equating war against civilians with terrorism, and this leads to absurdity.
Read more >
Five Things I Know About Solving Persistent Problems
If they had worked, the problem would no longer exist. Your solutions have now become part of the problem system. If you do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found