Is there a way to get rid of [Object: null prototype] in GraphQL

what is [object: null prototype]
node prototype is null or not an object
graphql optional arguments
description arg description undefined null arg description
graphql null vs undefined
req body object object

I'm trying to make one-to-many relationship database with Mongoose and GraphQL.

Whenever I insert the data to GraphQL mutation argument, I will get [Object: null prototype] error.

I notice the object will have [Object: null prototype] in front of it when I tried to console.log for debug purpose.

I have tried many ways, tried to map() args or even to use replace() but no luck. All I have been getting is "args.ingredient.map/replace is not a function"

I have test hard coded method by changing the args for example:

args.category = '5c28c79af62fad2514ccc788'
args.ingredient = '5c28c8deb99a9d263462a086'

Surprisingly it works with this method. I assume the input cannot be an object but just an ID.

Refer below for actual results.

Resolvers

Query: {
    recipes: async (root, args, { req }, info) => {
        return Recipe.find({}).populate('ingredient category', 'name createdAt').exec().then(docs => docs.map(x => x))
    },
},
Mutation: {
    addRecipe: async (root, args, { req }, info) => {
      // args.category = '5c28c79af62fad2514ccc788'
      // args.ingredient = '5c28c8deb99a9d263462a086'
      // console.log(args.map(x => x))
      return Recipe.create(args)
    }
}

TypeDef

extend type Mutation {
    addRecipe(name: String!, direction: [String!]!, ingredient: [IngredientInput], category: [CategoryInput]): Recipe
}

type Recipe {
    id: ID!
    name: String!
    direction: [String!]!
    ingredient: [Ingredient!]!
    category: [Category!]!
}

input IngredientInput {
    id: ID!
}

input CategoryInput {
    id: ID!
}

Models

const recipeSchema = new mongoose.Schema({
    name: String,
    direction: [String],
    ingredient: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Ingredient' }],
    category: { type: mongoose.Schema.Types.ObjectId, ref: 'Category' }
}, {
    timestamps: true // createdAt, updateAt
})

const Recipe = mongoose.model('Recipe', recipeSchema)

This is the result I console log the args when inserting the data

{ 
    name: 'Butter Milk Chicken TEST2',
    direction: [ 'Step1', 'Step2', 'Step3' ],
    ingredient:[[Object: null prototype] { id: '5c28c8d6b99a9d263462a085' }],
    category: [[Object: null prototype] { id: '5c28c79af62fad2514ccc788' }]
}

I assume I need to get something like this

{ 
    name: 'Butter Milk Chicken TEST2',
    direction: [ 'Step1', 'Step2', 'Step3' ],
    args.category = ['5c28c79af62fad2514ccc788']
    args.ingredient = ['5c28c8ccb99a9d263462a083', '5c28c8d3b99a9d263462a084', '5c28c8d6b99a9d263462a085']
}

We had this problem. We were looking to query a service object in the database that had a price on it.

Expected Result:

service: {
  price: 9999
}

However, we accidentally queried "services" (instead of "service") which gave us an array of prices (with only one price) like so:

[ [Object: null prototype] { price: 9.99 } ]

This was caused by a bad query.

Once we changed the query to "service" (instead of "services") the data came back as expected without the null prototype.

We use Prisma as our ORM though but perhaps you are querying for recipes when you should be querying for recipe.

Query/Mutation receives args object with a null prototype · Issue , The package name and version of Apollo showing the problem. /53983315/is-​there-a-way-to-get-rid-of-object-null-prototype-in-graphql  I'm trying to make one-to-many relationship database with Mongoose and GraphQL. Whenever i insert the data to graphql mutation argument, i will get [Object: null prototype] error

You can do something like below,and [Object: null prototype] would disappear

const a = JSON.parse(JSON.stringify(args));

args.category is

[[Object: null prototype] { id: '5c28c79af62fad2514ccc788' }], 

JSON.parse(JSON.stringify(args.category) would be { id: '5c28c79af62fad2514ccc788' }

arg parameters in resolve don't inherit from Object · Issue #177 , Actually, it's a question for graphql-js and it's already discussed here: Removing widely used methods from the most commonly used type in JS is only Query builder does not work with prototype-less (Object.create(null))  I'm using graphql-spqr:0.9.9 and graphql-java:11.0. Is this a bug or is there any workaround for this? Maybe using @GraphQLInputField? (I haven't used that before). P.S. Another question, I saw on gitter that someone asked how to get rid of @_mappedOperation and @_mappedType, but answer was vague. Is it possible now, did you find out a way?

In the playground I changed in settings request credentials from omit to include and it worked, "request.credentials": "include" I hope it helps.

Is there a way to get rid of [Object: null prototype] in GraphQL, Whenever i insert the data to graphql mutation argument, i will get [Object: null prototype] error. I notice the object will have [Object: null  There’s no way to automatically ensure this compatibility and warn the devs if it’s broken. That way, changes to the API could potentially break the frontend views and we would learn about it only in QA phase (or on production, if we’re not that lucky). A simple example is the decision to make a field in your database NULL-able.

type-graphql/Lobby, @Favna [Object: null prototype] means that the object was created by using it's just a way that NodeJS prints objects using console - for class instances you will Hello everyone, I'm trying to solve MichalLytek/type-graphql#254 locally, I think the issue may be Also, I figured out the problem was not apollo or formatError. Hi, I'm wondering if there is anything like an Object type for plain objects, just like you have Int, String, Boolean ? I'm storing a "session" field in my local apollo state, containing a loggedIn boolean and a currentUser object : func

Using nullability in GraphQL, I don't get it when querying the graphql server using playground or Postman. @​Favna [Object: null prototype] means that the object was created by using Also, I figured out the problem was not apollo or formatError. Also, the only way I think I can solve this with Apollo's formatError is by searching the message string​  Unfortunately, this can get unwieldly and we'd have to limit the number of sub-types in the GraphQL union (which probably isn't bad). Using .NET Types as GraphQL types also means that we have to instantiate the type to get properties on it because the .NET Type doesn't give a way to get additional information through Reflection (except through Attributes).

What Is [object Object] in JavaScript: Object.prototype.toString, How non-null in GraphQL works, and what it does; When and why you But, once we look more closely at our schema, it turns out that there have a restaurant object at all, it's guaranteed to have a value for the name field. To get rid of this problem, people started to use a pattern called data-loader. A data-loader is another layer in our GraphQL API that resides between our resolvers and our data-source. In the simple setup, the resolvers would access the data-source directly in the more complex iteration, the resolvers would tell a data-loader what they need

Comments
  • Where would the arrays come from?
  • Where exactly do you "get [Object: null prototype] error", in the Recipe.create line? Can you post the full error message, please
  • I filed as an issue in the apollo project: github.com/apollographql/apollo-server/issues/3149
  • This has been very quickly fixed in firestore. github.com/googleapis/nodejs-firestore/pull/736
  • I get the null prototype when I run a create mutation and return the results as well, so not sure if it's a naming thing.
  • Please include some explanation for your answer.