marmelab / marmelab/json-graphql-server
Schema fails at getRelatedType if table name and foreign key
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1.9k
- Forks
- 166
- Avg merge
- 3m
- Merged PRs (30d)
- 3
Description
Schema fails at getRelatedType if table name and foreign key.
Suppose you have table name m_oraganization and primary key id
and then you have foreign key organization_id in m_discount_type
at name conversion
exports.getRelatedType = fieldName =>
getTypeFromKey(fieldName.substr(0, fieldName.length - 3));
substr strips down last three and we get Organization which actually doesn't exist.
UnhandledPromiseRejectionWarning: Error: Unknown type "Organization". Did you mean "MOrganization", "MRelation", or "MOrganizationFilter"?
Please suggest any other logic to handle related type names. Thanks !
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at exports.getRelatedType and its call to getTypeFromKey, using the m_oraganization and organization_id example to trace how related type names are derived. Determine a naming rule that resolves the foreign key to the existing MOrganization type, then verify that schema generation no longer reports Unknown type "Organization".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100