0
votes

I have type for example "animal" and keys for this object can be any, but values always by type String, for example on one response I can get:

   type Animal {
    breed: String
    eyes: String
    }

for other response:

type Animal {
something: String
somethingElse: String
someOtherField: String
}

Is it possible to describe this object somehow?

type Animal {
  // how i can describe this object?
}

type General {
  name: String
  example: Animal
}
1
The two responses describe two different types - they both can’t be Animal types. That’s why you’re having trouble “describing” them as a single collective set of properties. - Randy Casburn
the point is that the "Animal" object can have any keys - chikipiki_3443
Right, I get that, but it makes no sense to have an Animal “type” that has random keys like “wheels”, “controls”, “modelNumber”, “gearRatio”, etc. Types in Typescript describe a consistent set of properties that are relied upon to statically check variables designed to take the “shape” of the type. Without the “consistent” part, which you are destroying with your idea, the entire idea of “type checking” is thrown out the window. But, good luck to you. - Randy Casburn

1 Answers

-1
votes

Am not familiar with 'graphql-js', so not certain if this helps, but a plain java object can be enumerated as follows:

var animal = {
    something: "one",
    somethingelse: "two",
    somethingother: "three"
}

for (var propName in animal)
{
    console.log(propName, animal[propName]);
}

output:

"something", "one"
"somethingelse", "two"
"somethingother", "three"