vulcan-npm
vulcan-npm copied to clipboard
Use of TData might be wrong
It's not clear in Apollo whether the generic type "TData" refers to the type of "document" or type of the response.
For example, if it refers to the document, we could have TData = { hello: string }
, so it matches the schema. If it refers to the data, we could have TData = { data: { createFoo : { document: { hello: string }}
, so TData would vary amongs mutations.
The second case is more likely in Apollo. But what we want in Vulcan is the first case. We should introduce a new TModel
generic which is the type of the model, and try to build the corresponding "TData" automatically.
The biggest issue is that the name of the resolver is dependent on the model (createFoo
, createBar
), it is not static so hard to precompute in typescript.
You could use graphql aliases as a workaround for this:
mutation createFoo {
foo : createFoo {
id
}
}
mutation updateBar {
foo: updateFoo {
id
}
}
Both mutations will have the same TData :
interface Foo {
foo : {
id : String
}
}
Didn't know about that, thank you!
The API would be more:
interface FooData {
foo : {
data: {
id : String
}
}
}
because the data is always nested in its own object, but that's still fairly straightforward to use.
We could probably do a generic:
interface VulcanData<Key extends string, TModel = Object> {
[Key] : {
data: TModel
}
}
interface FooData extends VulcanData<"foo", Foo> {}