Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unprototyped objects coming in from GraphQL to Loopback #90

Open
cdokolas opened this issue Sep 12, 2017 · 0 comments
Open

Unprototyped objects coming in from GraphQL to Loopback #90

cdokolas opened this issue Sep 12, 2017 · 0 comments

Comments

@cdokolas
Copy link

I'm trying to use the "where" parameter in a query like this:

query getAllStatus {
  allVStatus(where: {name : {like: "abc%"}}) {
    VStatus {
      name
      field1
      field2
    }
  }
}

I get an error Cannot convert object to primitive value. Full stack trace:

Uncaught TypeError: Cannot convert object to primitive value
    at Object.String [as DataType] (<anonymous>)
    at eval (eval at DataAccessObject._coerce (E:\dev\pm-web\node_modules\loopback\node_modules\loopback-datasource-juggler\lib\dao.js:1791:11), <anonymous>:1:1)
    at Function.DataAccessObject._coerce (E:\dev\pm-web\node_modules\loopback\node_modules\loopback-datasource-juggler\lib\dao.js:1791:11)
    at Function.DataAccessObject.count (E:\dev\pm-web\node_modules\loopback\node_modules\loopback-datasource-juggler\lib\dao.js:2431:18)
    at getCount (E:\dev\pm-web\node_modules\loopback-graphql\dist\index.js:187:18)
    at Object.findAll (E:\dev\pm-web\node_modules\loopback-graphql\dist\index.js:208:12)
    at Query._a.(anonymous function) (E:\dev\pm-web\node_modules\loopback-graphql\dist\index.js:709:34)
    at resolveOrError (E:\dev\pm-web\node_modules\graphql\execution\execute.js:474:12)
    at resolveField (E:\dev\pm-web\node_modules\graphql\execution\execute.js:460:16)
    at E:\dev\pm-web\node_modules\graphql\execution\execute.js:275:18
    at Array.reduce (<anonymous>)
    at executeFields (E:\dev\pm-web\node_modules\graphql\execution\execute.js:272:42)
    at executeOperation (E:\dev\pm-web\node_modules\graphql\execution\execute.js:212:10)
    at E:\dev\pm-web\node_modules\graphql\execution\execute.js:120:13
    at Promise (<anonymous>)
    at Object.execute (E:\dev\pm-web\node_modules\graphql\execution\execute.js:119:10)

All I've managed to find out is that the where object that reaches DataAccessObject._coerce (loopback-datasource-juggler\lib\dao.js) is an unprototyped object and the line with the statement val = DataType(val); (currently 1791) causes the exception.

I've not determined which function is called, but it belongs to the loopback model of the table. It may be ModelBuilder.prototype.resolveType but I've been unable to step into the function.

The unprototyped object probably comes from GraphQL's values.js function getVariableValues (instantiates stuff with Object.create(null)).

Note: I'm using the GraphiQL interface to test all this. It is worth noting that using a variable works much better:

query getAllStatus($where: JSON!) {
  allVStatus(where: $where) {
...

and the variable is declared with {"where": {"name": {"like": "abc%"}}}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant