Skip to content

String gets transformed in object with each letter as property #1774

Answered by the-noob
the-noob asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @EmilTholin - sorry for wasting your time, found the issue, close to PEBKAC.
I've updated the sandbox example just for completeness and will describe the issue here, maybe it helps someone.

The mobx models mirror the GQL entities and we are using ApolloClient queries. The response has some extra __typename field and I made a function to remove that.

export const removeTypename = obj => {
  const result = {};
  Object.getOwnPropertyNames(obj).forEach(key => {
    if (key !== "__typename") {
      if (Array.isArray(obj[key])) {
        result[key] = obj[key].map(item => removeTypename(item));
      } else if (obj[key] !== null && typeof obj[key] === "object") {
        result[key] = remo…

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@EmilTholin
Comment options

Answer selected by the-noob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants