Skip to content
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

Get singular and plural model names from jsonSchema #61

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aurium
Copy link

@aurium aurium commented Jul 21, 2018

This is similar to listFieldName and fieldName from graphQLBuilder().model()'s extra parameter.
It can simple replace listFieldName and fieldName if you can add collectiveName and singleName to your models's jsonSchema.
The benefit is:

  • Center the model description;
  • Produce the correct single type name in the result graphQL schema;
  • Share the model identification with oder modules in the app.

This is similar to `listFieldName` and `fieldName` from `graphQLBuilder().model()`'s extra parameter.
It can simple replace `listFieldName` and `fieldName` if you can add `collectiveName` and `singleName` to your models's jsonSchema.
The benefit is:
* Center the model description;
* Produce the correct single type name in the result graphQL schema;
* Share the model identification with oder modules in the app.
@andriibieriezhnoi
Copy link

andriibieriezhnoi commented Apr 27, 2019

I ran into a problem when the name of the table is "users" and I have to write userss (double s)

i think this is a useful PR.

@tsimons
Copy link

tsimons commented May 23, 2019

Any thought on when this will be merged? I've run in to this issue now as well.

@aizotov
Copy link

aizotov commented Aug 8, 2019

Please merge 🙏

@andriibieriezhnoi
Copy link

@sbabushkin could you check this PR please? :)

const listFieldName = modelData.opt.listFieldName || (`${defaultFieldName}s`);
const schema = modelData.modelClass.jsonSchema;
const singleFieldName = schema.singleName || modelData.opt.fieldName || defaultFieldName;
const listFieldName = schema.collectiveName || modelData.opt.listFieldName || (`${defaultFieldName}s`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const listFieldName = schema.collectiveName || modelData.opt.listFieldName || (`${defaultFieldName}s`);
const listFieldName = schema.collectiveName || modelData.opt.listFieldName || (`${singleFieldName}s`);

@CarlosFandango
Copy link

Bump!

I've encountered this in my project as well. Would be great to get this merged in :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants