Closed FedericoBiccheddu closed 3 years ago
I like the idea.
Would the following be a compiler error?
type Droid {
id: string;
name: number; // this is number instead of string
}
const droidType = t.objectType<Droid>({
// ...
fields: () => [
t.field('id', t.NonNull(t.ID), {
resolve: (src) => src.id
}),
// will this be a compiler error because Droid["name"] is number instead of string?
t.field('name', t.NonNull(t.String)),
],
});
It should, but at the moment there is no inference from Src
so it will pass.
I will try and update #49 to fix this scenario.
I was thinking about an implicit resolution of
field
in order to have the same behavior as GraphQL.At the moment there are two ways of resolving fields with the same result in return: Explicit:
Implicit:
To simplify the API having one way to obtain the same result in different ways, I did experiment with this approach:
field
becomes the only way to resolve an object; if no resolve is provided, it will resolve using thedefaultField
approachThe code will be something like:
What do you folks think?