marmelab / marmelab/json-graphql-server

Schema fails at getRelatedType if table name and foreign key

Open
#72 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.