mickhansen / graphql-sequelize

GraphQL & Relay for MySQL & Postgres via Sequelize
MIT License
1.9k stars 172 forks source link

defaultListArgs or JSONType scalar replaces query variables with a function #591

Closed Kinzeng closed 4 years ago

Kinzeng commented 6 years ago

When I try to make a query using query variables, it replaces the value with a function instead, thus causing sequelize to throw an error Invalid value [Function]. Example: query:

query ($user: String!) {
  aListQuery(
    where: {
      user: $user
    }
  ) {
      id
      name
      user
  }
}

variables:

{
  "user": "123"
}

I edited the code in node_modules and this is what's printed out in jsonType.js as the value for user:

function (object) {
    return object == null ? undefined : object[key];
}

which returns this as the final object for the where argument:

{ where: { user: [Function] } }

After looking at the source code, I see that in jsonType.js, for variables you are returning _.property(ast.name.value). Lodash documentation says that _.property returns a function, so that could be cause of the issues. If this is not the problem, what can I do to get around this?

mickhansen commented 6 years ago

Sorry for the slow response but i don't really have a clue as to what might be going wrong. Try opening a PR with a failing test.

RichAyotte commented 6 years ago

@Kinzeng Can you try again the latest version and report back.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

joewoodhouse commented 4 years ago

This is a problem I believe if you're writing your own resolvers....

The JSONType when it encouters a variable in parsing replaces it with the _.property lodash function. Then if you're using the resolver function it knows how to unwrap those with the whereQueryVarsToValues. However if you're rolling your own resolver, that won't happen and yes you end up with functions where there should be primitives.