-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Issues with typescript generated models #364
Comments
Can you maybe share a minimal project where these errors are produced?
I haven't had problems with this, but I think there should be some updates here, because
I also had this for an old project where I just wanted to update mst-gql. This helped:
For newly created projects and adding the necessary mst-gql dependencies this error didn't come up.
Hopefully I have a fix for this one: #361 You may give it try using:
@jesse-savary, can you please take a look at my PR-s #361, #363? |
Hi, I will give you a report soon.
I will revert to the previous schema and will make the APIs publicly available (it's a PoC anyway) so you will be able to test it yourself. |
I came back to see if there are any answers and I have noticed my previous comment is gone... I have included two schema files with examples... I think I must have messed up something. schema_with_instances.graphql.txt EDIT: |
@beepsoft i've edited my previous comment because of a mistake in my tests, but just to ping you, the version |
What is the error you are getting with |
I've shared the two schemas here: #364 (comment) |
That's too bad there's no private messaging in GH and I don't feel comfortable sharing email addresses here. Instead, try to PM me on twitter @ beepshow. |
my thought exactly... I've spent a few minutes looking for a DM. Thanks. |
I just created a new CRA project
and added these scripts:
This is my final package.json: {
"name": "my-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.16.4",
"@testing-library/react": "^13.2.0",
"@testing-library/user-event": "^13.5.0",
"@types/jest": "^27.5.0",
"@types/node": "^16.11.33",
"@types/react": "^18.0.8",
"@types/react-dom": "^18.0.3",
"graphql": "^16.4.0",
"graphql-request": "^4.2.0",
"graphql-tag": "^2.12.6",
"mobx": "^6.5.0",
"mobx-react": "^7.3.0",
"mobx-state-tree": "^5.1.4",
"mst-gql": "beepsoft/mst-gql#mst-gql-v0.15.0-gitpkg",
"react": "^18.1.0",
"react-dom": "^18.1.0",
"react-scripts": "5.0.1",
"typescript": "^4.6.4",
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"gql:gen": "mst-gql --format ts --outDir src/models schema_without_instances.graphql",
"gql:build": "tsc --extendedDiagnostics"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
} Then generated and
This is my result:
I tried it with both schema_without_instances.txt and schema_with_instances.graphql.txt and both of them generated and compiled all right (needed to rename them to .graphql). It might be better if you shared a (failing) project on github, so I could see how to reproduce the error. |
I've tried to reach out to you on Twitter but you have your DMs blocked. |
Oops, you are right, now I enabled DM-s. |
I haven't looked into how to fix this within the library itself but the manual workaround working locally for me (for a related field called return this.__child(`events(distinctOn: .... with this: return this.__child(args == null ? 'events' : `events(distinctOn: .... so that it falls back to the old functionality when args is not provided. Another issue to note is that some of the required dependencies used by the omitted part of the above code are not properly imported automatically. |
Hopefully this together with some other issues affecting v0.15.0 is already fixed with the PR-s merged into main. @jesse-savary could you maybe create a beta release on NPM so that we can try the new version in our projects? |
It took me a little, but here's a repo showing my issues. I've used the last commit + a super simple graphql example (attached). https://github.com/krstns/mst-gql-issues
|
Hello
I have a few issues with generated models by mst-gql 0.15.0. My project fails to compile.
All of the exported types cause circular reference issues. I have to replace:
export type RootStoreType = Instance<typeof RootStore.Type>;
with
export interface RootStoreType extends Instance<typeof RootStore.Type> {}
and similar.
TS7022: 'RootStore' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. (this one is also fixed by changes made in 1.)
TS2742: The inferred type of 'RootStore' cannot be named without a reference to 'mst-gql/node_modules/graphql'. This is likely not portable. A type annotation is necessary.
Incorrect handling of optional type args in the model selector query. One of my fields is generated like this:
instances(builder: string | ActionConnectionModelSelector | ((selector: ActionConnectionModelSelector) => ActionConnectionModelSelector) | undefined, args?: { first?: number, last?: number, before?: string, after?: string }) { return this.__child(
instances(first: ${JSON.stringify(args['first'])}, last: ${JSON.stringify(args['last'])}, before: ${JSON.stringify(args['before'])}, after: ${JSON.stringify(args['after'])}), ActionConnectionModelSelector, builder) }
Inside the
JSON.stringify
calls, theargs
can be undefined.The text was updated successfully, but these errors were encountered: