question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

persist/push: Avoid sending object properties not declared in input types

See original GitHub issue

Currently when pushing an object back to my GraphQL API, I can control the name of the input type for the update request handily using the adapter method getInputTypeName.

However, despite returning the name of an input type that is defined in my schema, the plugin encodes all values of my object into the push request rather than just those defined in the input type.

Using the example from the documentation, if my updatePost mutation only allowed changes to the content and title, but not the user, my schema might look something like this:

type Post {
    id: ID!
    userId: ID!
    title: String
    content: String
    ....
}

input PostInput {
    title: String
    content: String
}

type Mutation {
    updatePost(id: Int!, post: PostInput!): Post
}

However, if I tried to $push() an existing post, I will get an error from the GraphQL server, since all of the Post properties are getting encoded in the Input object, despite the input type only having title and content fields.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
phortxcommented, May 28, 2020

Good News:

This is an issue in my current project too. The best reason to tackle that 😉

I’ll provide a patch this week.

0reactions
phortxcommented, May 29, 2020

This should be fixed in version 1.0.0-rc.39.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to restrict TypeScript object to contain only ...
First, define a type that, when passed a union of keys, creates an object which // cannot have those properties. I couldn't find...
Read more >
Object.defineProperty() - JavaScript - MDN Web Docs
The static method Object.defineProperty() defines a new property directly on an object, or modifies an existing property on an object, ...
Read more >
Documentation - Object Types - TypeScript
Each property in an object type can specify a couple of things: the type, whether the property is optional, and whether the property...
Read more >
object — Understanding JSON Schema 2020-12 documentation
In this schema, the properties declared in the then schema only count as “evaluated” properties if the “type” of the address is “business”....
Read more >
Set or skip an object property based on a condition · Issue #387
I've found that by using union as suggested, much of this heartache can be avoided. You'll always want to pass all the possible...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found