-
Notifications
You must be signed in to change notification settings - Fork 9
Add generic Schema types to Paper
#197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
`; | ||
const graphqlSchema = buildSchema(schemaString); | ||
|
||
type Person = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace this with a separate set of tests with use cases and typings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Write tests using tsd
ea7c355
to
12d09c2
Compare
packages/paper/src/paper.ts
Outdated
export class Paper<UserOperations extends OperationMap = OperationMap> { | ||
protected history: DocumentStore[] = []; | ||
protected current: DocumentStore; | ||
export class Paper<ST extends SchemaTypes = SchemaTypes, UserOperations extends OperationMap = OperationMap> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is considered a breaking change as the first type argument is no longer the UserOperations
.
Any news on this?! |
Hi @mammadataei, I'm a bit stuck on keeping the context type in tact for the operations when they're destructured. I've moved the work to a typescript playground to iterate more quickly with all the types in one place. Take a look at the playground, let me know if you have any ideas. Essentially, the types get lost in the |
Paper
storeGraphQLHandler
data and operations
GraphQLHandler
data and operationsPaper
@mammadataei Okay, I got it, but it's super messy and I'm not sure which parts are required. I'll have to do a few passes to clean it up, there's a quite a bit here that's outside my understanding. |
@chadian Hi again, sorry I've been busy recently. I've checked your playground, and I have no idea what's going on! I'll try to read the source code to learn how it's working; I hope I can help better. Any suggestion on where should I start?! |
Hi @mammadataei, all good! I think I know how it's working in the playground, essentially type parameters need to be destructured next to each other to get the underlying type inference, and by not setting default types or passing any in. I've just updated the PR and I need to add some tests using https://github.com/SamVerschueren/tsd and I think it'll be good to go. |
Paper
Paper
I thought I had it in the playground, and it's pretty close, but it's missing some sort of inference in the transaction and being bound with the operation context. I've whittled it down a more representative example with samples of what should and shouldn't pass in this playground. What is working here is the types on the store when reading values eg This website offers some insights into what's required to get this working. It's just the multiple levels of passing these types that I'm missing something. |
Note to self: try bumping typescript and using |
By passing the types available on a schema, there should be accessible types and autocomplete:
Paper.prototype.mutate
and operationsPaper.prototype.data
CHANGELOG
package-name
* (feature) Added a new feature