Skip to content

Clone is not a function? #456

@SpyridonZ

Description

@SpyridonZ

Using basically a modified version of the example in the documentation at the "Dynamic Filter" section here: https://cult-of-coders.github.io/grapher/#Introduction

Regular queries are working, but if I attempt to use clone on any reusable queries, it's not working. Here's my code:

productQuery.js:

import {ProductCollection} from "../db/ProductCollection";

export default ProductCollection.createQuery(
    {
    $filter({filters, options, params}) {
        filters.code = params.code;
    },
    $options: {sort: {code: -1}},
    code: 1,
    price: 1,
    author: 1
});

Usage:

import { check } from 'meteor/check';
import { ProductCollection } from "../db/ProductCollection";
const { DateTime } = require("luxon");
import {Match} from 'meteor/check';
import productQuery from "./productQuery"; // Grapher query instance

Meteor.methods({

    'products.get'() {

        if (!this.userId) {
            throw new Meteor.Error('Access Denied: User not authenticated.');
        }

        // Example query
        return productQuery.clone({
            code: "0000"
        }).fetch()
    },

This results in:

I20211118-11:06:05.823(-8)? Exception while invoking method 'products.get' TypeError: productQuery.clone is not a function
I20211118-11:06:05.824(-8)?     at MethodInvocation.products.get (imports/api/productMethods.js:38:29)
I20211118-11:06:05.824(-8)?     at maybeAuditArgumentChecks (packages/ddp-server/livedata_server.js:1885:12)
I20211118-11:06:05.825(-8)?     at packages/ddp-server/livedata_server.js:769:19
I20211118-11:06:05.825(-8)?     at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1257:12)
I20211118-11:06:05.826(-8)?     at packages/ddp-server/livedata_server.js:767:46
I20211118-11:06:05.826(-8)?     at Meteor.EnvironmentVariable.EVp.withValue (packages\meteor.js:1257:12)
I20211118-11:06:05.827(-8)?     at packages/ddp-server/livedata_server.js:765:46
I20211118-11:06:05.827(-8)?     at new Promise (<anonymous>)
I20211118-11:06:05.828(-8)?     at Session.method (packages/ddp-server/livedata_server.js:739:23)
I20211118-11:06:05.828(-8)?     at packages/ddp-server/livedata_server.js:603:43

Any ideas how to resolve this error? I tried searching and strangely I can't find anyone else who encountered this issue...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions