mst-gql icon indicating copy to clipboard operation
mst-gql copied to clipboard

Casing issues in the generated code

Open sanketsahu opened this issue 5 years ago • 7 comments

I have a GraphQL type named as "FileContent", the generated props collection in the RootStore was "fileContents" but during merge it was looking for a prop "filecontents" on the RootStore (with a small c).

Any quick hints where to look for it?

sanketsahu avatar Apr 10 '20 10:04 sanketsahu

I'm guessing this is due to a bug related to the new naming that @beepsoft worked on. I would start looking at the changes in this PR first: https://github.com/mobxjs/mst-gql/pull/155

Who ever looks at this should add a test if at all possible!

chrisdrackett avatar Apr 13 '20 15:04 chrisdrackett

@sanketsahusoft Can you maybe share your graphql schema?

beepsoft avatar Apr 13 '20 16:04 beepsoft

@sanketsahusoft Can you maybe share your graphql schema?

And also provide the parameters you used for generating the mst models, please!

beepsoft avatar Apr 13 '20 17:04 beepsoft

@sanketsahusoft One thing that worth checking is whether the mst-gql you use to generate the schema and the one that you use at runtime (at the time executing the queries) are of the same version. I created a test with a simple graphql model like this:

type Query {
  files: [FileContent]!
}

type FileContent {
  id: ID
  text: String!
  path: String!
}

and it seems to correctly generate fileContents root map, and when I do a files query the merge correctly tries to store it in the fileContents field.

The generator now has 2 modes: the default mode is to generate names according to Javascript naming conventions, the other mode (--dontRenameModels) will generate names as found in your graphql schema. If you use the default Javascript naming convention mode, then at runtime for a model named FileContent it will look for a root map fileContents, while in --dontRenameModels mode it would look for filecontents. This is also the naming convention used in mst-gql up to version 0.7.1.

So, in case you somehow generate your models with version 0.10.0 but have 0.7.1 at runtime then the root field naming convention will be different and you end up with the error you described. But this is only my hypothesis until you can provide some more detail, or maybe an example project resulting in this error.

beepsoft avatar Apr 13 '20 18:04 beepsoft

Thanks, @beepsoft @chrisdrackett! I will try the --dontRenameModels flag.

sanketsahu avatar Apr 14 '20 08:04 sanketsahu

@sanketsahusoft Also, if you upgraded from an earlier version of mst-gql (eg. from 0.7.1 to 0.10.0) you may have to regenerate all model files using --force. WARNING: this would overwrite any customizations you added to RootStore.ts and any model files, which are extended from the .base.ts files, so take care with that.

beepsoft avatar Apr 14 '20 08:04 beepsoft

@beepsoft I am on 0.7.1. I didn't realize when 0.10.0 went live. Let me see! Thanks again!

sanketsahu avatar Apr 14 '20 08:04 sanketsahu