graphql/express-graphql

Getting [Object: null prototype] in passed arguments

coolemur opened this issue · 0 comments

Hello.

Trying basic example https://graphql.org/graphql-js/running-an-express-graphql-server/

In schema I'm trying to pass input type.

My Schema looks like this:

var schema = buildSchema(`

  type User {
    id: String
    name: String
  }

  input UserOrderByInput {
    id: Sort
    name: Sort
  }

  enum Sort {
    asc
    desc
  }

  type Query {
    user(id: String): User!
    users(orderBy: UserOrderByInput): [User!]!
  }

  input UserInput {
    name: String!
  }

  type Mutation {
    createUser(user: UserInput): User!
    updateUser(id: String!, user: UserInput!): User!
    deleteUser(id: String!): User!
  }
`);

In root I've:

var users = [{
  id: 'a',
  name: 'alice',
},
{
  id: 'b',
  name: 'bob',
}];

var root = {
...
  users: ({orderBy}) => {
    console.log(orderBy);
    return users;
  },
...
};

Query looks like this:

query {
  users(orderBy: { id: asc, name: asc }) {
    id
    name
  }
}

In console log I'm getting orderBy object:

[Object: null prototype] { id: 'asc', name: 'asc' }

Is there a reason why each input type has "Object: null prototype" ?
(basically this applies for every input type that I use)

I can get rid of it using var orderByParsed = JSON.parse(JSON.stringify(orderBy)); but this doen't seem a right way to handle this issue.

Is there other solution how to get rid of "Object: null prototype" in passed args ?