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

GraphQL Aliases on relational value #8402

Closed
DamienMrtl opened this issue Sep 28, 2021 · 16 comments · Fixed by #9012
Closed

GraphQL Aliases on relational value #8402

DamienMrtl opened this issue Sep 28, 2021 · 16 comments · Fixed by #9012
Labels

Comments

@DamienMrtl
Copy link

DamienMrtl commented Sep 28, 2021

Describe the Bug

When using alias in a graphqQL query on a junction table the returned value of the field using the alias is null. When I remove the alias from the query the data is there.

To Reproduce

  1. Two collections with a m2m relation to get a junction table.
  2. Use graphQL to query nested data from both collections.
  3. Add an alias on the junction table field in the graphQL query.

What version of Directus are you using?

9.0.0-rc95

What version of Node.js are you using?

14.17.5

What database are you using?

Postgres 13.2

What browser are you using?

Chrome

What operating system are you using?

Windows

How are you deploying Directus?

Jelastic

@azrikahar
Copy link
Contributor

Can confirm this bug is present, and seems like #8332 was correct in that aliases are broken since rc.94 (even though we couldn't replicate it back then).

Managed to narrow it down to this bug being introduced in #8009's api/src/services/graphql.ts as reverting that specific file only makes aliases work again.

@rijkvanzanten rijkvanzanten changed the title GraphQL Aliases on junction collection breaking the returned value GraphQL Aliases on relational value Sep 29, 2021
@hueindahaus

This comment has been minimized.

@rijkvanzanten

This comment has been minimized.

@filipproch
Copy link
Contributor

I managed to narrow it down to the line (api/src/services/graphql.ts)
1378 current = selection.alias?.value ?? selection.name.value;

removing the part
selection.alias?.value ??
fixes the issue

@rijkvanzanten
Copy link
Member

Wanna open a PR with that fix @filipproch? 🙂

@filipproch
Copy link
Contributor

filipproch commented Oct 20, 2021

@rijkvanzanten sure, would there be an appropriate place to also create a test case for future?

@filipproch
Copy link
Contributor

Also one more edit is needed,
now
[415] return obj[info?.path?.key ?? field.field];
to make it work
[415] return obj[field.field];

both edits are required to make it work
first => to get the value of the field from DB, second - to correctly resolve it in the query

@rijkvanzanten
Copy link
Member

We've just started an effort to setup test cases for more and more bits of the API, but I don't think the GraphQL endpoint / services have something spun up yet, right @jaycammarano?

@jamescammarano
Copy link
Contributor

We've just started an effort to setup test cases for more and more bits of the API, but I don't think the GraphQL endpoint / services have something spun up yet, right @jaycammarano?

No. That was on my notes to discuss. Was thinking of probably doing e2e for REST and integration for GraphQL? Just so there's not a ton of repetition in the e2e tests.

@filipproch
Copy link
Contributor

Ok will send PR with just the fix then

filipproch added a commit to Coconut-Works/directus that referenced this issue Oct 21, 2021
@azrikahar azrikahar mentioned this issue Oct 21, 2021
rijkvanzanten pushed a commit that referenced this issue Oct 21, 2021
@cdanny358
Copy link

Unfortunately, this fix seems to have broken other things. Now aliases to simple fields return the error message "Cannot destructure property 'type' of 'field' as it is undefined," and aliases to many-to-one fields return null, which was the original problem I was seeing. I'm in version rc.99.

@filipproch
Copy link
Contributor

@cdanny358 I will look into it further then and invent a better solution

@iksent
Copy link
Contributor

iksent commented Nov 2, 2021

I can confirm this bug exists in RC100.

Cannot destructure property 'type' of 'field' as it is undefined.

My code:

query siteMapContests {
  contest(limit: 100) {
    s: slug # <<< Works OK without renaming "s: "
  }
}

Should we reopen this one or open a new issue?

@rijkvanzanten
Copy link
Member

A new issue would be most helpful @iksent 👍🏻

@filipproch
Copy link
Contributor

@iksent And feel free to mention me, I plan to submit a PR this week

@rijkvanzanten
Copy link
Member

Awesome, thank you!

AustinPhillipTaylor pushed a commit to AustinPhillipTaylor/directus that referenced this issue May 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants