nuwave / nuwave/lighthouse

Scope on morphTo directive applied to source model, rather than target

Open
#2,106 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PHP
Stars
3.5k
Forks
468
Avg merge
3h 9m
Merged PRs (30d)
2

Description

Describe the bug

When applying a scope to the morphTo directive, it appears that Lighthouse is trying to apply the scope to the root model, rather than then target relationship. For instance, given the following schema:

type Author {
    id: ID!
    publications: [Publication!]!
}

type Publication {
    id: ID!
    publication: Publishable @morphTo(scopes: ["active"])
}

type Magazine {
    id: ID!
    title: String!
    isActive: Boolean!
}

type Book {
    id: ID!
    title: String!
    isActive: Boolean!
}

union Publishable = Book | Magazine

Lighthouse is trying to apply the active scope to the Publication model, rather than the Magazine or Book model.

Expected behavior/Solution

The scope should be applied to the query responsible for fetching the Magazine or Book.

Steps to reproduce

See above example.

Lighthouse Version
v5.23.1

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 by reproducing the supplied Author, Publication, Magazine, and Book schema with the morphTo directive and active scope. Trace the morphTo scope handling to determine why the source model receives the scope instead of the target query. Done means active filters the Magazine or Book result and the behavior is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, laravel, php
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.