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

object.assign called with boolean argument #111

Closed
arolson101 opened this issue Jul 9, 2018 · 4 comments
Closed

object.assign called with boolean argument #111

arolson101 opened this issue Jul 9, 2018 · 4 comments
Labels
Bug 🐛 Something isn't working
Milestone

Comments

@arolson101
Copy link

Describe the bug
When I run a query in react-native I get the following:

TypeError: In this environment the sources for assign MUST be an object. This error is a performance optimization and not spec compliant.
    at Object.assign

the problem is in type-graphql/src/resolvers/validate-arg.ts:

import { validateOrReject, ValidatorOptions } from "class-validator";

import { ArgumentValidationError } from "../errors/ArgumentValidationError";

export async function validateArg<T extends Object>(
  arg: T | undefined,
  globalValidate: boolean | ValidatorOptions,
  argValidate?: boolean | ValidatorOptions,
): Promise<T | undefined> {
  const validate = argValidate !== undefined ? argValidate : globalValidate;
  if (validate === false || arg == null || typeof arg !== "object") {
    return arg;
  }

  const validatorOptions: ValidatorOptions = Object.assign({}, globalValidate, argValidate);
  if (validatorOptions.skipMissingProperties !== false) {
    validatorOptions.skipMissingProperties = true;
  }

  try {
    await validateOrReject(arg, validatorOptions);
    return arg;
  } catch (err) {
    throw new ArgumentValidationError(err);
  }
}

in this case globalValidate is true and argValidate is undefined

I think it's reasonable to request that Object.assign not be called with boolean arguments. Perhaps:

const validatorOptions: ValidatorOptions = Object.assign({}, (typeof globalValidate === 'object' ? globalValidate : {}), (typeof argValidate) === 'object' ? argValidate : {}));

To Reproduce
A quick guide how to reproduce the bug.
You can paste here code snippets or even better, provide a link to the repository with minimal reproducible code example.

Run under react-native. The relevant code is in the polyfill for object.assign in Object.es6.js:

  for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) {
    var nextSource = arguments[nextIndex];
    if (nextSource == null) {
      continue;
    }

    if (__DEV__) {
      if (typeof nextSource !== 'object' &&
          typeof nextSource !== 'function') {
        throw new TypeError(
          'In this environment the sources for assign MUST be an object. ' +
          'This error is a performance optimization and not spec compliant.'
        );
      }
    }`

Expected behavior
no error

Logs
If applicable, add some console logs to help explain your problem.
You can paste the errors with stack trace that were printed when the error occured.

Enviorment (please complete the following information):

  • OS: android
  • Node 8.11.2
  • Package version: 0.12.2
  • TypeScript version 2.9.2

Additional context

@MichalLytek MichalLytek added the Bug 🐛 Something isn't working label Jul 10, 2018
@MichalLytek
Copy link
Owner

Honestly, I've never considered React Native as a platform for TypeGraphQL.
What is you use case that you run GraphQL server inside a mobile app?

The fix is easy, so I will do that in a minute 😉

@arolson101
Copy link
Author

I find graphql to be a good way to access the local database inside my mobile app. React doesn’t really have any good way to handle async data fetches- it’s all redux saga or redux-thunk, and all I want to do is fetch some data that is local state for a component and not make things complicated.

@arolson101
Copy link
Author

And thank you!

@MichalLytek
Copy link
Owner

fixed via af742d8, released in v0.12.3 🎉

@MichalLytek MichalLytek added this to the 1.0.0 release milestone Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐛 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants