alphasights / ember-graphql-adapter

GraphQL adapter for Ember Data
MIT License
244 stars 26 forks source link

Allow explicit relationship resolution #203

Closed JamesTsaoAS closed 3 years ago

JamesTsaoAS commented 3 years ago

Problem

When resolving an ember model object graph, objects that contain relationships that itself contain relationships with the same name do not get resolved. Example:

+-- angle
    +-- id
    +-- title
    +-- details
    +-- angleTeamMemberships
    |   +-- id
    |   +-- name
    |   +-- avatar
    +-- geographies
    |   +-- id
    |   +-- name
    |   +-- code
    +-- angleCompanies
    |   +-- id
    |   +-- alphaCompany
    |   |   +-- id
    |   |   +-- name
    |   +-- aliasCompany
    |   |   +-- id
    |   |   +-- name
    +-- subAngles
        +-- id
        +-- title
        +-- details
        +-- angleTeamMemberships (missing)
        |   +-- id
        |   +-- name
        |   +-- avatar
        +-- geographies (missing)
        |   +-- id
        |   +-- name
        |   +-- code
        +-- angleCompanies (missing)
            +-- id
            +-- alphaCompany
            |   +-- id
            |   +-- name
            +-- aliasCompany
                +-- id
                +-- name

Given the angle object graph above, a sub-angles's relationships (angleTeamMemberships, geographies, angleCompanies) are missing from the response of an angle's graphql query.

Root problem

The ember-graphql-adatper keeps track of visited relationships by the relationship name. If it encounters the same relationship name again, it will not walk down that path when parsing and building the ember object graph. This results in a generated graphql query with child relationships missing relationships.

Solution

Extend the options of the ember model definition with resolveAlways. When the parser encounters this option, it will traverse this relationship even if it has already been visited.